-
Notifications
You must be signed in to change notification settings - Fork 152
Expand file tree
/
Copy pathExpressionTest.php
More file actions
69 lines (61 loc) · 1.84 KB
/
Copy pathExpressionTest.php
File metadata and controls
69 lines (61 loc) · 1.84 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
64
65
66
67
68
69
<?php
declare(strict_types=1);
namespace Sabberworm\CSS\Tests\Value;
use PHPUnit\Framework\TestCase;
use Sabberworm\CSS\Parsing\ParserState;
use Sabberworm\CSS\OutputFormat;
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 list<array{input: non-empty-string, expected_output: non-empty-string, expression_index: int}>
*/
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, $val->render(OutputFormat::createCompact()));
}
/**
* @return list<non-empty-string>
*/
private function getDelimiters(string $rule): array
{
$closure = function ($rule) {
return self::listDelimiterForRule($rule);
};
$getter = $closure->bindTo(null, Rule::class);
return $getter($rule);
}
}