diff --git a/src/bindings/php/Tests/SepBy1Test.php b/src/bindings/php/Tests/SepBy1Test.php new file mode 100644 index 0000000000000000000000000000000000000000..a5a36cc3d204a3ba1c5111a8072e92a0e6f07196 --- /dev/null +++ b/src/bindings/php/Tests/SepBy1Test.php @@ -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); + } +} +?> \ No newline at end of file diff --git a/src/bindings/php/Tests/SepByTest.php b/src/bindings/php/Tests/SepByTest.php new file mode 100644 index 0000000000000000000000000000000000000000..fdf4ed4901f004326046b81eab636dbaa524c2d0 --- /dev/null +++ b/src/bindings/php/Tests/SepByTest.php @@ -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); + } +} +?> \ No newline at end of file