-
Notifications
You must be signed in to change notification settings - Fork 152
Expand file tree
/
Copy pathParserTest.php
More file actions
91 lines (76 loc) · 2.21 KB
/
Copy pathParserTest.php
File metadata and controls
91 lines (76 loc) · 2.21 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
declare(strict_types=1);
namespace Sabberworm\CSS\Tests\Functional;
use PHPUnit\Framework\TestCase;
use Sabberworm\CSS\CSSList\Document;
use Sabberworm\CSS\Parser;
use Sabberworm\CSS\Settings;
use TRegx\PhpUnit\DataProviders\DataProvider;
/**
* @covers \Sabberworm\CSS\Parser
*/
final class ParserTest extends TestCase
{
/**
* @test
*/
public function parseWithEmptyStringReturnsDocument(): void
{
$parser = new Parser('');
$result = $parser->parse();
self::assertInstanceOf(Document::class, $result);
}
/**
* @test
*/
public function parseWithOneRuleSetReturnsDocument(): void
{
$parser = new Parser('.thing { }');
$result = $parser->parse();
self::assertInstanceOf(Document::class, $result);
}
/**
* @return array<non-empty-string, array{0: string}>
*/
public static function provideEmptyCss(): array
{
return [
'empty string' => [''],
'space' => [' '],
'newline' => ["\n"],
'carriage return' => ["\r"],
'tab' => ["\t"],
'Windows line ending' => ["\r\n"],
'comment' => ['/* I get put in a separate property */'],
];
}
/**
* @return array<non-empty-string, array{0: bool}>
*/
public static function provideLenientParsingFlag(): array
{
return [
'strict parsing' => [false],
'lenient parsing' => [true],
];
}
/**
* @return DataProvider<non-empty-string, array{0: string, 1: bool}>
*/
public static function provideEmptyCssAndLenientParsingFlag(): DataProvider
{
return DataProvider::cross(static::provideEmptyCss(), static::provideLenientParsingFlag());
}
/**
* @test
*
* @dataProvider provideEmptyCssAndLenientParsingFlag
*/
public function parsesEmptyCss(string $css, bool $parseLeniently): void
{
$parser = new Parser($css, Settings::create()->withLenientParsing($parseLeniently));
$result = $parser->parse();
// Note: Comments for the document are accessed separately via `getComments()`.
self::assertSame([], $result->getContents());
}
}