public function testUtf8() { $parser = ParserHelper::compile(new RegexExpression(".")); $result = $parser->parse("€"); $this->assertNotNull($result); $this->assertEquals("€", $result->getString()); }
public function testAlternativeRepeat() { $n = 500000; $expression = new RepeaterExpression(new AlternativeExpression(array(new ConstantExpression("a"), new ConstantExpression("b")))); $target = str_repeat("a", $n); $parser = ParserHelper::compile($expression); $result = $parser->parse($target); $this->assertCount($n, $result->getResults()); }
public function testUtf8() { $expression = new AnyExpression(); $parser = ParserHelper::compile($expression); $target = "€€€"; $result = $parser->parse($target); $this->assertNotNull($result); $this->assertEquals("€", $result->getString()); }
public function testAlternativeKey() { $parser = ParserHelper::compile(new AlternativeExpression(array(1 => new ConstantExpression("a"), "key" => new ConstantExpression("b")))); $result = $parser->parse("a"); $this->assertNotNull($result); $this->assertEquals(1, $result->getKey()); $result = $parser->parse("b"); $this->assertNotNull($result); $this->assertEquals("key", $result->getKey()); }
public function testRecursive() { $parser = ParserHelper::compile(new JoinedExpression(new JoinedExpression(new ConstantExpression("a"), new ConstantExpression(",")), new ConstantExpression(","))); /** @var \PeterVanDommelen\Parser\Expression\Joined\JoinedExpressionResult $result */ $result = $parser->parse("a,a"); $this->assertNotNull($result); $this->assertEquals("a,a", $result->getString()); $expected = new JoinedExpressionResult(array(new JoinedExpressionResult(array(new ConstantExpressionResult("a"), new ConstantExpressionResult("a")), array(new ConstantExpressionResult(",")))), array()); $this->assertEquals($expected, $result); }
public function testEndOfString() { $expression = new EndOfStringExpression(); $parser = ParserHelper::compile($expression); $result = $parser->parse(""); $this->assertNotNull($result); $this->assertEquals("", $result->getString()); $result = $parser->parse("a"); $this->assertNull($result); }
public function testUseKeyAsIndex() { $target = "abcdefg"; $parser = ParserHelper::compile(new ConcatenatedExpression(array("key" => new ConstantExpression("abc")))); /** @var ConcatenatedExpressionResult $result */ $result = $parser->parse($target); $this->assertNotNull($result); $this->assertEquals(3, $result->getLength()); /** @var ConstantExpressionResult $part_result */ $part_result = $result->getPart("key"); $this->assertEquals("abc", $part_result->getString()); }
public function testLeftRecursionRepeater() { $this->expectException(InvalidExpressionException::class); $expression = null; $expression = new RepeaterExpression(new ConcatenatedExpression(array(&$expression, new ConstantExpression("a")))); ParserHelper::compile($expression)->parse("a"); }
public function testStringDoesNotMatch() { $parser = ParserHelper::compile(new ConstantExpression("abc")); $result = $parser->parse("xabcdefg"); $this->assertNull($result); }