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:
2026-04-05 13:19:55 +02:00
parent 2d07f1f75a
commit f0316013fc
@@ -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
}