mirror of
https://github.com/tc39/test262.git
synced 2025-05-03 22:40:28 +02:00
* [javascriptcore-test262-automation] changes from git@github.com:WebKit/webkit.git at sha 949e26452cfa153a7f4afe593da97e2fe9e1b706 on Tue Jul 03 2018 14:35:15 GMT-0400 (Eastern Daylight Time)
112 lines
5.6 KiB
JavaScript
112 lines
5.6 KiB
JavaScript
|
|
function testSyntax(script) {
|
|
try {
|
|
eval(script);
|
|
} catch (error) {
|
|
if (error instanceof SyntaxError)
|
|
throw new Error("Bad error: " + String(error));
|
|
}
|
|
}
|
|
|
|
function testSyntaxError(script, message) {
|
|
var error = null;
|
|
try {
|
|
eval(script);
|
|
} catch (e) {
|
|
error = e;
|
|
}
|
|
if (!error)
|
|
throw new Error("Expected syntax error not thrown");
|
|
|
|
if (String(error) !== message)
|
|
throw new Error("Bad error: " + String(error));
|
|
}
|
|
|
|
testSyntax("`Hello`");
|
|
testSyntax("(`Hello`)");
|
|
testSyntax("(`Hello`) + 42");
|
|
testSyntax("`\nHello\nWorld`");
|
|
testSyntax("`\nHello\n${World}`");
|
|
testSyntax("`${World}`");
|
|
testSyntax("`${World} Hello`");
|
|
testSyntax("`$ {World} Hello`");
|
|
testSyntax("`\\uFEFFtest`");
|
|
testSyntax("`\r\n`");
|
|
testSyntax("`\\r\\n`");
|
|
testSyntax("`\n`");
|
|
testSyntax("`\\n`");
|
|
testSyntax("`\u2028`");
|
|
testSyntax("`\\u2028`");
|
|
testSyntax("`\u2029`");
|
|
testSyntax("`\\u2029`");
|
|
testSyntax("`\\0`");
|
|
testSyntax("`\0`");
|
|
testSyntax("`\\x7f`");
|
|
testSyntax("(`Hello`) + 42");
|
|
testSyntax("`\\\n`");
|
|
testSyntax("`\\\r\n`");
|
|
testSyntax("`\\\r`");
|
|
testSyntax("Hello`bad escape sequence: \\unicode`");
|
|
testSyntax("Hello`\\00`");
|
|
testSyntax("Hello`\\01`");
|
|
testSyntax("Hello`\\1`");
|
|
testSyntax("Hello`\\xo`");
|
|
testSyntax("Hello`\\x0o`");
|
|
testSyntax("Hello`\\uo`");
|
|
testSyntax("Hello`\\u0o`");
|
|
testSyntax("Hello`\\u00o`");
|
|
testSyntax("Hello`\\u000o`");
|
|
testSyntax("Hello`\\u{o`");
|
|
testSyntax("Hello`\\u{0o`");
|
|
testSyntax("Hello`\\u{110000o`");
|
|
|
|
testSyntaxError("`Hello", "SyntaxError: Unexpected EOF");
|
|
testSyntaxError("`Hello${expr}", "SyntaxError: Unexpected EOF");
|
|
testSyntaxError("`Hello${}", "SyntaxError: Unexpected token '}'. Template literal expression cannot be empty.");
|
|
testSyntaxError("`Hello${expr} ${}", "SyntaxError: Unexpected token '}'. Template literal expression cannot be empty.");
|
|
testSyntaxError("`Hello${expr}", "SyntaxError: Unexpected EOF");
|
|
testSyntaxError("`Hello${expr} ${expr}", "SyntaxError: Unexpected EOF");
|
|
testSyntaxError("`Hello${expr`", "SyntaxError: Unexpected EOF");
|
|
testSyntaxError("`Hello${expr} ${expr`", "SyntaxError: Unexpected EOF");
|
|
testSyntaxError("`Hello expr${`", "SyntaxError: Unexpected EOF");
|
|
testSyntaxError("`Hello${expr} expr${`", "SyntaxError: Unexpected EOF");
|
|
testSyntaxError("`Hello ${}`", "SyntaxError: Unexpected token '}'. Template literal expression cannot be empty.");
|
|
testSyntaxError("`Hello${expr} ${}`", "SyntaxError: Unexpected token '}'. Template literal expression cannot be empty.");
|
|
testSyntaxError("`\\07`", "SyntaxError: The only valid numeric escape in strict mode is '\\0'");
|
|
for (var i = 1; i < 7; ++i) {
|
|
testSyntaxError("`\\" + i + "`", "SyntaxError: The only valid numeric escape in strict mode is '\\0'");
|
|
testSyntaxError("`${expr}\\" + i + "`", "SyntaxError: The only valid numeric escape in strict mode is '\\0'");
|
|
}
|
|
// \8 and \9 are not allowed.
|
|
for (var i = 8; i < 9; ++i) {
|
|
testSyntaxError("`\\" + i + "`", "SyntaxError: The only valid numeric escape in strict mode is '\\0'");
|
|
testSyntaxError("`${expr}\\" + i + "`", "SyntaxError: The only valid numeric escape in strict mode is '\\0'");
|
|
}
|
|
testSyntaxError("`\\x7`", "SyntaxError: \\x can only be followed by a hex character sequence");
|
|
testSyntaxError("`${expr}\\x7`", "SyntaxError: \\x can only be followed by a hex character sequence");
|
|
testSyntaxError("`\\x`", "SyntaxError: \\x can only be followed by a hex character sequence");
|
|
testSyntaxError("`${expr}\\x`", "SyntaxError: \\x can only be followed by a hex character sequence");
|
|
testSyntaxError("`\\u`", "SyntaxError: \\u can only be followed by a Unicode character sequence");
|
|
testSyntaxError("`${expr}\\u`", "SyntaxError: \\u can only be followed by a Unicode character sequence");
|
|
testSyntaxError("`\\u2`", "SyntaxError: \\u can only be followed by a Unicode character sequence");
|
|
testSyntaxError("`${expr}\\u2`", "SyntaxError: \\u can only be followed by a Unicode character sequence");
|
|
testSyntaxError("`\\u20`", "SyntaxError: \\u can only be followed by a Unicode character sequence");
|
|
testSyntaxError("`${expr}\\u20`", "SyntaxError: \\u can only be followed by a Unicode character sequence");
|
|
testSyntaxError("`\\u202`", "SyntaxError: \\u can only be followed by a Unicode character sequence");
|
|
testSyntaxError("`${expr}\\u202`", "SyntaxError: \\u can only be followed by a Unicode character sequence");
|
|
|
|
testSyntaxError("`bad escape sequence: \\unicode`", "SyntaxError: \\u can only be followed by a Unicode character sequence");
|
|
|
|
testSyntaxError("`\\00`", "SyntaxError: The only valid numeric escape in strict mode is '\\0'");
|
|
testSyntaxError("`\\01`", "SyntaxError: The only valid numeric escape in strict mode is '\\0'");
|
|
testSyntaxError("`\\1`", "SyntaxError: The only valid numeric escape in strict mode is '\\0'");
|
|
testSyntaxError("`\\xo`", "SyntaxError: \\x can only be followed by a hex character sequence");
|
|
testSyntaxError("`\\x0o`", "SyntaxError: \\x can only be followed by a hex character sequence");
|
|
testSyntaxError("`\\uo`", "SyntaxError: \\u can only be followed by a Unicode character sequence");
|
|
testSyntaxError("`\\u0o`", "SyntaxError: \\u can only be followed by a Unicode character sequence");
|
|
testSyntaxError("`\\u00o`", "SyntaxError: \\u can only be followed by a Unicode character sequence");
|
|
testSyntaxError("`\\u000o`", "SyntaxError: \\u can only be followed by a Unicode character sequence");
|
|
testSyntaxError("`\\u{o`", "SyntaxError: \\u can only be followed by a Unicode character sequence");
|
|
testSyntaxError("`\\u{0o`", "SyntaxError: \\u can only be followed by a Unicode character sequence");
|
|
testSyntaxError("`\\u{110000o`", "SyntaxError: \\u can only be followed by a Unicode character sequence");
|