Skip to content

Commit 1644d6a

Browse files
committed
Add a test for line numbers
1 parent e282cb3 commit 1644d6a

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

tests/Sabberworm/CSS/ParserTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
namespace Sabberworm\CSS;
44

5+
use Sabberworm\CSS\CSSList\KeyFrame;
56
use Sabberworm\CSS\Value\Size;
67
use Sabberworm\CSS\Property\Selector;
78
use Sabberworm\CSS\RuleSet\DeclarationBlock;
89
use Sabberworm\CSS\Property\AtRule;
10+
use Sabberworm\CSS\Value\URL;
911

1012
class ParserTest extends \PHPUnit_Framework_TestCase {
1113

@@ -435,4 +437,42 @@ function parsedStructureForFile($sFileName, $oSettings = null) {
435437
return $oParser->parse();
436438
}
437439

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+
438478
}

tests/files/line-numbers.css

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
@charset "utf-8"; /* line 3 */
2+
3+
@namespace "http://toto.example.org"; /* line 1 */
4+
5+
@font-face { /* line 5 */
6+
font-family: "CrassRoots";
7+
src: url("http://example.com/media/cr.ttf")
8+
}
9+
10+
11+
#header { /* line 11 */
12+
margin: 10px 2em 1cm 2%;
13+
font-family: Verdana, Helvetica, "Gill Sans", sans-serif;
14+
color: red !important;
15+
}
16+
17+
@keyframes mymove { /* line 17 */
18+
from { top: 0px; } /* line 18 */
19+
20+
to { top: 200px; } /* line 20 */
21+
}
22+
23+
@IMPORT uRL(test.css); /* line 23 */
24+
25+
body {
26+
background: #FFFFFF url("http://somesite.com/images/someimage.gif") repeat top center; /* line 25 */
27+
color: rgb(233, 100, 450);
28+
}

0 commit comments

Comments
 (0)