Skip to content

Commit c62ad72

Browse files
committed
Generalize E'' string tests
1 parent cd624fc commit c62ad72

File tree

3 files changed

+22
-27
lines changed

3 files changed

+22
-27
lines changed

test/duckdb.test.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ describe('DuckDBFormatter', () => {
5252
supportsOnConflict(format);
5353
supportsUpdate(format);
5454
supportsTruncateTable(format, { withTable: false, withoutTable: true });
55-
supportsStrings(format, ["''-qq", "X''", "B''"]);
55+
supportsStrings(format, ["''-qq", "X''", "B''", "E''"]);
5656
supportsIdentifiers(format, [`""-qq`]);
5757
supportsBetween(format);
5858
// Missing: '::' type cast (tested separately)
@@ -138,18 +138,6 @@ describe('DuckDBFormatter', () => {
138138
});
139139

140140
// DuckDB-specific string types
141-
it("supports E'' strings with C-style escapes", () => {
142-
expect(format("E'blah blah'")).toBe("E'blah blah'");
143-
expect(format("E'some \\' FROM escapes'")).toBe("E'some \\' FROM escapes'");
144-
expect(format("SELECT E'blah' FROM foo")).toBe(dedent`
145-
SELECT
146-
E'blah'
147-
FROM
148-
foo
149-
`);
150-
expect(format("E'blah''blah'")).toBe("E'blah''blah'");
151-
});
152-
153141
it('supports basic dollar-quoted strings', () => {
154142
expect(format('$$foo JOIN bar$$')).toBe('$$foo JOIN bar$$');
155143
expect(format('$$foo $ JOIN bar$$')).toBe('$$foo $ JOIN bar$$');

test/features/strings.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ type StringType =
1717
| "B''" // no escaping
1818
| 'B""' // no escaping
1919
| "R''" // no escaping
20-
| 'R""'; // no escaping
20+
| 'R""' // no escaping
21+
| "E''"; // with backslash escaping
2122

2223
export default function supportsStrings(format: FormatFn, stringTypes: StringType[]) {
2324
if (stringTypes.includes('""-qq') || stringTypes.includes('""-bs')) {
@@ -238,4 +239,22 @@ export default function supportsStrings(format: FormatFn, stringTypes: StringTyp
238239
expect(format(`r"a ha"r"hm mm"`)).toBe(`r"a ha" r"hm mm"`);
239240
});
240241
}
242+
243+
if (stringTypes.includes("E''")) {
244+
it("supports E'' strings with C-style escapes", () => {
245+
expect(format("E'blah blah'")).toBe("E'blah blah'");
246+
expect(format("E'some \\' FROM escapes'")).toBe("E'some \\' FROM escapes'");
247+
expect(format("SELECT E'blah' FROM foo")).toBe(dedent`
248+
SELECT
249+
E'blah'
250+
FROM
251+
foo
252+
`);
253+
expect(format("E'blah''blah'")).toBe("E'blah''blah'");
254+
});
255+
256+
it(`detects consecutive E'' strings as separate ones`, () => {
257+
expect(format(`e'a ha'e'hm mm'`)).toBe(`e'a ha' e'hm mm'`);
258+
});
259+
}
241260
}

test/postgresql.test.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ describe('PostgreSqlFormatter', () => {
5555
supportsOnConflict(format);
5656
supportsUpdate(format, { whereCurrentOf: true });
5757
supportsTruncateTable(format, { withoutTable: true });
58-
supportsStrings(format, ["''-qq", "U&''", "X''", "B''"]);
58+
supportsStrings(format, ["''-qq", "U&''", "X''", "B''", "E''"]);
5959
supportsIdentifiers(format, [`""-qq`, 'U&""']);
6060
supportsBetween(format);
6161
supportsSchema(format);
@@ -173,18 +173,6 @@ describe('PostgreSqlFormatter', () => {
173173
});
174174

175175
// Postgres-specific string types
176-
it("supports E'' strings with C-style escapes", () => {
177-
expect(format("E'blah blah'")).toBe("E'blah blah'");
178-
expect(format("E'some \\' FROM escapes'")).toBe("E'some \\' FROM escapes'");
179-
expect(format("SELECT E'blah' FROM foo")).toBe(dedent`
180-
SELECT
181-
E'blah'
182-
FROM
183-
foo
184-
`);
185-
expect(format("E'blah''blah'")).toBe("E'blah''blah'");
186-
});
187-
188176
it('supports dollar-quoted strings', () => {
189177
expect(format('$xxx$foo $$ LEFT JOIN $yyy$ bar$xxx$')).toBe(
190178
'$xxx$foo $$ LEFT JOIN $yyy$ bar$xxx$'

0 commit comments

Comments
 (0)