Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

<!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">
<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>