Skip to content

Commit 7bc94f0

Browse files
committed
added unicode escape tests
1 parent 0f8c0bb commit 7bc94f0

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

tests/CSSParserTests.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,49 @@ function testColorParsing() {
6161
}
6262
}
6363

64+
function testUnicodeParsing() {
65+
$oDoc = $this->parsedStructureForFile('unicode');
66+
foreach($oDoc->getAllRuleSets() as $oRuleSet) {
67+
if(!$oRuleSet instanceof CSSSelector) {
68+
continue;
69+
}
70+
$aSelector = $oRuleSet->getSelector();
71+
if(substr($aSelector[0], 0, strlen('.test-')) !== '.test-') {
72+
continue;
73+
}
74+
$aContentRules = $oRuleSet->getRules('content');
75+
$aContents = $aContentRules['content']->getValues();
76+
$sCssString = $aContents[0][0]->__toString();
77+
if($aSelector[0] === '.test-1') {
78+
$this->assertSame('" "', $sCssString);
79+
}
80+
if($aSelector[0] === '.test-2') {
81+
$this->assertSame('"é"', $sCssString);
82+
}
83+
if($aSelector[0] === '.test-3') {
84+
$this->assertSame('" "', $sCssString);
85+
}
86+
if($aSelector[0] === '.test-4') {
87+
$this->assertSame('"𝄞"', $sCssString);
88+
}
89+
if($aSelector[0] === '.test-5') {
90+
$this->assertSame('"水"', $sCssString);
91+
}
92+
if($aSelector[0] === '.test-6') {
93+
$this->assertSame('"¥"', $sCssString);
94+
}
95+
if($aSelector[0] === '.test-7') {
96+
$this->assertSame('"\A"', $sCssString);
97+
}
98+
if($aSelector[0] === '.test-8') {
99+
$this->assertSame('"\"\""', $sCssString);
100+
}
101+
if($aSelector[0] === '.test-9') {
102+
$this->assertSame('"\"\\\'"', $sCssString);
103+
}
104+
}
105+
}
106+
64107
function parsedStructureForFile($sFileName) {
65108
$sFile = dirname(__FILE__).DIRECTORY_SEPARATOR.'files'.DIRECTORY_SEPARATOR."$sFileName.css";
66109
$oParser = new CSSParser(file_get_contents($sFile));

tests/files/unicode.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.test-1 { content: "\20"; }
2+
.test-2 { content: "\E9"; }
3+
.test-3 { content: "\0020"; }
4+
.test-5 { content: "\6C34" }
5+
.test-6 { content: "\00A5" }
6+
.test-7 { content: '\a' }
7+
.test-8 { content: "\"\22" }
8+
.test-9 { content: "\"\27" }
9+
10+
.test-4 { content: "\1D11E" } /* Beyond the Basic Multilingual Plane */

0 commit comments

Comments
 (0)