From bd8ff3e485e6b94910cb48f71034b77d3b45b170 Mon Sep 17 00:00:00 2001 From: DHTMLGoodies Date: Fri, 14 Apr 2017 19:17:26 +0200 Subject: [PATCH] updates --- PgnParser.php | 2 +- test/ParserTest.php | 18 ++++++++++++++++++ test/pgn/arrowtest.pgn | 16 ++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 test/pgn/arrowtest.pgn diff --git a/PgnParser.php b/PgnParser.php index 7130c8e..8faf2d4 100755 --- a/PgnParser.php +++ b/PgnParser.php @@ -66,7 +66,7 @@ class PgnParser $c = $this->pgnContent; $c = preg_replace('/"\]\s{0,10}\[/s', "]\n[", $c); - $c = preg_replace('/"\]\s{0,10}([\.0-9])/s', "\"]\n\n$1", $c); + $c = preg_replace('/"\]\s{0,10}([\.0-9]|{)/s', "\"]\n\n$1", $c); $c = preg_replace("/{\s{0,6}\[%emt[^\}]*?\}/","",$c); diff --git a/test/ParserTest.php b/test/ParserTest.php index f762327..59de078 100755 --- a/test/ParserTest.php +++ b/test/ParserTest.php @@ -2139,6 +2139,24 @@ Rc8 Ne6+ 72. Kf6 d2 73. c5+ Kd7 0-1'; } + /** + * @test + */ + public function shouldHandleDifficultPgnWithArrowsAndSquares(){ + // given + $pgnParser = new PgnParser("pgn/arrowtest.pgn"); + + // when + $game = $pgnParser->getGameByIndex(0); + + // then + $this->assertEquals(8, count($game["moves"])); + + $this->assertNotEmpty($game["moves"][0]); + $m = $game["moves"][1]; + $this->assertEquals("Qxf7+", $m["m"], "MOVE: ". json_encode($game["moves"][0])); + } + /** * @test */ diff --git a/test/pgn/arrowtest.pgn b/test/pgn/arrowtest.pgn new file mode 100644 index 0000000..22aace3 --- /dev/null +++ b/test/pgn/arrowtest.pgn @@ -0,0 +1,16 @@ +[eventdate "1998.??.??"] +[eventdate "1998.??.??"] +[setup "1"] +[castle "1"] +[index "1"] +[ts "1487793853499"] +[event " White to move."] +[site "?"] +[date "1998.??.??"] +[round "?"] +[white "White mates in 4"] +[black "White mates in 4 1001 Brilliant Ways to Checkmate"] +[result "1-0"] +[fen "r1b2rk1/pp1p1pp1/1b1p2B1/n1qQ2p1/8/5N2/P3RPPP/4R1K1 w - - 0 1"] +[plycount "7"] +{[%ar d5g8][%sq f7,h7]}1. Qxf7+{[%ar g6f7] [%sq g8]} Rxf7 2. Re8+ Rf8 3. Rxf8+ Kxf8 4. Re8# \ No newline at end of file