implement predicate; decruft; quiet phpunit

This commit is contained in:
Meredith L. Patterson 2013-12-16 13:42:14 +01:00
parent c2cde65764
commit bd48af7b90
3 changed files with 52 additions and 5 deletions

View 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);
}
}
?>