Debian Codegraph @

rhino/testsrc/doctests/controlchars.doctest

raw
1 // This Source Code Form is subject to the terms of the Mozilla Public
2 // License, v. 2.0. If a copy of the MPL was not distributed with this
3 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
5 js> var controlChars = [
6 > 0x200C, 0x200D, 0x200E, 0x200F,
7 > 0x202A, 0x202B, 0x202C, 0x202D, 0x202E,
8 > 0x00AD,
9 > 0x2061, 0x2062, 0x2063, 0x2064,
10 > 0x206A, 0x206B, 0x206C, 0x206D, 0x206E, 0x206F
11 > ];
12
13 js> function validInRegExpLiteral(num) {
14 > eval('/.'+String.fromCharCode(num)+'./');
15 > }
16 js> function validInStringLiteral(num) {
17 > eval('"'+String.fromCharCode(num)+'"');
18 > }
19 js> function validInComments(num) {
20 > eval('/*'+String.fromCharCode(num)+'*/');
21 > }
22
23 js> function check(test) {
24 > return function(codePoint) {
25 > try {
26 > test(codePoint);
27 > return true;
28 > } catch (e) {
29 > throw "problem with U+"+codePoint.toString(16).toUpperCase()+": "+e;
30 > }
31 > };
32 > }
33
34 js> controlChars.every(check(validInRegExpLiteral))
35 true
36 js> controlChars.every(check(validInStringLiteral))
37 true
38 js> controlChars.every(check(validInComments))
39 true