Bugfixes + support for getting shorter parsing format

This commit is contained in:
DHTMLGoodies
2017-08-17 13:53:35 +02:00
parent 9490f2cd09
commit 68d6e084c9
7 changed files with 185 additions and 18 deletions

View File

@@ -72,11 +72,11 @@ class ParserTest extends PHPUnit_Framework_TestCase
// when
$parser->move("e2e4");
$parser->move("e7e5");
$parser->move("c7c5");
// then
$this->assertEquals("e6", $parser->getEnPassantSquare());
$this->assertEquals("c6", $parser->getEnPassantSquare());
$parser->move("e4e5");
@@ -2358,4 +2358,79 @@ Rc8 Ne6+ 72. Kf6 d2 73. c5+ Kd7 0-1';
// then
$this->assertEquals(30, count($games));
}
/**
* @test
*/
public function shouldParseProblematic_4(){
// given
$parser = new PgnParser("pgn/problematic4.pgn");
// when
$games = $parser->getGames();
// then
$this->assertEquals(1, count($games));
}
/**
* @test
*/
public function shouldBeAbleToImportWithoutFenForEachMove(){
// given
$parser = new PgnParser("pgn/greatgames.pgn");
// when
$games = $parser->getGamesShort();
$game = $games[0];
// then
$this->assertEquals(10, count($games));
$this->assertArrayNotHasKey("fen", $game["moves"][0], json_encode($game["moves"][0]));
$this->assertEquals("e2e4", $game["moves"][0]["n"], json_encode($game["moves"][0]));
}
/**
* @test
*/
public function shouldBeAbleToHandleVariationWhenUsingShortVersion()
{
// given
$parser = new PgnParser("pgn/variation.pgn");
// when
$games = $parser->getGamesShort();
$this->assertEquals(1, count($games), json_encode($games));
$game = $games[0];
$variations = $game["moves"][0]["v"];
$msg = json_encode($variations);
// then
$this->assertEquals(3, count($variations), $msg);
$this->assertEquals(2, count($variations[0]), $msg);
$this->assertEquals(1, count($variations[1]), $msg);
$this->assertEquals(1, count($variations[2]), $msg);
$var1 = $variations[0];
$this->assertEquals("d2d4", $var1[0]["n"]);
$this->assertEquals("d2d4", $var1[0]["n"]);
$var2 = $variations[1];
$this->assertEquals("c2c4", $var2[0]["n"]);
$var2 = $variations[2];
$this->assertEquals("f2f4", $var2[0]["n"]);
$var3 = $game["moves"][2]["v"][0];
$this->assertEquals("b1c3", $var3[0]["n"], json_encode($game));
}
}

15
test/pgn/problematic4.pgn Normal file
View File

@@ -0,0 +1,15 @@
[Event "e"]
[Site "s"]
[Date "????.??.??"]
[Round "r"]
[White "w"]
[Black "b"]
[Result "*"]
[FEN "5k2/8/4KP2/8/8/8/8/8 w - - 0 1"]
[SetUp "1"]
[WhiteElo "1500"]
[BlackElo "1500"]
[ECO ""]
[CurrentPosition "5k2/8/4KP2/8/8/8/8/8 w - - 0 1"]
1.f7 Kg7 2.Ke7 Kh7 3.f8=Q *

11
test/pgn/variation.pgn Normal file
View File

@@ -0,0 +1,11 @@
[Event "001 Art of Attack"]
[Site "?"]
[Date "????.??.??"]
[Round "?"]
[White "?"]
[Black "?"]
[Result "*"]
[SetUp "1"]
[PlyCount "5"]
1. e4 (1. d4 Nf6) (1. c4) (1. f4) e5 2. Nf3 (2. Nc3) f5