1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
<!doctype html>
<title>Urange Parsing</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
@font-face {
font-family: foo;
src: url(http://example.com);
}
.error {}
</style>
<meta name=author title="Tab Atkins-Bittner">
<link rel=help href="https://drafts.csswg.org/css-syntax/#urange-syntax">
<script>
function testUrange(input, expected) {
test(()=>{
const rule = document.styleSheets[0].cssRules[0];
rule.style.setProperty("unicode-range", "U+1357");
rule.style.setProperty("unicode-range", input);
assert_equals(rule.style.getPropertyValue("unicode-range").toUpperCase(), expected.toUpperCase());
}, `"${input}" => "${expected}"`)
}
function testInvalidUrange(input) {
test(()=>{
const rule = document.styleSheets[0].cssRules[0];
rule.style.setProperty("unicode-range", "U+1357");
rule.style.setProperty("unicode-range", input);
assert_equals(rule.style.getPropertyValue("unicode-range").toUpperCase(), "U+1357");
}, `"${input}" is invalid`);
}
/* First exercise all the clauses individually */
//<urange> =
// u '+' <ident-token> '?'* |
/* comments can go between tokens */
testUrange("u/**/+/**/a/**/?", "U+A0-AF");
/* capitalization doesn't matter */
testUrange("u+abc", "U+ABC");
testUrange("U+abc", "U+ABC");
testUrange("u+ABC", "U+ABC");
testUrange("U+ABC", "U+ABC");
testUrange("u+AbC", "U+ABC");
/* only hex */
testInvalidUrange("u+efg");
/* no spacing */
testInvalidUrange("u+ abc");
testInvalidUrange("u +abc");
testInvalidUrange("u + abc");
testInvalidUrange("U + a b c");
/* 1-6 characters */
testUrange("u+a", "U+A");
testUrange("u+aa", "U+AA");
testUrange("u+aaa", "U+AAA");
testUrange("u+aaaa", "U+AAAA");
testUrange("u+aaaaa", "U+AAAAA");
testInvalidUrange("u+aaaaaaa");
/* Or ? at the end, still up to 6 */
testUrange("u+a?", "U+A0-AF");
testUrange("u+a??", "U+A00-AFF");
testUrange("u+a???", "U+A000-AFFF");
testUrange("u+a????", "U+A0000-AFFFF");
testInvalidUrange("u+aaaaaa?");
testInvalidUrange("u+aaaaa??");
testInvalidUrange("u+aaaa???");
testInvalidUrange("u+aaa????");
testInvalidUrange("u+aa?????");
testInvalidUrange("u+a??????");
/* no characters after ? */
testInvalidUrange("u+a?a");
// Too large!
testInvalidUrange("u+aaaaaa");
testInvalidUrange("u+a?????");
// u <dimension-token> '?'* |
testUrange("u/**/+0a/**/?", "U+A0-AF");
testUrange("u+0a", "U+A");
testUrange("U+0a0", "U+A0");
testUrange("u+0aaaaa", "U+AAAAA");
testInvalidUrange("u+0aaaaaa");
testUrange("u+0a0000", "U+A0000");
testInvalidUrange("u+0a00000");
testInvalidUrange("u+0aaaaa0");
testUrange("u+00000a", "U+A");
testInvalidUrange("u+00000aa");
testInvalidUrange("u+00000a0")
testInvalidUrange("u+000000a");
testUrange("u+0a????", "U+A0000-AFFFF");
testInvalidUrange("u+0a?????");
testInvalidUrange("u+00a????");
// Too large!
testInvalidUrange("u+22222a");
// Scinot!
testUrange("u+1e9a", "U+1E9A");
// u <number-token> '?'* |
testUrange("u/**/+0/**/?", "U+0-F");
testInvalidUrange("u/**/0");
testUrange("u+0", "U+0");
testUrange("u+00", "U+0");
testUrange("u+000", "U+0");
testUrange("u+0000", "U+0");
testUrange("u+00000", "U+0");
testUrange("u+000000", "U+0");
testInvalidUrange("u+0000000");
testUrange("u+00000?", "U+0-F");
testUrange("u+0?????", "U+0-FFFFF");
testInvalidUrange("u+0?a");
testInvalidUrange("u+000000?");
testInvalidUrange("u+00000??");
testInvalidUrange("u+0??????");
// Scinot!
testUrange("u+1e3", "U+1E3");
testUrange("u+1e-20", "U+1E-20");
// Too large!
testInvalidUrange("u+222222");
testInvalidUrange("u+2?????");
// u <number-token> <dimension-token> |
testUrange("u/**/+0/**/-0a", "U+0-A");
testUrange("u+0-0a", "U+0-A");
testUrange("u+000000-0aaaaa", "U+0-AAAAA");
testInvalidUrange("u+0000000-0a");
testInvalidUrange("u+0-0aaaaaa");
testInvalidUrange("u+0-000000a");
testInvalidUrange("u+0+0a");
testInvalidUrange("u+0?-0a");
testInvalidUrange("u+0-0a?");
// Too large!
testInvalidUrange("u+222222-22222a");
// u <number-token> <number-token> |
testUrange("u/**/+0/**/-1", "U+0-1");
testUrange("u+0-1", "U+0-1");
testInvalidUrange("u-0-1");
testInvalidUrange("u-0+1");
testInvalidUrange("u+0+1");
testUrange("u+000000-000001", "U+0-1");
testInvalidUrange("u+0000000-1");
testInvalidUrange("u+0-0000001");
// Too large!
testInvalidUrange("u+0-222222");
// u '+' '?'+
testUrange("u/**/+/**/?", "U+0-F");
testUrange("u+?", "U+0-F");
testUrange("u+?????", "u+0-FFFFF");
testInvalidUrange("u+???????");
testInvalidUrange("u+?a");
// U+FFFFFF is too large!
testInvalidUrange("u+??????");
/* Finally, verify that u+a is properly parsed
as IDENT(u) DELIM(+) IDENT(a) in other contexts */
test(()=>{
const rule = document.styleSheets[0].cssRules[1];
// Establish that it works with whitespace...
rule.selectorText = "u + a";
assert_equals(rule.selectorText, "u + a");
// And then again without...
rule.selectorText = ".error";
rule.selectorText = "u+a";
assert_equals(rule.selectorText, "u + a");
}, "u+a is a valid selector");
</script>
|