| 1 |
/* |
| 2 |
* Any copyright is dedicated to the Public Domain. |
| 3 |
* http://creativecommons.org/licenses/publicdomain/ |
| 4 |
*/ |
| 5 |
|
| 6 |
var BUGNUMBER = 1434429; |
| 7 |
var summary = |
| 8 |
"Report unterminated string/template literal errors with the line/column " + |
| 9 |
"number of the point of non-termination"; |
| 10 |
|
| 11 |
function test(f, quotes, [line, col]) |
| 12 |
{ |
| 13 |
var caught = false; |
| 14 |
try |
| 15 |
{ |
| 16 |
f(); |
| 17 |
} |
| 18 |
catch (e) |
| 19 |
{ |
| 20 |
caught = true; |
| 21 |
assertEq(e.lineNumber, line, "line number"); |
| 22 |
assertEq(e.columnNumber, col, "column number"); |
| 23 |
assertEq(e.message.includes(quotes), true, |
| 24 |
"message must contain delimiter"); |
| 25 |
} |
| 26 |
|
| 27 |
assertEq(caught, true); |
| 28 |
} |
| 29 |
|
| 30 |
test(function() { |
| 31 |
//1234 |
| 32 |
eval("'hi"); |
| 33 |
}, "''", [1, 4]); |
| 34 |
|
| 35 |
test(function() { |
| 36 |
//1234 5 |
| 37 |
eval("'hi\\"); |
| 38 |
}, "''", [1, 5]); |
| 39 |
|
| 40 |
test(function() { |
| 41 |
//1234567 |
| 42 |
eval(" 'hi"); |
| 43 |
}, "''", [1, 7]); |
| 44 |
|
| 45 |
test(function() { |
| 46 |
//1234567 8 |
| 47 |
eval(" 'hi\\"); |
| 48 |
}, "''", [1, 8]); |
| 49 |
|
| 50 |
test(function() { |
| 51 |
//12345678 12345678 |
| 52 |
eval('var x =\n "hi'); |
| 53 |
}, '""', [2, 8]); |
| 54 |
|
| 55 |
test(function() { |
| 56 |
//1234567 12345678 9 |
| 57 |
eval('var x =\n "hi\\'); |
| 58 |
}, '""', [2, 9]); |
| 59 |
|
| 60 |
test(function() { |
| 61 |
// 1 |
| 62 |
//1234567 12345678 123456789 12345678901234 |
| 63 |
eval('var x =\n "hi\\\n bye\\\n no really'); |
| 64 |
}, '""', [4, 14]); |
| 65 |
|
| 66 |
test(function() { |
| 67 |
// 1 |
| 68 |
//1234567 12345678 123456789 12345678901234 5 |
| 69 |
eval('var x =\n "hi\\\n bye\\\n no really\\'); |
| 70 |
}, '""', [4, 15]); |
| 71 |
|
| 72 |
test(function() { |
| 73 |
//1234567 12345678 123456789 |
| 74 |
eval('var x =\n "hi\\\n bye\n'); |
| 75 |
}, '""', [3, 9]); |
| 76 |
|
| 77 |
test(function() { |
| 78 |
// 1 |
| 79 |
//1234567 12345678 123456789 0 |
| 80 |
eval('var x =\n "hi\\\n bye\\'); |
| 81 |
}, '""', [3, 10]); |
| 82 |
|
| 83 |
test(function() { |
| 84 |
//1234567 12345678 |
| 85 |
eval('var x =\n `'); |
| 86 |
}, '``', [2, 8]); |
| 87 |
|
| 88 |
test(function() { |
| 89 |
//1234567 12345678 9 |
| 90 |
eval('var x =\n `\\'); |
| 91 |
}, '``', [2, 9]); |
| 92 |
|
| 93 |
test(function() { |
| 94 |
// 1 |
| 95 |
//1234567 1234567890123456 |
| 96 |
eval('var x =\n htmlEscape`'); |
| 97 |
}, '``', [2, 16]); |
| 98 |
|
| 99 |
test(function() { |
| 100 |
// 1 |
| 101 |
//1234567 1234567890123456 7 |
| 102 |
eval('var x =\n htmlEscape`\\'); |
| 103 |
}, '``', [2, 17]); |
| 104 |
|
| 105 |
test(function() { |
| 106 |
// 1 |
| 107 |
//1234567 12345678901234 12345 |
| 108 |
eval('var x =\n htmlEscape\n `'); |
| 109 |
}, '``', [3, 5]); |
| 110 |
|
| 111 |
test(function() { |
| 112 |
// 1 |
| 113 |
//1234567 12345678901234 12345 6 |
| 114 |
eval('var x =\n htmlEscape\n `\\'); |
| 115 |
}, '``', [3, 6]); |
| 116 |
|
| 117 |
if (typeof reportCompare === "function") |
| 118 |
reportCompare(0, 0, "ok"); |
| 119 |
|
| 120 |
print("Tests complete"); |