Skip to content

Commit 5eda7e7

Browse files
committed
Added unit tests to test if Z0 can be parsed
1 parent 8246b5e commit 5eda7e7

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

src/Lexer/AbstractLexer.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ public function getNextToken(): ?TokenInterface
5454
return new TagPair($matches[1], $matches[3]);
5555
}
5656

57+
// Match a null move
58+
if (preg_match('/^\s*--\s*/', $this->buffer, $matches)) {
59+
$this->buffer = substr($this->buffer, strlen($matches[0]));
60+
return new NullMove();
61+
}
62+
63+
// Match a null move
64+
if (preg_match('/^\s*Z0\s*/', $this->buffer, $matches)) {
65+
$this->buffer = substr($this->buffer, strlen($matches[0]));
66+
return new NullMove();
67+
}
68+
5769
// Match an end result:
5870
if (preg_match('/^\s*(\*|1-0|0-1|1\/2-1\/2)\s*/', $this->buffer, $matches)) {
5971
$this->buffer = substr($this->buffer, strlen($matches[0]));
@@ -96,18 +108,6 @@ public function getNextToken(): ?TokenInterface
96108
return new NumericAnnotationGlyph((int)trim($matches[1]));
97109
}
98110

99-
// Match a null move
100-
if (preg_match('/^\s*--\s*/', $this->buffer, $matches)) {
101-
$this->buffer = substr($this->buffer, strlen($matches[0]));
102-
return new NullMove();
103-
}
104-
105-
// Match a null move
106-
if (preg_match('/^\s*Z0\s*/', $this->buffer, $matches)) {
107-
$this->buffer = substr($this->buffer, strlen($matches[0]));
108-
return new NullMove();
109-
}
110-
111111
throw InvalidTokenException::createForBuffer($this->buffer);
112112
}
113113

tests/Lexer/AbstractLexerTest.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public function testMatchEndResultWhiteWins()
126126
static::assertEquals('1-0', $result->getResult());
127127
}
128128

129-
public function testMatchNullMove()
129+
public function testMatchNullMoveWithDashes()
130130
{
131131
// Arrange
132132
$buffer = '--';
@@ -140,6 +140,20 @@ public function testMatchNullMove()
140140
static::assertInstanceOf(NullMove::class, $result);
141141
}
142142

143+
public function testMatchNullMoveWithZ0()
144+
{
145+
// Arrange
146+
$buffer = 'Z0';
147+
148+
$lexer = new StringLexer($buffer);
149+
150+
// Act
151+
$result = $lexer->getNextToken();
152+
153+
// Assert
154+
static::assertInstanceOf(NullMove::class, $result);
155+
}
156+
143157
public function testMoveNumberWhite()
144158
{
145159
// Arrange

0 commit comments

Comments
 (0)