diff --git a/src/Hexpress.php b/src/Hexpress.php index 85123df..a8ee0ef 100644 --- a/src/Hexpress.php +++ b/src/Hexpress.php @@ -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; } diff --git a/src/Hexpress/Many.php b/src/Hexpress/Many.php index 1285804..018a062 100644 --- a/src/Hexpress/Many.php +++ b/src/Hexpress/Many.php @@ -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); } } diff --git a/tests/Case/Hexpress/Hexpress/ManyTest.php b/tests/Case/Hexpress/Hexpress/ManyTest.php index e0f0654..6087c11 100644 --- a/tests/Case/Hexpress/Hexpress/ManyTest.php +++ b/tests/Case/Hexpress/Hexpress/ManyTest.php @@ -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 @@ -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()); + } } diff --git a/tests/Case/Hexpress/HexpressTest.php b/tests/Case/Hexpress/HexpressTest.php index d1269c2..4116ffd 100644 --- a/tests/Case/Hexpress/HexpressTest.php +++ b/tests/Case/Hexpress/HexpressTest.php @@ -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());