h_action test is written, but something is wrong with h_choice.

This commit is contained in:
Meredith L. Patterson 2013-11-30 17:10:24 -08:00
parent 72edbfa167
commit ce5a621ee3

View file

@ -0,0 +1,32 @@
<?php
include_once 'hammer.php';
class ActionTest extends PHPUnit_Framework_TestCase
{
protected $parser;
protected function actTest(string $token)
{
return strtoupper($token);
}
protected function setUp()
{
$this->parser = h_action(h_sequence(h_choice(h_ch("a"), h_ch("A")), h_choice(h_ch("b"), h_ch("B"))), "actTest");
}
public function testSuccess()
{
$result1 = h_parse($this->parser, "ab");
$result2 = h_parse($this->parser, "AB");
$result3 = h_parse($this->parser, "aB");
$this->assertEquals("AB", $result1);
$this->assertEquals("AB", $result2);
$this->assertEquals("AB", $result3);
}
public function testFailure()
{
$result = h_parse($this->parser, "XX");
$this->assertEquals(NULL, $result);
}
}
?>