Skip to content

Commit 13c41e5

Browse files
committed
add more tests for tagged templates
1 parent 5a8659f commit 13c41e5

File tree

4 files changed

+71
-25
lines changed

4 files changed

+71
-25
lines changed

jscomp/test/build.ninja

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,8 @@ o test/submodule.cmi test/submodule.cmj : cc test/submodule.res | $bsc $stdlib r
571571
o test/submodule_call.cmi test/submodule_call.cmj : cc test/submodule_call.res | test/submodule.cmj $bsc $stdlib runtime
572572
o test/switch_case_test.cmi test/switch_case_test.cmj : cc test/switch_case_test.res | test/mt.cmj $bsc $stdlib runtime
573573
o test/switch_string.cmi test/switch_string.cmj : cc test/switch_string.res | $bsc $stdlib runtime
574-
o test/tagged_template_test.cmi test/tagged_template_test.cmj : cc test/tagged_template_test.res | test/mt.cmj $bsc $stdlib runtime
574+
o test/tagged_template_test.cmj : cc_cmi test/tagged_template_test.res | test/mt.cmj test/tagged_template_test.cmi $bsc $stdlib runtime
575+
o test/tagged_template_test.cmi : cc test/tagged_template_test.resi | $bsc $stdlib runtime
575576
o test/tailcall_inline_test.cmi test/tailcall_inline_test.cmj : cc test/tailcall_inline_test.res | test/mt.cmj $bsc $stdlib runtime
576577
o test/template.cmi test/template.cmj : cc test/template.res | $bsc $stdlib runtime
577578
o test/test.cmi test/test.cmj : cc test/test.res | $bsc $stdlib runtime

jscomp/test/tagged_template_test.js

Lines changed: 41 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jscomp/test/tagged_template_test.res

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,36 @@
1-
@module("./tagged_template_lib.js") @variadic external sql: (array<string>, array<string>) => string = "sql"
1+
@module("./tagged_template_lib.js") @variadic
2+
external sql: (array<string>, array<string>) => string = "sql"
23

34
let table = "users"
45
let id = "5"
56

67
let query = sql`SELECT * FROM ${table} WHERE id = ${id}`
78

9+
let foo = (strings, values) => {
10+
let res = ref("")
11+
let valueCount = Array.length(values)
12+
for i in 0 to valueCount - 1 {
13+
res := res.contents ++ strings[i] ++ string_of_int(values[i] * 10)
14+
}
15+
res.contents ++ strings[valueCount]
16+
}
17+
18+
let res = foo`| 5 * 10 = ${5} |`
19+
820
Mt.from_pair_suites(
9-
"tagged template",
10-
list{
11-
("it should return a string with the correct interpolations", () =>
12-
Eq(query, "SELECT * FROM users WHERE id = 5")),
13-
}
21+
"tagged templates",
22+
list{
23+
(
24+
"with externals, it should return a string with the correct interpolations",
25+
() => Eq(query, "SELECT * FROM users WHERE id = 5"),
26+
),
27+
(
28+
"with rescript function, it should return a string with the correct interpolations",
29+
() => Eq(res, "| 5 * 10 = 50 |"),
30+
),
31+
(
32+
"a template literal tagged with json should generate a regular string interpolation for now",
33+
() => Eq(json`some random ${"string"}`, "some random string"),
34+
),
35+
},
1436
)

jscomp/test/tagged_template_test.resi

Whitespace-only changes.

0 commit comments

Comments
 (0)