Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions game_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,15 @@ func TestPGNWithValidData(t *testing.T) {
if g.Method() != NoMethod {
t.Fatalf("expected method %s but got %s", NoMethod, g.Method())
}
if len(g.Moves()) != 6 {
t.Fatalf("expected 6 moves got %v", len(g.Moves()))
}
if len(g.Positions()) != 7 {
t.Fatalf("expected 7 positions got %v", len(g.Positions()))
}
if g.currentMove.String() != "a7a6" {
t.Fatalf("expected current move a7a6 but got %v", g.currentMove.String())
}
}

func TestTaglessPGN(t *testing.T) {
Expand Down Expand Up @@ -1247,6 +1256,33 @@ func TestInvalidPushNotationMove(t *testing.T) {
}
}

func TestValidPushNotationMove(t *testing.T) {
pgn := strings.NewReader("1. e4 (1. g4) 1... c5 2. Nc3 Nc6 3. f4 g6 4. Nf3 Bg7 5. a4 Nf6 6. e5 *")
mv := "Ng4"
opt, err := PGN(pgn)
if err != nil {
t.Fatalf("PGN(pgn) failed")
}
game := NewGame(opt)

startMlen := len(game.Moves())
startPlen := len(game.Positions())

err = game.PushNotationMove(mv, AlgebraicNotation{}, &PushMoveOptions{
ForceMainline: true,
})
if err != nil {
t.Errorf("PushNotationMove() failed but should have succeeded")
}

if len(game.Moves()) != startMlen+1 {
t.Errorf("PushNotationMove() failed to update game.Moves()")
}
if len(game.Positions()) != startPlen+1 {
t.Errorf("PushNotationMove() failed to update game.Positions()")
}
}

func validateSplit(t *testing.T, origPgn string, expectedLastLines []string) {
reader := strings.NewReader(origPgn)
scanner := NewScanner(reader)
Expand Down
2 changes: 2 additions & 0 deletions pgn.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ func (p *Parser) Parse() (*Game, error) {
if p.game.outcome == UnknownOutcome {
p.game.outcome = NoOutcome
}
p.game.currentMove = p.currentMove

return p.game, nil
}

Expand Down
Loading