|
5 | 5 | namespace Sabberworm\CSS\Tests\RuleSet;
|
6 | 6 |
|
7 | 7 | use PHPUnit\Framework\TestCase;
|
| 8 | +use Sabberworm\CSS\OutputFormat; |
8 | 9 | use Sabberworm\CSS\Parser;
|
9 | 10 | use Sabberworm\CSS\Rule\Rule;
|
| 11 | +use Sabberworm\CSS\Settings as ParserSettings; |
10 | 12 | use Sabberworm\CSS\Value\Size;
|
11 | 13 |
|
12 | 14 | /**
|
@@ -428,4 +430,51 @@ public function orderOfElementsMatchingOriginalOrderAfterExpandingShorthands():
|
428 | 430 | \array_map('strval', $lastDeclarationBlock->getRulesAssoc())
|
429 | 431 | );
|
430 | 432 | }
|
| 433 | + |
| 434 | + /** |
| 435 | + * @return array<string, array{0: non-empty-string, 1: non-empty-string}> |
| 436 | + */ |
| 437 | + public static function declarationBlocksWithCommentsProvider(): array |
| 438 | + { |
| 439 | + return [ |
| 440 | + 'CSS comments with one asterisk' => ['p {color: #000;/* black */}', 'p {color: #000;}'], |
| 441 | + 'CSS comments with two asterisks' => ['p {color: #000;/** black */}', 'p {color: #000;}'], |
| 442 | + ]; |
| 443 | + } |
| 444 | + |
| 445 | + /** |
| 446 | + * @test |
| 447 | + * @dataProvider declarationBlocksWithCommentsProvider |
| 448 | + */ |
| 449 | + public function canRemoveCommentsFromRulesUsingLenientParsing( |
| 450 | + string $cssWithComments, |
| 451 | + string $cssWithoutComments |
| 452 | + ): void { |
| 453 | + $parserSettings = ParserSettings::create()->withLenientParsing(true); |
| 454 | + $document = (new Parser($cssWithComments, $parserSettings))->parse(); |
| 455 | + |
| 456 | + $outputFormat = (new OutputFormat())->setRenderComments(false); |
| 457 | + $renderedDocument = $document->render($outputFormat); |
| 458 | + |
| 459 | + self::assertSame($cssWithoutComments, $renderedDocument); |
| 460 | + } |
| 461 | + |
| 462 | + /** |
| 463 | + * @test |
| 464 | + * @dataProvider declarationBlocksWithCommentsProvider |
| 465 | + */ |
| 466 | + public function canRemoveCommentsFromRulesUsingStrictParsing( |
| 467 | + string $cssWithComments, |
| 468 | + string $cssWithoutComments |
| 469 | + ): void { |
| 470 | + self::markTestSkipped('This currently crashes, and we need to fix it.'); |
| 471 | + |
| 472 | + $parserSettings = ParserSettings::create()->withLenientParsing(false); |
| 473 | + $document = (new Parser($cssWithComments, $parserSettings))->parse(); |
| 474 | + |
| 475 | + $outputFormat = (new OutputFormat())->setRenderComments(false); |
| 476 | + $renderedDocument = $document->render($outputFormat); |
| 477 | + |
| 478 | + self::assertSame($cssWithoutComments, $renderedDocument); |
| 479 | + } |
431 | 480 | }
|
0 commit comments