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 <noreply@anthropic.com>
This commit is contained in:
2026-04-05 13:12:19 +02:00
parent 3214386556
commit 9f48f7afeb
@@ -91,18 +91,21 @@ class FenParserTest extends AnyFunSuite with Matchers:
val context = FenParser.parseFen(fen) val context = FenParser.parseFen(fen)
context.isLeft shouldBe true context.isLeft shouldBe true
context.fold(msg => msg should include("expected 6"), _ => fail("Expected Left"))
test("parse full FEN - invalid color"): test("parse full FEN - invalid color"):
val fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR x KQkq - 0 1" val fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR x KQkq - 0 1"
val context = FenParser.parseFen(fen) val context = FenParser.parseFen(fen)
context.isLeft shouldBe true context.isLeft shouldBe true
context.fold(msg => msg should include("color"), _ => fail("Expected Left"))
test("parse full FEN - invalid castling"): test("parse full FEN - invalid castling"):
val fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w XYZ - 0 1" val fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w XYZ - 0 1"
val context = FenParser.parseFen(fen) val context = FenParser.parseFen(fen)
context.isLeft shouldBe true context.isLeft shouldBe true
context.fold(msg => msg should include("castling"), _ => fail("Expected Left"))
test("parseFen: castling '-' produces no castling rights"): test("parseFen: castling '-' produces no castling rights"):
val fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w - - 0 1" 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.isLeft shouldBe true
result.fold(msg => msg should include("Invalid FEN"), _ => fail("Expected Left")) 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"))