Skip to content

Commit a223e5f

Browse files
committed
Added support for castling moves with zeroes
1 parent 5eda7e7 commit a223e5f

File tree

4 files changed

+28
-8
lines changed

4 files changed

+28
-8
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"type": "library",
66
"require": {
77
"php": "^7.1",
8-
"chesszebra/standard-algebraic-notation": "^1.0"
8+
"chesszebra/standard-algebraic-notation": "^1.4"
99
},
1010
"require-dev": {
1111
"phpunit/phpunit": "^6.4",

composer.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Lexer/AbstractLexer.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ public function getNextToken(): ?TokenInterface
8484
return new StandardAlgebraicNotation(new Notation($matches[1]));
8585
}
8686

87+
// Match a SAN (castling):
88+
if (preg_match('/^\s*(0-0(?:-0)?[\+\-\!\#\=\?]*)\s*/s', $this->buffer, $matches)) {
89+
$this->buffer = substr($this->buffer, strlen($matches[0]));
90+
return new StandardAlgebraicNotation(new Notation($matches[1]));
91+
}
92+
8793
// Match a SAN:
8894
if (preg_match('/^\s*([a-zA-Z][a-zA-Z0-9\+\-\!\#\=\?]+)\s*/s', $this->buffer, $matches)) {
8995
$this->buffer = substr($this->buffer, strlen($matches[0]));

tests/Lexer/AbstractLexerTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,20 @@ public function testMatchSANCastling()
316316
static::assertInstanceOf(StandardAlgebraicNotation::class, $result);
317317
}
318318

319+
public function testMatchSANCastlingZeroes()
320+
{
321+
// Arrange
322+
$buffer = '0-0';
323+
324+
$lexer = new StringLexer($buffer);
325+
326+
// Act
327+
$result = $lexer->getNextToken();
328+
329+
// Assert
330+
static::assertInstanceOf(StandardAlgebraicNotation::class, $result);
331+
}
332+
319333
public function testMatchSAN()
320334
{
321335
// Arrange

0 commit comments

Comments
 (0)