From 9f48f7afeb8e73f4e6168694180edeee131c63e4 Mon Sep 17 00:00:00 2001 From: Janis Date: Sun, 5 Apr 2026 13:12:19 +0200 Subject: [PATCH] test(io): add comprehensive error path coverage to FenParserTest Added 3 new tests for missing error paths: - Invalid en passant square parsing (e.g., "x5") - Half-move clock non-integer (e.g., "abc") - Full-move number non-integer (e.g., "abc") Updated 3 existing error tests to verify error messages: - "expected 6" for invalid parts count - "color" for invalid active color - "castling" for invalid castling rights All error assertions now use .fold() to verify message content, improving test robustness. Test count increased from 19 to 22. Co-Authored-By: Claude Sonnet 4.6 --- .../de/nowchess/io/fen/FenParserTest.scala | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/modules/io/src/test/scala/de/nowchess/io/fen/FenParserTest.scala b/modules/io/src/test/scala/de/nowchess/io/fen/FenParserTest.scala index f192cb1..c54bf13 100644 --- a/modules/io/src/test/scala/de/nowchess/io/fen/FenParserTest.scala +++ b/modules/io/src/test/scala/de/nowchess/io/fen/FenParserTest.scala @@ -91,18 +91,21 @@ class FenParserTest extends AnyFunSuite with Matchers: val context = FenParser.parseFen(fen) context.isLeft shouldBe true + context.fold(msg => msg should include("expected 6"), _ => fail("Expected Left")) 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.isLeft shouldBe true + context.fold(msg => msg should include("color"), _ => fail("Expected Left")) 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.isLeft shouldBe true + context.fold(msg => msg should include("castling"), _ => fail("Expected Left")) test("parseFen: castling '-' produces no castling rights"): val fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w - - 0 1" @@ -151,3 +154,24 @@ class FenParserTest extends AnyFunSuite with Matchers: result.isLeft shouldBe true result.fold(msg => msg should include("Invalid FEN"), _ => fail("Expected Left")) + test("parse full FEN - invalid en passant"): + val fen = "rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq x5 0 1" + val context = FenParser.parseFen(fen) + + context.isLeft shouldBe true + context.fold(msg => msg should include("en passant"), _ => fail("Expected Left")) + + test("parse full FEN - invalid half-move clock"): + val fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - abc 1" + val context = FenParser.parseFen(fen) + + context.isLeft shouldBe true + context.fold(msg => msg should include("half-move clock"), _ => fail("Expected Left")) + + test("parse full FEN - invalid full-move number"): + val fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 abc" + val context = FenParser.parseFen(fen) + + context.isLeft shouldBe true + context.fold(msg => msg should include("full move number"), _ => fail("Expected Left")) +