forked from MyIntervals/PHP-CSS-Parser
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathExpressionTest.php
More file actions
63 lines (56 loc) · 1.64 KB
/
Copy pathExpressionTest.php
File metadata and controls
63 lines (56 loc) · 1.64 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
54
55
56
57
58
59
60
61
62
63
<?php
namespace Sabberworm\CSS\Tests\Value;
use PHPUnit\Framework\TestCase;
use Sabberworm\CSS\Parsing\ParserState;
use Sabberworm\CSS\Settings;
use Sabberworm\CSS\Value\Value;
use Sabberworm\CSS\Value\ValueList;
use Sabberworm\CSS\Value\Expression;
use Sabberworm\CSS\Rule\Rule;
/**
* @covers \Sabberworm\CSS\Value\Expression
*/
final class ExpressionTest extends TestCase
{
/**
* @return array<0, array{string: string}>
*/
public static function provideExpressions(): array
{
return [
[
'input' => '(vh - 10) / 2',
'expected_output' => '(vh - 10)/2',
'expression_index' => 0,
],
[
'input' => 'max(5, (vh - 10))',
'expected_output' => 'max(5,(vh - 10))',
'expression_index' => 1
],
];
}
/**
* @test
*
* @dataProvider provideExpressions
*/
public function parseExpressions(string $input, string $expected, int $expression_index): void
{
$val = Value::parseValue(
new ParserState($input, Settings::create()),
$this->getDelimiters('height')
);
self::assertInstanceOf(ValueList::class, $val);
self::assertInstanceOf(Expression::class, $val->getListComponents()[$expression_index]);
self::assertSame($expected, (string) $val);
}
private function getDelimiters(string $rule): array
{
$closure = function($rule) {
return self::listDelimiterForRule($rule);
};
$getter = $closure->bindTo(null, Rule::class);
return $getter($rule);
}
}