|
7 | 7 | use PHPUnit\Framework\TestCase; |
8 | 8 | use Sabberworm\CSS\Comment\Commentable; |
9 | 9 | use Sabberworm\CSS\CSSElement; |
| 10 | +use Sabberworm\CSS\CSSList\CSSList; |
10 | 11 | use Sabberworm\CSS\CSSList\CSSListItem; |
| 12 | +use Sabberworm\CSS\CSSList\Document; |
| 13 | +use Sabberworm\CSS\OutputFormat; |
| 14 | +use Sabberworm\CSS\Parsing\ParserState; |
11 | 15 | use Sabberworm\CSS\Property\Selector; |
12 | 16 | use Sabberworm\CSS\Renderable; |
13 | 17 | use Sabberworm\CSS\RuleSet\DeclarationBlock; |
| 18 | +use Sabberworm\CSS\Settings; |
14 | 19 | use Sabberworm\CSS\Tests\Unit\CSSList\Fixtures\ConcreteCSSList; |
15 | 20 |
|
16 | 21 | /** |
@@ -342,4 +347,37 @@ public function removeDeclarationBlockBySelectorRemovesMultipleBlocksWithStringS |
342 | 347 |
|
343 | 348 | self::assertSame([], $subject->getContents()); |
344 | 349 | } |
| 350 | + |
| 351 | + /** |
| 352 | + * The content provided must (currently) be in the same format as the expected rendering. |
| 353 | + * |
| 354 | + * @return array<non-empty-string, array{0: non-empty-string}> |
| 355 | + */ |
| 356 | + public function provideValidContentForParsing(): array |
| 357 | + { |
| 358 | + return [ |
| 359 | + 'at-import rule' => ['@import url("foo.css");'], |
| 360 | + 'rule with declaration block' => ['a {color: green;}'], |
| 361 | + ]; |
| 362 | + } |
| 363 | + |
| 364 | + /** |
| 365 | + * @test |
| 366 | + * |
| 367 | + * @param non-empty-string $followingContent |
| 368 | + * |
| 369 | + * @dataProvider provideValidContentForParsing |
| 370 | + */ |
| 371 | + public function parseListAtRootLevelSkipsErroneousClosingBraceAndParsesFollowingContent( |
| 372 | + string $followingContent |
| 373 | + ): void { |
| 374 | + $parserState = new ParserState('}' . $followingContent, Settings::create()); |
| 375 | + // The subject needs to be a `Document`, as that is currently the test for 'root level'. |
| 376 | + // Otherwise `}` will be treated as 'end of list'. |
| 377 | + $subject = new Document(); |
| 378 | + |
| 379 | + CSSList::parseList($parserState, $subject); |
| 380 | + |
| 381 | + self::assertSame($followingContent, $subject->render(new OutputFormat())); |
| 382 | + } |
345 | 383 | } |
0 commit comments