Skip to content

Commit bf5beff

Browse files
committed
add test for external tagged template not returning a string
1 parent c6044f4 commit bf5beff

File tree

3 files changed

+36
-8
lines changed

3 files changed

+36
-8
lines changed

jscomp/test/tagged_template_lib.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@ exports.sql = (strings, ...values) => {
55
}
66
result += strings[values.length];
77
return result;
8-
};
8+
};
9+
10+
exports.length = (strings, ...values) =>
11+
strings.reduce((acc, curr) => acc + curr.length, 0) +
12+
values.reduce((acc, curr) => acc + curr, 0);

jscomp/test/tagged_template_test.js

Lines changed: 21 additions & 7 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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ let id = "5"
66

77
let query = sql`SELECT * FROM ${table} WHERE id = ${id}`
88

9+
@module("./tagged_template_lib.js") @variadic
10+
external length: (array<string>, array<int>) => int = "length"
11+
12+
let extraLength = 10
13+
let length = length`hello ${extraLength} what's the total length? Is it ${3}?`
14+
915
let foo = (strings, values) => {
1016
let res = ref("")
1117
let valueCount = Array.length(values)
@@ -23,6 +29,10 @@ Mt.from_pair_suites(
2329
(
2430
"with externals, it should return a string with the correct interpolations",
2531
() => Eq(query, "SELECT * FROM 'users' WHERE id = '5'"),
32+
),
33+
(
34+
"with externals, it should return the result of the function",
35+
() => Eq(length, 52),
2636
),
2737
(
2838
"with rescript function, it should return a string with the correct interpolations",

0 commit comments

Comments
 (0)