diff --git a/src/bindings/php/Tests/IgnoreTest.php b/src/bindings/php/Tests/IgnoreTest.php new file mode 100644 index 0000000000000000000000000000000000000000..82ef554ba03978fc4f5bc902bca0966a7ed22f96 --- /dev/null +++ b/src/bindings/php/Tests/IgnoreTest.php @@ -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); + } +} +?> \ No newline at end of file diff --git a/src/bindings/php/Tests/OptionalTest.php b/src/bindings/php/Tests/OptionalTest.php new file mode 100644 index 0000000000000000000000000000000000000000..22b15dfe904b3cf20d0b8a640b7b2bea74554ced --- /dev/null +++ b/src/bindings/php/Tests/OptionalTest.php @@ -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); + } +} +?> \ No newline at end of file