|
2 | 2 |
|
3 | 3 | namespace Sabberworm\CSS;
|
4 | 4 |
|
| 5 | +use Sabberworm\CSS\CSSList\KeyFrame; |
5 | 6 | use Sabberworm\CSS\Value\Size;
|
6 | 7 | use Sabberworm\CSS\Property\Selector;
|
7 | 8 | use Sabberworm\CSS\RuleSet\DeclarationBlock;
|
8 | 9 | use Sabberworm\CSS\Property\AtRule;
|
| 10 | +use Sabberworm\CSS\Value\URL; |
9 | 11 |
|
10 | 12 | class ParserTest extends \PHPUnit_Framework_TestCase {
|
11 | 13 |
|
@@ -435,4 +437,42 @@ function parsedStructureForFile($sFileName, $oSettings = null) {
|
435 | 437 | return $oParser->parse();
|
436 | 438 | }
|
437 | 439 |
|
| 440 | + /** |
| 441 | + * @depends testFiles |
| 442 | + */ |
| 443 | + function testLineNumbersParsing() { |
| 444 | + $oDoc = $this->parsedStructureForFile('line-numbers'); |
| 445 | + // array key is the expected line number |
| 446 | + $aExpected = [ |
| 447 | + 1 => ['Sabberworm\CSS\Property\Charset'], |
| 448 | + 3 => ['Sabberworm\CSS\Property\CSSNamespace'], |
| 449 | + 5 => ['Sabberworm\CSS\RuleSet\AtRuleSet'], |
| 450 | + 11 => ['Sabberworm\CSS\RuleSet\DeclarationBlock'], |
| 451 | + // Line Numbers of the inner declaration blocks |
| 452 | + 17 => ['Sabberworm\CSS\CSSList\KeyFrame', 18, 20], |
| 453 | + 23 => ['Sabberworm\CSS\Property\Import'], |
| 454 | + 25 => ['Sabberworm\CSS\RuleSet\DeclarationBlock'] |
| 455 | + ]; |
| 456 | + |
| 457 | + $aActual = []; |
| 458 | + foreach ($oDoc->getContents() as $oContent) { |
| 459 | + $aActual[$oContent->getLineNo()] = [get_class($oContent)]; |
| 460 | + if ($oContent instanceof KeyFrame) { |
| 461 | + foreach ($oContent->getContents() as $block) { |
| 462 | + $aActual[$oContent->getLineNo()][] = $block->getLineNo(); |
| 463 | + } |
| 464 | + } |
| 465 | + } |
| 466 | + |
| 467 | + $aUrlExpected = [7, 26]; // expected line numbers |
| 468 | + $aUrlActual = []; |
| 469 | + foreach ($oDoc->getAllValues() as $oValue) { |
| 470 | + if ($oValue instanceof URL) { |
| 471 | + $aUrlActual[] = $oValue->getLineNo(); |
| 472 | + } |
| 473 | + } |
| 474 | + $this->assertEquals($aUrlExpected, $aUrlActual); |
| 475 | + $this->assertEquals($aExpected, $aActual); |
| 476 | + } |
| 477 | + |
438 | 478 | }
|
0 commit comments