File tree Expand file tree Collapse file tree 3 files changed +85
-4
lines changed
src/CssLint/Tokenizer/Parser
tests/TestSuite/Tokenizer Expand file tree Collapse file tree 3 files changed +85
-4
lines changed Original file line number Diff line number Diff line change 22/nbproject /
33/vendor
44/tools /vendor
5+ /tools /* .phar
56composer.lock
67.cache
78tests /.phpunit.result.cache
Original file line number Diff line number Diff line change @@ -106,12 +106,14 @@ private function getAtRuleName(TokenizerContext $tokenizerContext): string
106106 {
107107 $ content = trim ($ tokenizerContext ->getCurrentContent ());
108108 $ parts = explode (' ' , trim ($ content ), 2 );
109- return trim (
109+ $ name = trim (
110110 $ this ->removeStartingString (
111111 $ parts [0 ],
112112 self ::$ AT_RULE_START
113113 )
114114 );
115+
116+ return $ this ->removeAtRuleEndingString ($ name );
115117 }
116118
117119 private function getAtRuleValue (TokenizerContext $ tokenizerContext ): ?string
@@ -123,12 +125,15 @@ private function getAtRuleValue(TokenizerContext $tokenizerContext): ?string
123125 return null ;
124126 }
125127
126- $ atRuleValue = $ parts [1 ];
128+ return $ this ->removeAtRuleEndingString ($ parts [1 ]);
129+ }
127130
131+ private function removeAtRuleEndingString (string $ content ): string
132+ {
128133 foreach ([self ::$ AT_RULE_END , BlockParser::$ BLOCK_START ] as $ endChar ) {
129- $ atRuleValue = self ::removeEndingString ($ atRuleValue , $ endChar );
134+ $ content = self ::removeEndingString ($ content , $ endChar );
130135 }
131136
132- return trim ($ atRuleValue );
137+ return trim ($ content );
133138 }
134139}
Original file line number Diff line number Diff line change @@ -257,6 +257,81 @@ public function testTokenizeWithMultilineComments()
257257 $ this ->assertTokensOrErrorsEquals ($ expectedTokensOrErrors , $ tokensOrErrors );
258258 }
259259
260+ public function testTokenizeWithAtRuleProperties ()
261+ {
262+ // Arrange
263+ $ stream = $ this ->getStream ("@font-face{font-family:'Open Sans';src: url('open-sans.woff2');} " );
264+
265+ // Act
266+ $ tokensOrErrors = iterator_to_array ($ this ->tokenizer ->tokenize ($ stream ), false );
267+
268+ // Assert
269+ $ expectedTokensOrErrors = [
270+ [
271+ 'type ' => 'at-rule ' ,
272+ 'value ' => [
273+ 'name ' => 'font-face ' ,
274+ 'value ' => null ,
275+ 'isBlock ' => true ,
276+ ],
277+ 'start ' => [
278+ 'line ' => 1 ,
279+ 'column ' => 1 ,
280+ ],
281+ 'end ' => [
282+ 'line ' => 1 ,
283+ 'column ' => 10 ,
284+ ],
285+ ],
286+ [
287+ 'type ' => 'block ' ,
288+ 'value ' => [
289+ [
290+ 'type ' => 'property ' ,
291+ 'value ' => [
292+ 'name ' => 'font-family ' ,
293+ 'value ' => "'Open Sans' " ,
294+
295+ ],
296+ 'start ' => [
297+ 'line ' => 1 ,
298+ 'column ' => 11 ,
299+ ],
300+ 'end ' => [
301+ 'line ' => 1 ,
302+ 'column ' => 34 ,
303+ ],
304+ ],
305+ [
306+ 'type ' => 'property ' ,
307+ 'value ' => [
308+ 'name ' => 'src ' ,
309+ 'value ' => "url('open-sans.woff2') " ,
310+ ],
311+ 'start ' => [
312+ 'line ' => 1 ,
313+ 'column ' => 35 ,
314+ ],
315+ 'end ' => [
316+ 'line ' => 1 ,
317+ 'column ' => 62 ,
318+ ],
319+ ],
320+ ],
321+ 'start ' => [
322+ 'line ' => 1 ,
323+ 'column ' => 10 ,
324+ ],
325+ 'end ' => [
326+ 'line ' => 1 ,
327+ 'column ' => 64 ,
328+ ],
329+ ],
330+ ];
331+
332+ $ this ->assertTokensOrErrorsEquals ($ expectedTokensOrErrors , $ tokensOrErrors );
333+ }
334+
260335 public function testTokenizeWithAtRuleInBlock ()
261336 {
262337 // Arrange
You can’t perform that action at this time.
0 commit comments