Skip to content

Commit 14118a2

Browse files
committed
Add class-specific tests for CSS\Value\Expression
1 parent abbcc8f commit 14118a2

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

tests/Value/ExpressionTest.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
namespace Sabberworm\CSS\Tests\Value;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Sabberworm\CSS\Parsing\ParserState;
7+
use Sabberworm\CSS\Settings;
8+
use Sabberworm\CSS\Value\Value;
9+
use Sabberworm\CSS\Value\ValueList;
10+
use Sabberworm\CSS\Value\Expression;
11+
use Sabberworm\CSS\Rule\Rule;
12+
13+
/**
14+
* @covers \Sabberworm\CSS\Value\Expression
15+
*/
16+
final class ExpressionTest extends TestCase
17+
{
18+
/**
19+
* @return array<0, array{string: string}>
20+
*/
21+
public static function provideExpressions(): array
22+
{
23+
return [
24+
[
25+
'input' => '(vh - 10) / 2',
26+
'expected_output' => '(vh - 10)/2',
27+
'expression_index' => 0,
28+
],
29+
[
30+
'input' => 'max(5, (vh - 10))',
31+
'expected_output' => 'max(5,(vh - 10))',
32+
'expression_index' => 1
33+
],
34+
];
35+
}
36+
37+
/**
38+
* @test
39+
*
40+
* @dataProvider provideExpressions
41+
*/
42+
public function parseExpressions(string $input, string $expected, int $expression_index): void
43+
{
44+
$val = Value::parseValue(
45+
new ParserState($input, Settings::create()),
46+
$this->getDelimiters('height')
47+
);
48+
49+
self::assertInstanceOf(ValueList::class, $val);
50+
self::assertInstanceOf(Expression::class, $val->getListComponents()[$expression_index]);
51+
self::assertSame($expected, (string) $val);
52+
}
53+
54+
private function getDelimiters(string $rule): array
55+
{
56+
$closure = function($rule) {
57+
return self::listDelimiterForRule($rule);
58+
};
59+
60+
$getter = $closure->bindTo(null, Rule::class);
61+
return $getter($rule);
62+
}
63+
}

0 commit comments

Comments
 (0)