]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/stress/template-literal-syntax.js
2 function testSyntax(script
) {
6 if (error
instanceof SyntaxError
)
7 throw new Error("Bad error: " + String(error
));
11 function testSyntaxError(script
, message
) {
19 throw new Error("Expected syntax error not thrown");
21 if (String(error
) !== message
)
22 throw new Error("Bad error: " + String(error
));
25 testSyntax("`Hello`");
26 testSyntax("(`Hello`)");
27 testSyntax("(`Hello`) + 42");
28 testSyntax("`\nHello\nWorld`");
29 testSyntax("`\nHello\n${World}`");
30 testSyntax("`${World}`");
31 testSyntax("`${World} Hello`");
32 testSyntax("`$ {World} Hello`");
33 testSyntax("`\\uFEFFtest`");
35 testSyntax("`\\r\\n`");
38 testSyntax("`\u2028`");
39 testSyntax("`\\u2028`");
40 testSyntax("`\u2029`");
41 testSyntax("`\\u2029`");
44 testSyntax("`\\x7f`");
45 testSyntax("(`Hello`) + 42");
47 testSyntax("`\\\r\n`");
50 testSyntaxError("`Hello", "SyntaxError: Unexpected EOF");
51 testSyntaxError("`Hello${expr}", "SyntaxError: Unexpected EOF");
52 testSyntaxError("`Hello${}", "SyntaxError: Unexpected token '}'. Template literal expression cannot be empty.");
53 testSyntaxError("`Hello${expr} ${}", "SyntaxError: Unexpected token '}'. Template literal expression cannot be empty.");
54 testSyntaxError("`Hello${expr}", "SyntaxError: Unexpected EOF");
55 testSyntaxError("`Hello${expr} ${expr}", "SyntaxError: Unexpected EOF");
56 testSyntaxError("`Hello${expr`", "SyntaxError: Unexpected EOF");
57 testSyntaxError("`Hello${expr} ${expr`", "SyntaxError: Unexpected EOF");
58 testSyntaxError("`Hello expr${`", "SyntaxError: Unexpected EOF");
59 testSyntaxError("`Hello${expr} expr${`", "SyntaxError: Unexpected EOF");
60 testSyntaxError("`Hello ${}`", "SyntaxError: Unexpected token '}'. Template literal expression cannot be empty.");
61 testSyntaxError("`Hello${expr} ${}`", "SyntaxError: Unexpected token '}'. Template literal expression cannot be empty.");
62 testSyntaxError("`\\07`", "SyntaxError: The only valid numeric escape in strict mode is '\\0'");
63 for (var i
= 1; i
< 7; ++i
) {
64 testSyntaxError("`\\" + i
+ "`", "SyntaxError: The only valid numeric escape in strict mode is '\\0'");
65 testSyntaxError("`${expr}\\" + i
+ "`", "SyntaxError: The only valid numeric escape in strict mode is '\\0'");
67 // \8 and \9 are not allowed.
68 for (var i
= 8; i
< 9; ++i
) {
69 testSyntaxError("`\\" + i
+ "`", "SyntaxError: The only valid numeric escape in strict mode is '\\0'");
70 testSyntaxError("`${expr}\\" + i
+ "`", "SyntaxError: The only valid numeric escape in strict mode is '\\0'");
72 testSyntaxError("`\\x7`", "SyntaxError: \\x can only be followed by a hex character sequence");
73 testSyntaxError("`${expr}\\x7`", "SyntaxError: \\x can only be followed by a hex character sequence");
74 testSyntaxError("`\\x`", "SyntaxError: \\x can only be followed by a hex character sequence");
75 testSyntaxError("`${expr}\\x`", "SyntaxError: \\x can only be followed by a hex character sequence");
76 testSyntaxError("`\\u`", "SyntaxError: \\u can only be followed by a Unicode character sequence");
77 testSyntaxError("`${expr}\\u`", "SyntaxError: \\u can only be followed by a Unicode character sequence");
78 testSyntaxError("`\\u2`", "SyntaxError: \\u can only be followed by a Unicode character sequence");
79 testSyntaxError("`${expr}\\u2`", "SyntaxError: \\u can only be followed by a Unicode character sequence");
80 testSyntaxError("`\\u20`", "SyntaxError: \\u can only be followed by a Unicode character sequence");
81 testSyntaxError("`${expr}\\u20`", "SyntaxError: \\u can only be followed by a Unicode character sequence");
82 testSyntaxError("`\\u202`", "SyntaxError: \\u can only be followed by a Unicode character sequence");
83 testSyntaxError("`${expr}\\u202`", "SyntaxError: \\u can only be followed by a Unicode character sequence");