Skip to content

Commit 861e4ee

Browse files
committed
JS: Added test cases including manual interpolation and string concatination.
1 parent 92084dd commit 861e4ee

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

javascript/ql/test/query-tests/LanguageFeatures/TemplateSyntaxInStringLiteral/TemplateSyntaxInStringLiteral.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@
33
| TemplateSyntaxInStringLiteral.js:19:11:19:36 | 'global ... alVar}' | This string is not a template literal, but appears to reference the variable $@. | TemplateSyntaxInStringLiteral.js:14:5:14:13 | globalVar | globalVar |
44
| TemplateSyntaxInStringLiteral.js:28:15:28:21 | "${x} " | This string is not a template literal, but appears to reference the variable $@. | TemplateSyntaxInStringLiteral.js:25:14:25:14 | x | x |
55
| TemplateSyntaxInStringLiteral.js:42:17:42:57 | "Name: ... oobar}" | This string is not a template literal, but appears to reference the variable $@. | TemplateSyntaxInStringLiteral.js:37:11:37:16 | foobar | foobar |
6+
| TemplateSyntaxInStringLiteral.js:47:27:47:51 | ") ${ex ... got (" | This string is not a template literal, but appears to reference the variable $@. | TemplateSyntaxInStringLiteral.js:45:20:45:27 | expected | expected |
7+
| TemplateSyntaxInStringLiteral.js:47:71:47:83 | ") ${actual}" | This string is not a template literal, but appears to reference the variable $@. | TemplateSyntaxInStringLiteral.js:45:12:45:17 | actual | actual |
8+
| TemplateSyntaxInStringLiteral.js:62:15:62:29 | "Name: ${name}" | This string is not a template literal, but appears to reference the variable $@. | TemplateSyntaxInStringLiteral.js:61:30:61:33 | name | name |
9+
| TemplateSyntaxInStringLiteral.js:66:11:66:44 | "Name: ... {name}" | This string is not a template literal, but appears to reference the variable $@. | TemplateSyntaxInStringLiteral.js:61:30:61:33 | name | name |

javascript/ql/test/query-tests/LanguageFeatures/TemplateSyntaxInStringLiteral/TemplateSyntaxInStringLiteral.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,30 @@ function foo1() {
4040
writer.emit("Name: ${name}, Date: ${date}.", data);
4141

4242
writer.emit("Name: ${name}, Date: ${date}, ${foobar}", data); // $ Alert - `foobar` is not in `data`.
43-
}
43+
}
44+
45+
function a(actual, expected, description) {
46+
assert(false, "a", description, "expected (" +
47+
typeof expected + ") ${expected} but got (" + typeof actual + ") ${actual}", { // $SPURIOUS:Alert
48+
expected: expected,
49+
actual: actual
50+
});
51+
}
52+
53+
function replacer(str, name) {
54+
return str.replace("${name}", name);
55+
}
56+
57+
function replacerAll(str, name) {
58+
return str.replaceAll("${name}", name);
59+
}
60+
61+
function manualInterpolation(name) {
62+
let str = "Name: ${name}"; // $SPURIOUS:Alert
63+
let result1 = replacer(str, name);
64+
console.log(result1);
65+
66+
str = "Name: ${name} and again: ${name}"; // $SPURIOUS:Alert
67+
let result2 = replacerAll(str, name);
68+
console.log(result2);
69+
}

0 commit comments

Comments
 (0)