summaryrefslogtreecommitdiff
path: root/lib/querypath/test/Tests/QueryPath/CSS/UtilTest.php
blob: bdb8533a0bd1484027fc8f7cd1d721a753241247 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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'));
  }
}