2013-12-16 13:42:14 +01:00
|
|
|
<?php
|
|
|
|
|
include_once 'hammer.php';
|
|
|
|
|
|
|
|
|
|
function predTest($token)
|
|
|
|
|
{
|
|
|
|
|
return ($token[0] === $token[1]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class PredicateTest extends PHPUnit_Framework_TestCase
|
|
|
|
|
{
|
|
|
|
|
protected $parser;
|
|
|
|
|
|
|
|
|
|
protected function setUp()
|
|
|
|
|
{
|
2013-12-18 00:32:56 +01:00
|
|
|
$this->parser = hammer_predicate(hammer_many1(hammer_choice(hammer_ch('a'), hammer_ch('b'))), "predTest");
|
2013-12-16 13:42:14 +01:00
|
|
|
}
|
|
|
|
|
public function testSuccess()
|
|
|
|
|
{
|
2013-12-18 00:32:56 +01:00
|
|
|
$result1 = hammer_parse($this->parser, "aa");
|
|
|
|
|
$result2 = hammer_parse($this->parser, "bb");
|
2013-12-16 13:42:14 +01:00
|
|
|
$this->assertEquals(["a", "a"], $result1);
|
|
|
|
|
$this->assertEquals(["b", "b"], $result2);
|
|
|
|
|
}
|
|
|
|
|
public function testFailure()
|
|
|
|
|
{
|
2013-12-18 00:32:56 +01:00
|
|
|
$result = hammer_parse($this->parser, "ab");
|
2013-12-16 13:42:14 +01:00
|
|
|
$this->assertEquals(NULL, $result);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
?>
|