|
7 | 7 | use PHPUnit\Framework\TestCase; |
8 | 8 | use Sabberworm\CSS\CSSList\Document; |
9 | 9 | use Sabberworm\CSS\Parser; |
| 10 | +use Sabberworm\CSS\Settings; |
| 11 | +use TRegx\PhpUnit\DataProviders\DataProvider; |
10 | 12 |
|
11 | 13 | /** |
12 | 14 | * @covers \Sabberworm\CSS\Parser |
@@ -36,4 +38,54 @@ public function parseWithOneRuleSetReturnsDocument(): void |
36 | 38 |
|
37 | 39 | self::assertInstanceOf(Document::class, $result); |
38 | 40 | } |
| 41 | + |
| 42 | + /** |
| 43 | + * @return array<non-empty-string, array{0: string}> |
| 44 | + */ |
| 45 | + public static function provideEmptyCss(): array |
| 46 | + { |
| 47 | + return [ |
| 48 | + 'empty string' => [''], |
| 49 | + 'space' => [' '], |
| 50 | + 'newline' => ["\n"], |
| 51 | + 'carriage return' => ["\r"], |
| 52 | + 'tab' => ["\t"], |
| 53 | + 'Windows line ending' => ["\r\n"], |
| 54 | + 'comment' => ['/* I get put in a separate property */'], |
| 55 | + ]; |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * @return array<non-empty-string, array{0: bool}> |
| 60 | + */ |
| 61 | + public static function provideLenientParsingFlag(): array |
| 62 | + { |
| 63 | + return [ |
| 64 | + 'strict parsing' => [false], |
| 65 | + 'lenient parsing' => [true], |
| 66 | + ]; |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * @return DataProvider<non-empty-string, array{0: string, 1: bool}> |
| 71 | + */ |
| 72 | + public static function provideEmptyCssAndLenientParsingFlag(): DataProvider |
| 73 | + { |
| 74 | + return DataProvider::cross(static::provideEmptyCss(), static::provideLenientParsingFlag()); |
| 75 | + } |
| 76 | + |
| 77 | + /** |
| 78 | + * @test |
| 79 | + * |
| 80 | + * @dataProvider provideEmptyCssAndLenientParsingFlag |
| 81 | + */ |
| 82 | + public function parsesEmptyCss(string $css, bool $parseLeniently): void |
| 83 | + { |
| 84 | + $parser = new Parser($css, Settings::create()->withLenientParsing($parseLeniently)); |
| 85 | + |
| 86 | + $result = $parser->parse(); |
| 87 | + |
| 88 | + // Note: Comments for the document are accessed separately via `getComments()`. |
| 89 | + self::assertSame([], $result->getContents()); |
| 90 | + } |
39 | 91 | } |
0 commit comments