Skip to content

Commit

Permalink
Merge pull request #3 from sizuhiko/develop
Browse files Browse the repository at this point in the history
Fix bugs
  • Loading branch information
sizuhiko committed May 29, 2016
2 parents 68b31c7 + aee16c4 commit bc94231
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Hexpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function tab()
*/
public function line()
{
$this->either(new Character('(?:\n)'), new Character('(?:\r\n)'));
$this->either([new Character('(?:\n)'), new Character('(?:\r\n)')]);

return $this;
}
Expand Down
3 changes: 3 additions & 0 deletions src/Hexpress/Many.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ trait Many
{
public function many($value = null, $minimum = 1)
{
if ($minimum > 1) {
return $this->limit($value, $minimum);
}
return $this->addValues(ManyValue::class, $value, $minimum);
}
}
Expand Down
7 changes: 7 additions & 0 deletions tests/Case/Hexpress/Hexpress/ManyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
namespace Test\Hexpress\Hexpress;

use Hexpress\Hexpress\Many;
use Hexpress\Hexpress\Limit;

class ExampleWithMany
{
use Many;
use Limit;
}

class ManyTest extends \PHPUnit_Framework_TestCase
Expand All @@ -20,4 +22,9 @@ public function testOperatorReturnsPlusIfMinimumIs1()
{
$this->assertEquals('+', (new \Hexpress\Hexpress\ManyValue('', 1))->operator());
}

public function testOperatorReturnsLimitIfMinimumOver1()
{
$this->assertEquals('/(?:(?:\w)+){2}/', (new \Hexpress\Hexpress())->many(function ($hex) {$hex->words();}, 2)->toRegExp());
}
}
5 changes: 5 additions & 0 deletions tests/Case/Hexpress/HexpressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ public function testItTakesChainAndTurnsIntoRegex()
$this->assertEquals('/(foo)/', $pattern->toRegExp());
}

public function testLineReturnsTheLineMatcher()
{
$this->assertEquals('(?:(?:\n)|(?:\r\n))', (new Hexpress())->line()->__toString());
}

public function testWordReturnsTheWordMatcher()
{
$this->assertEquals('\w', (new Hexpress())->word());
Expand Down

0 comments on commit bc94231

Please sign in to comment.