still more tests failing because sequence/choice don't return right
This commit is contained in:
parent
eb2855dcb4
commit
a234bdfab3
2 changed files with 58 additions and 0 deletions
25
src/bindings/php/Tests/IgnoreTest.php
Normal file
25
src/bindings/php/Tests/IgnoreTest.php
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
<?php
|
||||||
|
include_once 'hammer.php';
|
||||||
|
|
||||||
|
class IgnoreTest extends PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
protected $parser;
|
||||||
|
|
||||||
|
protected function setUp()
|
||||||
|
{
|
||||||
|
$this->parser = sequence(ch("a"), h_ignore(ch("b")), ch("c"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSuccess()
|
||||||
|
{
|
||||||
|
$result = h_parse($this->parser, "abc");
|
||||||
|
$this->assertEquals(array("a", "c"), $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFailure()
|
||||||
|
{
|
||||||
|
$result = h_parse($this->parser, "ac");
|
||||||
|
$this->assertEquals(NULL, $result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
33
src/bindings/php/Tests/OptionalTest.php
Normal file
33
src/bindings/php/Tests/OptionalTest.php
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
<?php
|
||||||
|
include_once 'hammer.php';
|
||||||
|
|
||||||
|
class OptionalTest extends PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
protected $parser;
|
||||||
|
|
||||||
|
protected function setUp()
|
||||||
|
{
|
||||||
|
$this->parser = sequence(ch("a"), h_optional(choice(ch("b"), ch("c"))), ch("d"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSuccess()
|
||||||
|
{
|
||||||
|
$result1 = h_parse($this->parser, "abd");
|
||||||
|
$result2 = h_parse($this->parser, "acd");
|
||||||
|
$result3 = h_parse($this->parser, "ad");
|
||||||
|
$this->assertEquals(array("a", "b", "d"), $result1);
|
||||||
|
$this->assertEquals(array("a", "c", "d"), $result2);
|
||||||
|
$this->assertEquals(array("a", NULL, "d"), $result3);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFailure()
|
||||||
|
{
|
||||||
|
$result1 = h_parse($this->parser, "aed");
|
||||||
|
$result2 = h_parse($this->parser, "ab");
|
||||||
|
$result3 = h_parse($this->parser, "ac");
|
||||||
|
$this->assertEquals(NULL, $result1);
|
||||||
|
$this->assertEquals(NULL, $result2);
|
||||||
|
$this->assertEquals(NULL, $result3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue