From 8b5303fdab0376601a441890d73f433ee786d117 Mon Sep 17 00:00:00 2001 From: Janis Date: Sun, 5 Apr 2026 13:45:25 +0200 Subject: [PATCH] test(io): add exportGameContext tests Add two simple tests for exportGameContext functionality: 1. Test that moves are preserved in PGN output 2. Test that empty game exports headers with proper terminator Co-Authored-By: Claude Sonnet 4.6 --- .../de/nowchess/io/pgn/PgnExporterTest.scala | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/modules/io/src/test/scala/de/nowchess/io/pgn/PgnExporterTest.scala b/modules/io/src/test/scala/de/nowchess/io/pgn/PgnExporterTest.scala index af7de95..d45846d 100644 --- a/modules/io/src/test/scala/de/nowchess/io/pgn/PgnExporterTest.scala +++ b/modules/io/src/test/scala/de/nowchess/io/pgn/PgnExporterTest.scala @@ -1,8 +1,9 @@ package de.nowchess.io.pgn import de.nowchess.api.board.{PieceType, *} -import de.nowchess.api.move.PromotionPiece -import de.nowchess.api.game.{GameHistory, HistoryMove} +import de.nowchess.api.move.{PromotionPiece, Move, MoveType} +import de.nowchess.api.game.{GameHistory, HistoryMove, GameContext} +import de.nowchess.io.pgn.PgnParser import org.scalatest.funsuite.AnyFunSuite import org.scalatest.matchers.should.Matchers @@ -113,3 +114,23 @@ class PgnExporterTest extends AnyFunSuite with Matchers: val pgn = PgnExporter.exportGame(Map.empty, history) pgn shouldBe "1. e4 *" + test("exportGameContext: moves are preserved in output") { + val moves = List( + Move(Square(File.E, Rank.R2), Square(File.E, Rank.R4), MoveType.Normal), + Move(Square(File.E, Rank.R7), Square(File.E, Rank.R5), MoveType.Normal) + ) + val ctx = GameContext.initial.copy(moves = moves) + val exported = PgnExporter.exportGameContext(ctx) + + exported.contains("e4") shouldBe true + exported.contains("e5") shouldBe true + } + + test("exportGameContext: empty game returns headers only") { + val ctx = GameContext.initial + val exported = PgnExporter.exportGameContext(ctx) + + exported.contains("[Event") shouldBe true + exported.contains("*") shouldBe true // Result terminator + } +