Skip to content

Commit

Permalink
Also test skipping nested variations with Game.accept() (#798)
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasf committed Oct 7, 2021
1 parent bcce6cc commit 5587a8c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2791,8 +2791,16 @@ def end_variation(self):
else:
return super().end_variation()

game = chess.pgn.read_game(io.StringIO("1. e4 e5 (1... d5 2. exd5 Qxd5 3. Nc3 (3. c4) 3... Qa5)"), Visitor=BlackVariationsOnly)
self.assertEqual(game.accept(chess.pgn.StringExporter(headers=False)), "1. e4 e5 ( 1... d5 2. exd5 Qxd5 3. Nc3 Qa5 ) *")
pgn = "1. e4 e5 ( 1... d5 2. exd5 Qxd5 3. Nc3 ( 3. c4 ) 3... Qa5 ) *"
expected_pgn = "1. e4 e5 ( 1... d5 2. exd5 Qxd5 3. Nc3 Qa5 ) *"

# Driven by parser.
game = chess.pgn.read_game(io.StringIO(pgn), Visitor=BlackVariationsOnly)
self.assertEqual(game.accept(chess.pgn.StringExporter(headers=False)), expected_pgn)

# Driven by game tree traversal.
game = chess.pgn.read_game(io.StringIO(pgn)).accept(BlackVariationsOnly())
self.assertEqual(game.accept(chess.pgn.StringExporter(headers=False)), expected_pgn)


@unittest.skipIf(sys.platform == "win32" and (3, 8, 0) <= sys.version_info < (3, 8, 1), "https://bugs.python.org/issue34679")
Expand Down

0 comments on commit 5587a8c

Please sign in to comment.