]> git.saurik.com Git - apple/javascriptcore.git/blame - tests/stress/template-literal-line-terminators.js
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / tests / stress / template-literal-line-terminators.js
CommitLineData
ed1e77d3
A
1
2function test(actual, expected) {
3 if (actual !== expected)
4 throw new Error("bad value: " + actual);
5}
6
7function testEval(script, expected) {
8 test(eval(script), expected);
9}
10
11function testEvalLineNumber(script, expected, lineNum) {
12 testEval(script, expected);
13
14 var error = null;
15 var actualLine;
16 try {
17 eval(script + ';throw new Error("line");');
18 } catch (error) {
19 actualLine = error.line;
20 }
21 test(actualLine, lineNum);
22}
23
24test(`Hello`, "Hello");
25test(`Hello World`, "Hello World");
26test(`
27`, "\n");
28test(`Hello
29World`, "Hello\nWorld");
30
31testEvalLineNumber("`Hello World`", "Hello World", 1);
32
33testEvalLineNumber("`Hello\rWorld`", "Hello\nWorld", 2);
34testEvalLineNumber("`Hello\nWorld`", "Hello\nWorld", 2);
35
36testEvalLineNumber("`Hello\r\rWorld`", "Hello\n\nWorld", 3);
37testEvalLineNumber("`Hello\r\nWorld`", "Hello\nWorld", 2);
38testEvalLineNumber("`Hello\n\nWorld`", "Hello\n\nWorld", 3);
39testEvalLineNumber("`Hello\n\rWorld`", "Hello\n\nWorld", 2);
40
41testEvalLineNumber("`Hello\n\r\nWorld`", "Hello\n\nWorld", 3);
42testEvalLineNumber("`Hello\r\n\rWorld`", "Hello\n\nWorld", 3);
43testEvalLineNumber("`Hello\n\n\nWorld`", "Hello\n\n\nWorld", 4);
44
45testEvalLineNumber("`Hello\n\r\n\rWorld`", "Hello\n\n\nWorld", 3);
46testEvalLineNumber("`Hello\n\r\n\nWorld`", "Hello\n\n\nWorld", 4);
47testEvalLineNumber("`Hello\r\n\n\nWorld`", "Hello\n\n\nWorld", 4);
48
49testEvalLineNumber("`Hello\\\n\r\rWorld`", "Hello\n\nWorld", 3);
50testEvalLineNumber("`Hello\\\r\n\n\nWorld`", "Hello\n\nWorld", 4);
51testEvalLineNumber("`Hello\\\n\r\n\nWorld`", "Hello\n\nWorld", 4);
52testEvalLineNumber("`Hello\\\n\r\r\nWorld`", "Hello\n\nWorld", 3);
53
54testEvalLineNumber("`\u2028`", "\u2028", 2);
55testEvalLineNumber("`\u2029`", "\u2029", 2);
56testEvalLineNumber("`\\u2028`", "\u2028", 1);
57testEvalLineNumber("`\\u2029`", "\u2029", 1);