Skip to content

Commit

Permalink
Merge pull request #4 from zacharyrankin/default-fix
Browse files Browse the repository at this point in the history
Setting a default value for the token variable.
  • Loading branch information
RobertVelton committed Nov 7, 2016
2 parents 3b68c8f + 030169b commit 250a77d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Tokenizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class Tokenizer
{
public function tokenize($html)
{
$tokens = [];

$length = strlen($html);
while ($length) {
$token = $tokens[] = $this->getToken($html);
Expand Down
9 changes: 9 additions & 0 deletions tests/lexer-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@

require_once __DIR__ . '/../vendor/autoload.php';

Test::create('should return an empty array for no value', function(Test $test) {
$tokenizer = new Tokenizer;
$tokens = $tokenizer->tokenize("");
$test->equals(
$tokens,
[]
);
});

Test::create('should tokenize whitespace before word', function(Test $test) {
$tokenizer = new Tokenizer;
$tokens = $tokenizer->tokenize(" a");
Expand Down

0 comments on commit 250a77d

Please sign in to comment.