forked from GravityPDF/querypath
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtilTest.php
More file actions
53 lines (47 loc) · 1.41 KB
/
UtilTest.php
File metadata and controls
53 lines (47 loc) · 1.41 KB
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
52
53
<?php
namespace QueryPathTests\CSS;
use QueryPath\CSS\DOMTraverser\Util;
use QueryPathTests\TestCase;
/**
* @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([2, 0], Util::parseAnB('even'));
// odd
$this->assertEquals([2, 1], Util::parseAnB('odd'));
// 5
$this->assertEquals([0, 5], Util::parseAnB('5'));
// +5
$this->assertEquals([0, 5], Util::parseAnB('+5'));
// n
$this->assertEquals([1, 0], Util::parseAnB('n'));
// 2n
$this->assertEquals([2, 0], Util::parseAnB('2n'));
// -234n
$this->assertEquals([-234, 0], Util::parseAnB('-234n'));
// -2n+1
$this->assertEquals([-2, 1], Util::parseAnB('-2n+1'));
// -2n + 1
$this->assertEquals([-2, 1], Util::parseAnB(' -2n + 1 '));
// +2n-1
$this->assertEquals([2, -1], Util::parseAnB('2n-1'));
$this->assertEquals([2, -1], Util::parseAnB('2n - 1'));
// -n + 3
$this->assertEquals([-1, 3], Util::parseAnB('-n+3'));
$this->assertEquals([1, 3], Util::parseAnB('n+3'));
// Test invalid values
$this->assertEquals([0, 0], Util::parseAnB('obviously + invalid'));
}
}