forked from TypeScriptToLua/TypeScriptToLua
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplateLiterals.spec.ts
More file actions
62 lines (55 loc) · 1.97 KB
/
Copy pathtemplateLiterals.spec.ts
File metadata and controls
62 lines (55 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import * as util from "../util";
test.each([
{ a: 12, b: 23, c: 43 },
{ a: "test", b: "hello", c: "bye" },
{ a: "test", b: 42, c: "bye" },
{ a: "test", b: 42, c: 12 },
{ a: "test", b: 42, c: true },
{ a: false, b: 42, c: 12 },
])("template literal (%p)", ({ a, b, c }) => {
util.testExpressionTemplate`\`\${${a}} \${${b}} test \${${c}}\``.expectToMatchJsResult();
});
test.each(["a++", "a--", "--a", "++a"])("template literal with expression (%p)", expression => {
util.testFunction`
let a = 3;
return \`value\${${expression}}\`;
`.expectToMatchJsResult();
});
test.each(["`foo${'bar'}`.length", "`foo${'bar'}`.repeat(2)"])("template literal property access (%p)", expression => {
util.testExpression(expression).expectToMatchJsResult();
});
test.each([
"func``",
"func`hello`",
"func`hello ${1} ${2} ${3}`",
"func`hello ${(() => 'iife')()}`",
"func`hello ${1 + 2 + 3} arithmetic`",
"func`begin ${'middle'} end`",
"func`hello ${func`hello`}`",
"func`hello \\u00A9`",
"func`hello $ { }`",
"func`hello { ${'brackets'} }`",
"func`hello \\``",
"obj.func`hello ${'propertyAccessExpression'}`",
"obj['func']`hello ${'elementAccessExpression'}`",
])("tagged template literal (%p)", expression => {
util.testFunction`
function func(strings: TemplateStringsArray, ...expressions: any[]) {
return { strings: [...strings], raw: strings.raw, expressions };
}
const obj = { func };
return ${expression};
`.expectToMatchJsResult();
});
test.each(["func`noSelfParameter`", "obj.func`noSelfParameter`", "obj[`func`]`noSelfParameter`"])(
"tagged template literal function context (%p)",
expression => {
util.testFunction`
function func(this: void, strings: TemplateStringsArray) {
return [...strings];
}
const obj = { func };
return ${expression};
`.expectToMatchJsResult();
}
);