summaryrefslogtreecommitdiff
path: root/lib/querypath/test/Tests/QueryPath/CSS/UtilTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/querypath/test/Tests/QueryPath/CSS/UtilTest.php')
-rw-r--r--lib/querypath/test/Tests/QueryPath/CSS/UtilTest.php51
1 files changed, 51 insertions, 0 deletions
diff --git a/lib/querypath/test/Tests/QueryPath/CSS/UtilTest.php b/lib/querypath/test/Tests/QueryPath/CSS/UtilTest.php
new file mode 100644
index 0000000..bdb8533
--- /dev/null
+++ b/lib/querypath/test/Tests/QueryPath/CSS/UtilTest.php
@@ -0,0 +1,51 @@
+<?php
+/** @file
+ * CSS Event handling tests
+ */
+namespace QueryPath\Tests;
+
+require_once __DIR__ . '/../TestCase.php';
+
+use \QueryPath\CSS\DOMTraverser\Util;
+
+/**
+ * @ingroup querypath_tests
+ * @group CSS
+ */
+class UtilTest extends TestCase {
+ public function testRemoveQuotes() {
+ $this->assertEquals('foo', Util::removeQuotes('"foo"'));
+ $this->assertEquals('foo', Util::removeQuotes("'foo'"));
+ $this->assertEquals('"foo\'', Util::removeQuotes("\"foo'"));
+ $this->assertEquals('f"o"o', Util::removeQuotes('f"o"o'));
+
+ }
+ public function testParseAnB() {
+ // even
+ $this->assertEquals(array(2, 0), Util::parseAnB('even'));
+ // odd
+ $this->assertEquals(array(2, 1), Util::parseAnB('odd'));
+ // 5
+ $this->assertEquals(array(0, 5), Util::parseAnB('5'));
+ // +5
+ $this->assertEquals(array(0, 5), Util::parseAnB('+5'));
+ // n
+ $this->assertEquals(array(1, 0), Util::parseAnB('n'));
+ // 2n
+ $this->assertEquals(array(2, 0), Util::parseAnB('2n'));
+ // -234n
+ $this->assertEquals(array(-234, 0), Util::parseAnB('-234n'));
+ // -2n+1
+ $this->assertEquals(array(-2, 1), Util::parseAnB('-2n+1'));
+ // -2n + 1
+ $this->assertEquals(array(-2, 1), Util::parseAnB(' -2n + 1 '));
+ // +2n-1
+ $this->assertEquals(array(2, -1), Util::parseAnB('2n-1'));
+ $this->assertEquals(array(2, -1), Util::parseAnB('2n - 1'));
+ // -n + 3
+ $this->assertEquals(array(-1, 3), Util::parseAnB('-n+3'));
+
+ // Test invalid values
+ $this->assertEquals(array(0, 0), Util::parseAnB('obviously + invalid'));
+ }
+}