sepby also plagued by sequence/choice return issues
This commit is contained in:
parent
a234bdfab3
commit
5c5a10b5c1
2 changed files with 58 additions and 0 deletions
31
src/bindings/php/Tests/SepBy1Test.php
Normal file
31
src/bindings/php/Tests/SepBy1Test.php
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
<?php
|
||||||
|
include_once 'hammer.php';
|
||||||
|
|
||||||
|
class SepBy1Test extends PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
protected $parser;
|
||||||
|
|
||||||
|
protected function setUp()
|
||||||
|
{
|
||||||
|
$this->parser = h_sepBy1(choice(ch("1"), ch("2"), ch("3")), ch(","));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSuccess()
|
||||||
|
{
|
||||||
|
$result1 = h_parse($this->parser, "1,2,3");
|
||||||
|
$result2 = h_parse($this->parser, "1,3,2");
|
||||||
|
$result3 = h_parse($this->parser, "1,3");
|
||||||
|
$result4 = h_parse($this->parser, "3");
|
||||||
|
$this->assertEquals(array("1", "2", "3"), $result1);
|
||||||
|
$this->assertEquals(array("1", "3", "2"), $result2);
|
||||||
|
$this->assertEquals(array("1", "3"), $result3);
|
||||||
|
$this->assertEquals(array("3"), $result4);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFailure()
|
||||||
|
{
|
||||||
|
$result = h_parse($this->parser, "");
|
||||||
|
$this->assertEquals(NULL, $result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
27
src/bindings/php/Tests/SepByTest.php
Normal file
27
src/bindings/php/Tests/SepByTest.php
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
<?php
|
||||||
|
include_once 'hammer.php';
|
||||||
|
|
||||||
|
class SepByTest extends PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
protected $parser;
|
||||||
|
|
||||||
|
protected function setUp()
|
||||||
|
{
|
||||||
|
$this->parser = h_sepBy(choice(ch("1"), ch("2"), ch("3")), ch(","));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSuccess()
|
||||||
|
{
|
||||||
|
$result1 = h_parse($this->parser, "1,2,3");
|
||||||
|
$result2 = h_parse($this->parser, "1,3,2");
|
||||||
|
$result3 = h_parse($this->parser, "1,3");
|
||||||
|
$result4 = h_parse($this->parser, "3");
|
||||||
|
$result5 = h_parse($this->parser, "");
|
||||||
|
$this->assertEquals(array("1", "2", "3"), $result1);
|
||||||
|
$this->assertEquals(array("1", "3", "2"), $result2);
|
||||||
|
$this->assertEquals(array("1", "3"), $result3);
|
||||||
|
$this->assertEquals(array("3"), $result4);
|
||||||
|
$this->assertEquals(array(), $result5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue