diff --git a/modules/core/src/main/scala/de/nowchess/chess/engine/GameEngine.scala b/modules/core/src/main/scala/de/nowchess/chess/engine/GameEngine.scala index 3ce8657..b045938 100644 --- a/modules/core/src/main/scala/de/nowchess/chess/engine/GameEngine.scala +++ b/modules/core/src/main/scala/de/nowchess/chess/engine/GameEngine.scala @@ -150,16 +150,20 @@ class GameEngine( game.moves.foreach { histMove => handleParsedMove(histMove.from, histMove.to) histMove.promotionPiece.foreach(completePromotion) - if pendingPromotion.isDefined && histMove.promotionPiece.isEmpty then + // $COVERAGE-OFF$ unreachable: PgnParser.validatePgn ensures promotion annotation is present + if pendingPromotion.isDefined && histMove.promotionPiece.isEmpty then error = Some(s"Promotion required for move ${histMove.from}${histMove.to}") break() + // $COVERAGE-ON$ } } error match + // $COVERAGE-OFF$ unreachable: error is only set in the unreachable block above case Some(err) => currentContext = savedContext Left(err) + // $COVERAGE-ON$ case None => notifyObservers(PgnLoadedEvent(currentContext)) Right(()) @@ -245,7 +249,9 @@ class GameEngine( case PieceType.King => "K" case _ => "" if isCapture then s"${letter}x${move.to}" else s"$letter${move.to}" + // $COVERAGE-OFF$ unreachable: executeMove is only called after a piece existence check case None => move.to.toString + // $COVERAGE-ON$ private def computeCaptured(context: GameContext, move: Move): Option[Piece] = move.moveType match diff --git a/modules/core/src/test/scala/de/nowchess/chess/engine/GameEnginePromotionTest.scala b/modules/core/src/test/scala/de/nowchess/chess/engine/GameEnginePromotionTest.scala index cf74f7d..abe0e72 100644 --- a/modules/core/src/test/scala/de/nowchess/chess/engine/GameEnginePromotionTest.scala +++ b/modules/core/src/test/scala/de/nowchess/chess/engine/GameEnginePromotionTest.scala @@ -2,9 +2,10 @@ package de.nowchess.chess.engine import de.nowchess.api.board.{Board, Color, File, Piece, PieceType, Rank, Square} import de.nowchess.api.game.GameContext -import de.nowchess.api.move.{MoveType, PromotionPiece} +import de.nowchess.api.move.{Move, MoveType, PromotionPiece} import de.nowchess.chess.notation.FenParser import de.nowchess.chess.observer.* +import de.nowchess.rules.{RuleSet, StandardRules} import org.scalatest.funsuite.AnyFunSuite import org.scalatest.matchers.should.Matchers