Skip to content

Commit

Permalink
Made sure that empty lines are ignored when parsing chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
waltertamboer committed May 12, 2018
1 parent f38bfbe commit 67fa14b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Splitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private function parseTags(callable $callback, int &$result, string $line)
return;
}

if ($this->mode === self::SPLIT_CHUNKS) {
if ($this->mode === self::SPLIT_CHUNKS && trim($this->buffer) !== '') {
$result++;

$callback($this->buffer);
Expand Down
36 changes: 35 additions & 1 deletion tests/SplitterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function testSplitPerChunk()
static::assertEquals(2, $result);
}

public function testSplitLichessGames()
public function testSplitMultipleNewLinesInToGames()
{
// Arrange
$stream = $this->createStream("[A]
Expand Down Expand Up @@ -144,4 +144,38 @@ public function testSplitLichessGames()
// Assert
static::assertEquals(4, $result);
}

public function testSplitMultipleNewLinesInToChunks()
{
// Arrange
$stream = $this->createStream("[A]
1. e4 e5
[B]
1. e4 e5
[C]
1. d4 d5
[D]
1. e4 e5
");
$splitter = new Splitter($stream, Splitter::SPLIT_CHUNKS);
$callback = function(string $buffer) { };

// Act
$result = $splitter->split($callback);

// Assert
static::assertEquals(8, $result);
}
}

0 comments on commit 67fa14b

Please sign in to comment.