sepby also plagued by sequence/choice return issues

This commit is contained in:
Meredith L. Patterson 2013-12-01 21:51:57 -08:00
parent a234bdfab3
commit 5c5a10b5c1
2 changed files with 58 additions and 0 deletions

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

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