From 60d096bc16c389cc6f0965bac6a5cd812345087c Mon Sep 17 00:00:00 2001 From: "Meredith L. Patterson" <mlp@thesmartpolitenerd.com> Date: Sun, 1 Dec 2013 22:09:45 -0800 Subject: [PATCH] more tests written, need to fix that retval problem stat --- src/bindings/php/Tests/AndTest.php | 35 +++++++++++++++++++++++++ src/bindings/php/Tests/EpsilonPTest.php | 35 +++++++++++++++++++++++++ src/bindings/php/Tests/LeftrecTest.php | 24 +++++++++++++++++ src/bindings/php/Tests/NotTest.php | 35 +++++++++++++++++++++++++ 4 files changed, 129 insertions(+) create mode 100644 src/bindings/php/Tests/AndTest.php create mode 100644 src/bindings/php/Tests/EpsilonPTest.php create mode 100644 src/bindings/php/Tests/LeftrecTest.php create mode 100644 src/bindings/php/Tests/NotTest.php diff --git a/src/bindings/php/Tests/AndTest.php b/src/bindings/php/Tests/AndTest.php new file mode 100644 index 00000000..03f92582 --- /dev/null +++ b/src/bindings/php/Tests/AndTest.php @@ -0,0 +1,35 @@ +<?php +include_once 'hammer.php'; + +class AndTest extends PHPUnit_Framework_TestCase +{ + protected $parser1; + protected $parser2; + protected $parser3; + + protected function setUp() + { + $this->parser1 = sequence(h_and(ch("0")), ch("0")); + $this->parser2 = sequence(h_and(ch("0")), ch("1")); + $this->parser3 = sequence(ch("1"), h_and(ch("2"))); + } + + public function testSuccess1() + { + $result = h_parse($this->parser1, "0"); + $this->assertEquals(array("0"), $result); + } + + public function testFailure2() + { + $result = h_parse($this->parser2, "0"); + $this->assertEquals(NULL, $result); + } + + public function testSuccess3() + { + $result = h_parse($this->parser3, "12"); + $this->assertEquals(array("1"), $result); + } +} +?> \ No newline at end of file diff --git a/src/bindings/php/Tests/EpsilonPTest.php b/src/bindings/php/Tests/EpsilonPTest.php new file mode 100644 index 00000000..432afef4 --- /dev/null +++ b/src/bindings/php/Tests/EpsilonPTest.php @@ -0,0 +1,35 @@ +<?php +include_once 'hammer.php'; + +class EpsilonPTest extends PHPUnit_Framework_TestCase +{ + protected $parser1; + protected $parser2; + protected $parser3; + + protected function setUp() + { + $this->parser1 = sequence(ch("a"), h_epsilon_p(), ch("b")); + $this->parser2 = sequence(h_epsilon_p(), ch("a")); + $this->parser3 = sequence(ch("a"), h_epsilon_p()); + } + + public function testSuccess1() + { + $result = h_parse($this->parser1, "ab"); + $this->assertEquals(array("a", "b"), $result); + } + + public function testSuccess2() + { + $result = h_parse($this->parser2, "a"); + $this->assertEquals(array("a"), $result); + } + + public function testSuccess3() + { + $result = h_parse($this->parser3, "ab"); + $this->assertEquals(array("a"), $result); + } +} +?> \ No newline at end of file diff --git a/src/bindings/php/Tests/LeftrecTest.php b/src/bindings/php/Tests/LeftrecTest.php new file mode 100644 index 00000000..1a2878e1 --- /dev/null +++ b/src/bindings/php/Tests/LeftrecTest.php @@ -0,0 +1,24 @@ +<?php +include_once 'hammer.php'; + +class LeftrecTest extends PHPUnit_Framework_TestCase +{ + protected $parser; + + protected function setUp() + { + $this->parser = h_indirect(); + h_bind_indirect($this->parser, choice(sequence($this->parser, ch("a")), ch("a"))); + } + + public function testSuccess() + { + $result1 = h_parse($this->parser, "a"); + $result2 = h_parse($this->parser, "aa"); + $result3 = h_parse($this->parser, "aaa"); + $this->assertEquals("a", $result1); + $this->assertEquals(array("a", "a"), $result); + $this->assertEquals(array(array("a", "a"), "a"), $result); + } +} +?> \ No newline at end of file diff --git a/src/bindings/php/Tests/NotTest.php b/src/bindings/php/Tests/NotTest.php new file mode 100644 index 00000000..a2c76aa7 --- /dev/null +++ b/src/bindings/php/Tests/NotTest.php @@ -0,0 +1,35 @@ +<?php +include_once 'hammer.php'; + +class NotTest extends PHPUnit_Framework_TestCase +{ + protected $parser1; + protected $parser2; + + protected function setUp() + { + $this->parser1 = sequence(ch("a"), choice(ch("+"), h_token("++")), ch("b")); + $this->parser2 = sequence(ch("a"), choice(sequence(ch("+"), h_not(ch("+"))), h_token("++")), ch("b")); + } + + public function testSuccess1() + { + $result = h_parse($this->parser1, "a+b"); + $this->assertEquals(array("a", "+", "b"), $result); + } + + public function testFailure1() + { + $result = h_parse($this->parser1, "a++b"); + $this->assertEquals(NULL, $result); + } + + public function testSuccess2() + { + $result1 = h_parse($this->parser2, "a+b"); + $result2 = h_parse($this->parser2, "a++b"); + $this->assertEquals(array("a", array("+"), "b"), $result1); + $this->assertEquals(array("a", "++", "b"), $result2); + } +} +?> \ No newline at end of file -- GitLab