Commit Graph

11 Commits

Author SHA1 Message Date
Janis 09a70ed435 feat(io): implement PgnExporter.exportGameContext with move replay
PgnExporter now extends GameContextExport and implements exportGameContext,
which replays moves from GameContext.initial to reconstruct HistoryMove records
with proper castling/promotion info before generating PGN.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-05 13:20:59 +02:00
Janis f0316013fc test(io): add importGameContext tests to PgnParserTest
Added three test cases to validate importGameContext method:
1. Valid PGN with moves returns Right with populated GameContext
2. Invalid PGN (illegal move) returns Left with error message
3. PGN with no moves returns Right with initial position

Tests use coordinate notation (e.g., e2e4) compatible with importGameContext's move replay mechanism.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-05 13:19:55 +02:00
Janis 2d07f1f75a refactor(io): remove dead code from PgnParser.importGameContext
Remove unnecessary if/else check (lines 49-50) that could never be true.
DefaultRules.applyMove always calls .withMove(move) on the context,
so finalCtx.moves is always populated when game.moves.nonEmpty.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-05 13:15:41 +02:00
Janis 7c42260d14 feat(io): implement PgnParser.importGameContext with move replay
Implement the importGameContext method to validate PGN input via validatePgn()
and replay each move using DefaultRules.applyMove to populate GameContext.moves.
Returns final GameContext with all moves applied or error message on failure.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-05 13:14:25 +02:00
Janis 9f48f7afeb 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>
2026-04-05 13:12:19 +02:00
Janis 3214386556 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>
2026-04-05 13:10:24 +02:00
Janis c0a3592d3d refactor(io): implement FenParser.parseFen returning Either with detailed error messages
Update parseFen to return Either[String, GameContext] with specific error messages for each validation failure:
- Invalid parts count: reports expected 6 fields
- Invalid board: clear message about board position
- Invalid color: explains expected 'w' or 'b'
- Invalid castling, en passant, and move counts with clear descriptions

Simplify importGameContext to delegate directly to parseFen.

Keep helper methods (parseColor, parseCastling, parseEnPassant, etc.) returning Option as before.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-05 12:58:15 +02:00
Janis 6fcb880b93 fix(io): update GameContextExport to Scala 3 syntax and add importGameContext tests
- Update GameContextExport trait to use Scala 3 syntax (colon-based) to match GameContextImport
- Add test coverage for FenParser.importGameContext method:
  * Valid FEN string returns Right[GameContext] with correct context data
  * Invalid FEN string returns Left[String] with error message

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-05 12:43:25 +02:00
Janis f6f05ff2a1 refactor(io): change GameContextImport return type from Option to Either
Update GameContextImport trait to return Either[String, GameContext] instead of
Option[GameContext] to provide better error context during parsing. Update FenParser
implementation to convert Option to Either using toRight().

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-05 12:33:13 +02:00
Janis 9b3bbfbcb7 refactor(core): integrate Rule module and update GameContext handling 2026-04-04 20:25:20 +02:00
Janis 6def31dd80 refactor(core): add IO module and integrate GameContext import/export traits 2026-04-04 19:50:08 +02:00