Skip to content

Commit

Permalink
comments added in new game constructor (#97)
Browse files Browse the repository at this point in the history
Co-authored-by: Logan Spears <logan@logans-mac-mini.lan>
  • Loading branch information
notnil and Logan Spears authored Feb 1, 2022
1 parent 83f317b commit b82d4bf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions game.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ func (g *Game) copy(game *Game) {
g.pos = game.pos
g.outcome = game.outcome
g.method = game.method
g.comments = game.Comments()
}

func (g *Game) Clone() *Game {
Expand Down
14 changes: 14 additions & 0 deletions pgn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,20 @@ func TestCommentsDetection(t *testing.T) {
}
}

func TestNewGameComments(t *testing.T) {
for _, test := range commentTests {
pgn, err := PGN(strings.NewReader(test.PGN))
if err != nil {
t.Fatal(err)
}
game := NewGame(pgn)
comment := strings.Join(game.Comments()[test.MoveNumber], " ")
if comment != test.CommentText {
t.Fatalf("expected pgn comment to be %s but got %s", test.CommentText, comment)
}
}
}

func TestWriteComments(t *testing.T) {
pgn := mustParsePGN("fixtures/pgns/0005.pgn")
game, err := decodePGN(pgn)
Expand Down

0 comments on commit b82d4bf

Please sign in to comment.