From f0316013fccbfc7dbda5b4e40072118b36c49e2a Mon Sep 17 00:00:00 2001 From: Janis Date: Sun, 5 Apr 2026 13:19:55 +0200 Subject: [PATCH] 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 --- .../de/nowchess/io/pgn/PgnParserTest.scala | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/modules/io/src/test/scala/de/nowchess/io/pgn/PgnParserTest.scala b/modules/io/src/test/scala/de/nowchess/io/pgn/PgnParserTest.scala index d7e8db4..1a4c2f1 100644 --- a/modules/io/src/test/scala/de/nowchess/io/pgn/PgnParserTest.scala +++ b/modules/io/src/test/scala/de/nowchess/io/pgn/PgnParserTest.scala @@ -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 + } +