fix(io): update FEN tests to use Either API after parseFen signature change

FenParser.parseFen now returns Either[String, GameContext] instead of Option.
Updated all tests to use Either combinators (isRight, isLeft, fold) instead
of Option methods (isDefined, get). Both FenParserTest and FenExporterTest
now properly handle the Either-based return type.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-05 13:10:24 +02:00
parent c0a3592d3d
commit 3214386556
2 changed files with 26 additions and 20 deletions
@@ -97,6 +97,6 @@ class FenExporterTest extends AnyFunSuite with Matchers:
)
val fen = FenExporter.gameContextToFen(gameContext)
FenParser.parseFen(fen) match
case Some(ctx) => ctx.halfMoveClock shouldBe 42
case None => fail("FEN parsing failed")
case Right(ctx) => ctx.halfMoveClock shouldBe 42
case Left(err) => fail(s"FEN parsing failed: $err")
@@ -66,49 +66,55 @@ class FenParserTest extends AnyFunSuite with Matchers:
val fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
val context = FenParser.parseFen(fen)
context.isDefined shouldBe true
context.get.turn shouldBe Color.White
context.get.castlingRights.whiteKingSide shouldBe true
context.get.castlingRights.whiteQueenSide shouldBe true
context.get.castlingRights.blackKingSide shouldBe true
context.get.castlingRights.blackQueenSide shouldBe true
context.get.enPassantSquare shouldBe None
context.get.halfMoveClock shouldBe 0
context.isRight shouldBe true
context.fold(_ => fail(), ctx =>
ctx.turn shouldBe Color.White
ctx.castlingRights.whiteKingSide shouldBe true
ctx.castlingRights.whiteQueenSide shouldBe true
ctx.castlingRights.blackKingSide shouldBe true
ctx.castlingRights.blackQueenSide shouldBe true
ctx.enPassantSquare shouldBe None
ctx.halfMoveClock shouldBe 0
)
test("parse full FEN - after e4"):
val fen = "rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1"
val context = FenParser.parseFen(fen)
context.get.turn shouldBe Color.Black
context.get.enPassantSquare shouldBe Some(Square(File.E, Rank.R3))
context.fold(_ => fail(), ctx =>
ctx.turn shouldBe Color.Black
ctx.enPassantSquare shouldBe Some(Square(File.E, Rank.R3))
)
test("parse full FEN - invalid parts count"):
val fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq"
val context = FenParser.parseFen(fen)
context.isDefined shouldBe false
context.isLeft shouldBe true
test("parse full FEN - invalid color"):
val fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR x KQkq - 0 1"
val context = FenParser.parseFen(fen)
context.isDefined shouldBe false
context.isLeft shouldBe true
test("parse full FEN - invalid castling"):
val fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w XYZ - 0 1"
val context = FenParser.parseFen(fen)
context.isDefined shouldBe false
context.isLeft shouldBe true
test("parseFen: castling '-' produces no castling rights"):
val fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w - - 0 1"
val context = FenParser.parseFen(fen)
context.isDefined shouldBe true
context.get.castlingRights.whiteKingSide shouldBe false
context.get.castlingRights.whiteQueenSide shouldBe false
context.get.castlingRights.blackKingSide shouldBe false
context.get.castlingRights.blackQueenSide shouldBe false
context.isRight shouldBe true
context.fold(_ => fail(), ctx =>
ctx.castlingRights.whiteKingSide shouldBe false
ctx.castlingRights.whiteQueenSide shouldBe false
ctx.castlingRights.blackKingSide shouldBe false
ctx.castlingRights.blackQueenSide shouldBe false
)
test("parseBoard: returns None when a rank has too many files (overflow beyond 8)"):
// "9" alone would advance fileIdx to 9, exceeding 8 → None