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
|
<!doctype html>
<title>Non-ASCII codepoints</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<meta name="author" title="Tab Atkins-Bittner">
<link rel=help href="https://drafts.csswg.org/css-syntax/#non-ascii-ident-code-point">
<script>
function validIdentChar(cp) {
// Reset to a known-good ident
document.head.style.animationName = "foo";
// Then change to a name containing the char
document.head.style.animationName = "f"+String.fromCodePoint(cp)+"oo";
// And see if it actually changed.
return document.head.style.animationName != "foo";
}
function testValid(cp) {
test(()=>{
assert_true(validIdentChar(cp));
}, `Codepoint U+${cp.toString(16)} is a valid 'non-ASCII ident codepoint'.`)
}
function testInvalid(cp) {
// Just skip if the codepoint is outside the possible range.
if(cp > 0x1ffff) return;
test(()=>{
assert_false(validIdentChar(cp));
}, `Codepoint U+${cp.toString(16)} is not a 'non-ASCII ident codepoint'.`)
}
function testValidRanges(ranges) {
// Takes an array of codepoints or codepoints ranges,
// and tests whether the start, end, and middle of
// each range is valid, and confirms that the
// start/end of the regions between them are invalid.
for(const range of ranges) {
if(typeof range == "number") {
testValid(range);
continue;
}
testValid(range[0]);
if(range[1] - range[0] > 1) {
testValid(Math.floor((range[0]+range[1])/2));
}
testValid(range[1]);
}
testInvalid(0x80);
var lastTested = 0x80;
for(const range of ranges) {
if(typeof range == "number") {
if(range-1 != lastTested) testInvalid(range-1);
testInvalid(range+1);
lastTested = range+1;
continue;
}
if(range[0]-1 != lastTested) testInvalid(range[0]-1);
testInvalid(range[1]+1);
lastTested = range[1]+1;
}
}
testValidRanges([
0xb7,
[0xc0, 0xd6],
[0xd8, 0xf6],
[0xf8, 0x37d],
[0x37f, 0x1fff],
[0x200c, 0x200d],
[0x203f, 0x2040]
[0x2070, 0x218f],
[0x2c00, 0x2fef],
[0x3001, 0xd7ff],
[0xf900, 0xfdcf],
[0xfdf0, 0xfffd],
[0x10000, 0x1ffff],
]);
</script>
|