|
3 | 3 | namespace Sabberworm\CSS\Tests\RuleSet;
|
4 | 4 |
|
5 | 5 | use PHPUnit\Framework\TestCase;
|
| 6 | +use Sabberworm\CSS\OutputFormat; |
6 | 7 | use Sabberworm\CSS\Parser;
|
7 | 8 | use Sabberworm\CSS\Rule\Rule;
|
| 9 | +use Sabberworm\CSS\Settings as ParserSettings; |
8 | 10 | use Sabberworm\CSS\Value\Size;
|
9 | 11 |
|
10 | 12 | /**
|
@@ -450,4 +452,51 @@ public function orderOfElementsMatchingOriginalOrderAfterExpandingShorthands()
|
450 | 452 | array_map('strval', $oDeclaration->getRulesAssoc())
|
451 | 453 | );
|
452 | 454 | }
|
| 455 | + |
| 456 | + /** |
| 457 | + * @return array<string, array{0: non-empty-string, 1: non-empty-string}> |
| 458 | + */ |
| 459 | + public static function declarationBlocksWithCommentsProvider(): array |
| 460 | + { |
| 461 | + return [ |
| 462 | + 'CSS comments with one asterisk' => ['p {color: #000;/* black */}', 'p {color: #000;}'], |
| 463 | + 'CSS comments with two asterisks' => ['p {color: #000;/** black */}', 'p {color: #000;}'], |
| 464 | + ]; |
| 465 | + } |
| 466 | + |
| 467 | + /** |
| 468 | + * @test |
| 469 | + * @dataProvider declarationBlocksWithCommentsProvider |
| 470 | + */ |
| 471 | + public function canRemoveCommentsFromRulesUsingLenientParsing( |
| 472 | + string $cssWithComments, |
| 473 | + string $cssWithoutComments |
| 474 | + ): void { |
| 475 | + $parserSettings = ParserSettings::create()->withLenientParsing(true); |
| 476 | + $document = (new Parser($cssWithComments, $parserSettings))->parse(); |
| 477 | + |
| 478 | + $outputFormat = (new OutputFormat())->setRenderComments(false); |
| 479 | + $renderedDocument = $document->render($outputFormat); |
| 480 | + |
| 481 | + self::assertSame($cssWithoutComments, $renderedDocument); |
| 482 | + } |
| 483 | + |
| 484 | + /** |
| 485 | + * @test |
| 486 | + * @dataProvider declarationBlocksWithCommentsProvider |
| 487 | + */ |
| 488 | + public function canRemoveCommentsFromRulesUsingStrictParsing( |
| 489 | + string $cssWithComments, |
| 490 | + string $cssWithoutComments |
| 491 | + ): void { |
| 492 | + self::markTestSkipped('This currently crashes, and we need to fix it.'); |
| 493 | + |
| 494 | + $parserSettings = ParserSettings::create()->withLenientParsing(false); |
| 495 | + $document = (new Parser($cssWithComments, $parserSettings))->parse(); |
| 496 | + |
| 497 | + $outputFormat = (new OutputFormat())->setRenderComments(false); |
| 498 | + $renderedDocument = $document->render($outputFormat); |
| 499 | + |
| 500 | + self::assertSame($cssWithoutComments, $renderedDocument); |
| 501 | + } |
453 | 502 | }
|
0 commit comments