implement predicate; decruft; quiet phpunit
This commit is contained in:
parent
c2cde65764
commit
bd48af7b90
3 changed files with 52 additions and 5 deletions
31
src/bindings/php/Tests/PredicateTest.php
Normal file
31
src/bindings/php/Tests/PredicateTest.php
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
include_once 'hammer.php';
|
||||
|
||||
function predTest($token)
|
||||
{
|
||||
return ($token[0] === $token[1]);
|
||||
}
|
||||
|
||||
class PredicateTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $parser;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->parser = predicate(h_many1(choice(ch('a'), ch('b'))), "predTest");
|
||||
}
|
||||
public function testSuccess()
|
||||
{
|
||||
$result1 = h_parse($this->parser, "aa");
|
||||
$result2 = h_parse($this->parser, "bb");
|
||||
$this->assertEquals(["a", "a"], $result1);
|
||||
$this->assertEquals(["b", "b"], $result2);
|
||||
}
|
||||
public function testFailure()
|
||||
{
|
||||
$result = h_parse($this->parser, "ab");
|
||||
$this->assertEquals(NULL, $result);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue