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 + } +