Skip to content

Commit 5e17ac0

Browse files
committed
add test for passing stringifyObjects via options to tag handler
1 parent 4ff723d commit 5e17ac0

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

lib/es6/Template.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function computeStatic (strings) {
5757
}
5858

5959
function interpolateSqlIntoFragment (
60-
{ stringifyObjects, timeZone } = {},
60+
{ stringifyObjects, timeZone },
6161
{ raw, delimiters, chunks },
6262
strings, values) {
6363
// A buffer to accumulate output.

test/unit/es6/Template.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,30 @@ test('template tag', {
2626
() => sql`SELECT ${1 + 1}`);
2727
},
2828
'date': function () {
29+
const date = new Date(Date.UTC(2000, 0, 1, 0, 0, 0));
2930
runTagTest(
3031
`SELECT '2000-01-01 00:00:00.000'`,
31-
() => sql({ timeZone: 'GMT' })`SELECT ${new Date(Date.UTC(2000, 0, 1, 0, 0, 0))}`);
32+
() => sql({ timeZone: 'GMT' })`SELECT ${date}`);
3233
},
3334
'string': function () {
3435
runTagTest(
3536
`SELECT 'Hello, World!\\n'`,
3637
() => sql`SELECT ${'Hello, World!\n'}`);
3738
},
39+
'stringify': function () {
40+
const obj = {
41+
'Hello': 'World!',
42+
toString: function () {
43+
return 'Hello, World!';
44+
}
45+
};
46+
runTagTest(
47+
`SELECT 'Hello, World!'`,
48+
() => sql({ stringifyObjects: true })`SELECT ${obj}`);
49+
runTagTest(
50+
'SELECT * FROM t WHERE `Hello` = \'World!\'',
51+
() => sql({ stringifyObjects: false })`SELECT * FROM t WHERE ${obj}`);
52+
},
3853
'identifier': function () {
3954
runTagTest(
4055
'SELECT `foo`',
@@ -139,4 +154,7 @@ test('template tag', {
139154
// See comments in lib/es6/Lexer.js.
140155
assert.throws(() => sql`SELECT (${0}) -- comment`);
141156
}
157+
158+
// TODO: is there a token-merging hazard in sql`SELECT 'x'${'y'}`?
159+
// A literal ' shows up in the decoded output of a single string literal.
142160
});

0 commit comments

Comments
 (0)