test(io): add importGameContext tests to PgnParserTest
Added three test cases to validate importGameContext method: 1. Valid PGN with moves returns Right with populated GameContext 2. Invalid PGN (illegal move) returns Left with error message 3. PGN with no moves returns Right with initial position Tests use coordinate notation (e.g., e2e4) compatible with importGameContext's move replay mechanism. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -438,3 +438,33 @@ class PgnParserTest extends AnyFunSuite with Matchers:
|
||||
result shouldBe None
|
||||
}
|
||||
|
||||
test("importGameContext: valid PGN returns Right with GameContext") {
|
||||
val pgn = """[Event "Test"]
|
||||
[White "A"]
|
||||
[Black "B"]
|
||||
|
||||
1. e2e4 e7e5
|
||||
"""
|
||||
val result = PgnParser.importGameContext(pgn)
|
||||
result.isRight shouldBe true
|
||||
val ctx = result.fold(err => fail(s"Got error: $err"), identity)
|
||||
ctx.moves.length shouldBe 2
|
||||
ctx.turn shouldBe Color.White
|
||||
}
|
||||
|
||||
test("importGameContext: invalid PGN returns Left") {
|
||||
val pgn = "[Event \"T\"]\n\n1. d1d4"
|
||||
val result = PgnParser.importGameContext(pgn)
|
||||
result.isLeft shouldBe true
|
||||
result.fold(msg => msg should include("Illegal or impossible move"), _ => fail("Expected Left"))
|
||||
}
|
||||
|
||||
test("importGameContext: PGN with no moves returns Right with initial position") {
|
||||
val pgn = "[Event \"T\"]\n[White \"A\"]\n[Black \"B\"]\n"
|
||||
val result = PgnParser.importGameContext(pgn)
|
||||
result.isRight shouldBe true
|
||||
val ctx = result.fold(_ => fail(), identity)
|
||||
ctx.moves.isEmpty shouldBe true
|
||||
ctx.board shouldBe Board.initial
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user