]> git.saurik.com Git - apple/javascriptcore.git/blob - tests/stress/template-literal-line-terminators.js
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / tests / stress / template-literal-line-terminators.js
1
2 function test(actual, expected) {
3 if (actual !== expected)
4 throw new Error("bad value: " + actual);
5 }
6
7 function testEval(script, expected) {
8 test(eval(script), expected);
9 }
10
11 function 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
24 test(`Hello`, "Hello");
25 test(`Hello World`, "Hello World");
26 test(`
27 `, "\n");
28 test(`Hello
29 World`, "Hello\nWorld");
30
31 testEvalLineNumber("`Hello World`", "Hello World", 1);
32
33 testEvalLineNumber("`Hello\rWorld`", "Hello\nWorld", 2);
34 testEvalLineNumber("`Hello\nWorld`", "Hello\nWorld", 2);
35
36 testEvalLineNumber("`Hello\r\rWorld`", "Hello\n\nWorld", 3);
37 testEvalLineNumber("`Hello\r\nWorld`", "Hello\nWorld", 2);
38 testEvalLineNumber("`Hello\n\nWorld`", "Hello\n\nWorld", 3);
39 testEvalLineNumber("`Hello\n\rWorld`", "Hello\n\nWorld", 2);
40
41 testEvalLineNumber("`Hello\n\r\nWorld`", "Hello\n\nWorld", 3);
42 testEvalLineNumber("`Hello\r\n\rWorld`", "Hello\n\nWorld", 3);
43 testEvalLineNumber("`Hello\n\n\nWorld`", "Hello\n\n\nWorld", 4);
44
45 testEvalLineNumber("`Hello\n\r\n\rWorld`", "Hello\n\n\nWorld", 3);
46 testEvalLineNumber("`Hello\n\r\n\nWorld`", "Hello\n\n\nWorld", 4);
47 testEvalLineNumber("`Hello\r\n\n\nWorld`", "Hello\n\n\nWorld", 4);
48
49 testEvalLineNumber("`Hello\\\n\r\rWorld`", "Hello\n\nWorld", 3);
50 testEvalLineNumber("`Hello\\\r\n\n\nWorld`", "Hello\n\nWorld", 4);
51 testEvalLineNumber("`Hello\\\n\r\n\nWorld`", "Hello\n\nWorld", 4);
52 testEvalLineNumber("`Hello\\\n\r\r\nWorld`", "Hello\n\nWorld", 3);
53
54 testEvalLineNumber("`\u2028`", "\u2028", 2);
55 testEvalLineNumber("`\u2029`", "\u2029", 2);
56 testEvalLineNumber("`\\u2028`", "\u2028", 1);
57 testEvalLineNumber("`\\u2029`", "\u2029", 1);