From a234bdfab3162f22401e73fd4fef26b41747d70a Mon Sep 17 00:00:00 2001 From: "Meredith L. Patterson" <mlp@thesmartpolitenerd.com> Date: Sun, 1 Dec 2013 21:44:45 -0800 Subject: [PATCH] still more tests failing because sequence/choice don't return right --- src/bindings/php/Tests/IgnoreTest.php | 25 +++++++++++++++++++ src/bindings/php/Tests/OptionalTest.php | 33 +++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 src/bindings/php/Tests/IgnoreTest.php create mode 100644 src/bindings/php/Tests/OptionalTest.php diff --git a/src/bindings/php/Tests/IgnoreTest.php b/src/bindings/php/Tests/IgnoreTest.php new file mode 100644 index 00000000..82ef554b --- /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 00000000..22b15dfe --- /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 -- GitLab