Skip to content

Commit 0544514

Browse files
committed
Move all common tests to behavesLikePostgresqlFormatter()
1 parent 89fc28b commit 0544514

File tree

3 files changed

+32
-58
lines changed

3 files changed

+32
-58
lines changed

test/behavesLikePostgresqlFormatter.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,42 @@
11
import dedent from 'dedent-js';
22
import { FormatFn } from '../src/sqlFormatter.js';
3+
import behavesLikeSqlFormatter from './behavesLikeSqlFormatter.js';
4+
import supportsComments from './features/comments.js';
5+
import supportsCommentOn from './features/commentOn.js';
6+
import supportsArrayAndMapAccessors from './features/arrayAndMapAccessors.js';
7+
import supportsAlterTable from './features/alterTable.js';
8+
import supportsDeleteFrom from './features/deleteFrom.js';
9+
import supportsInsertInto from './features/insertInto.js';
10+
import supportsOnConflict from './features/onConflict.js';
11+
import supportsBetween from './features/between.js';
12+
import supportsIsDistinctFrom from './features/isDistinctFrom.js';
13+
import supportsReturning from './features/returning.js';
14+
import supportsWindow from './features/window.js';
15+
import supportsDataTypeCase from './options/dataTypeCase.js';
316

417
/**
518
* Shared tests for PostgreSQL and DuckDB
619
*/
720
export default function behavesLikePostgresqlFormatter(format: FormatFn) {
21+
behavesLikeSqlFormatter(format);
22+
supportsComments(format, { nestedBlockComments: true });
23+
supportsCommentOn(format);
24+
supportsArrayAndMapAccessors(format);
25+
supportsAlterTable(format, {
26+
addColumn: true,
27+
dropColumn: true,
28+
renameTo: true,
29+
renameColumn: true,
30+
});
31+
supportsDeleteFrom(format);
32+
supportsInsertInto(format);
33+
supportsOnConflict(format);
34+
supportsBetween(format);
35+
supportsIsDistinctFrom(format);
36+
supportsReturning(format);
37+
supportsWindow(format);
38+
supportsDataTypeCase(format);
39+
840
it('allows $ character as part of identifiers', () => {
941
expect(format('SELECT foo$, some$$ident')).toBe(dedent`
1042
SELECT

test/duckdb.test.ts

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,61 +2,34 @@ import dedent from 'dedent-js';
22

33
import { format as originalFormat, FormatFn } from '../src/sqlFormatter.js';
44

5-
import behavesLikeSqlFormatter from './behavesLikeSqlFormatter.js';
65
import behavesLikePostgresqlFormatter from './behavesLikePostgresqlFormatter.js';
7-
import supportsAlterTable from './features/alterTable.js';
8-
import supportsBetween from './features/between.js';
96
import supportsCreateTable from './features/createTable.js';
107
import supportsDropTable from './features/dropTable.js';
118
import supportsJoin from './features/join.js';
129
import supportsOperators from './features/operators.js';
1310
import supportsStrings from './features/strings.js';
14-
import supportsReturning from './features/returning.js';
15-
import supportsDeleteFrom from './features/deleteFrom.js';
16-
import supportsComments from './features/comments.js';
17-
import supportsCommentOn from './features/commentOn.js';
1811
import supportsIdentifiers from './features/identifiers.js';
1912
import supportsParams from './options/param.js';
20-
import supportsArrayAndMapAccessors from './features/arrayAndMapAccessors.js';
21-
import supportsWindow from './features/window.js';
2213
import supportsSetOperations from './features/setOperations.js';
2314
import supportsLimiting from './features/limiting.js';
24-
import supportsInsertInto from './features/insertInto.js';
2515
import supportsUpdate from './features/update.js';
2616
import supportsCreateView from './features/createView.js';
27-
import supportsOnConflict from './features/onConflict.js';
28-
import supportsIsDistinctFrom from './features/isDistinctFrom.js';
2917
import supportsArrayLiterals from './features/arrayLiterals.js';
30-
import supportsDataTypeCase from './options/dataTypeCase.js';
3118
import supportsTruncateTable from './features/truncateTable.js';
3219

3320
describe('DuckDBFormatter', () => {
3421
const language = 'duckdb';
3522
const format: FormatFn = (query, cfg = {}) => originalFormat(query, { ...cfg, language });
3623

37-
behavesLikeSqlFormatter(format);
3824
behavesLikePostgresqlFormatter(format);
39-
supportsComments(format, { nestedBlockComments: true });
40-
supportsCommentOn(format);
4125
supportsCreateView(format, { orReplace: true, ifNotExists: true });
4226
supportsCreateTable(format, { orReplace: true, ifNotExists: true });
4327
supportsDropTable(format, { ifExists: true });
4428
supportsArrayLiterals(format, { withoutArrayPrefix: true });
45-
supportsArrayAndMapAccessors(format);
46-
supportsAlterTable(format, {
47-
addColumn: true,
48-
dropColumn: true,
49-
renameTo: true,
50-
renameColumn: true,
51-
});
52-
supportsDeleteFrom(format);
53-
supportsInsertInto(format);
54-
supportsOnConflict(format);
5529
supportsUpdate(format);
5630
supportsTruncateTable(format, { withTable: false, withoutTable: true });
5731
supportsStrings(format, ["''-qq", "X''", "B''", "E''", '$$']);
5832
supportsIdentifiers(format, [`""-qq`]);
59-
supportsBetween(format);
6033
// Missing: '::' type cast (tested separately)
6134
supportsOperators(
6235
format,
@@ -100,7 +73,6 @@ describe('DuckDBFormatter', () => {
10073
],
10174
{ any: true }
10275
);
103-
supportsIsDistinctFrom(format);
10476
supportsJoin(format, {
10577
additionally: [
10678
'ASOF JOIN',
@@ -125,12 +97,9 @@ describe('DuckDBFormatter', () => {
12597
'INTERSECT',
12698
'INTERSECT ALL',
12799
]);
128-
supportsReturning(format);
129100
// TODO: named params $foo currently conflict with $$-quoted strings
130101
supportsParams(format, { positional: true, numbered: ['$'], quoted: ['$""'] });
131-
supportsWindow(format);
132102
supportsLimiting(format, { limit: true, offset: true });
133-
supportsDataTypeCase(format);
134103

135104
it('formats TIMESTAMP WITH TIME ZONE syntax', () => {
136105
expect(

test/postgresql.test.ts

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,20 @@ import dedent from 'dedent-js';
22

33
import { format as originalFormat, FormatFn } from '../src/sqlFormatter.js';
44

5-
import behavesLikeSqlFormatter from './behavesLikeSqlFormatter.js';
6-
import supportsAlterTable from './features/alterTable.js';
7-
import supportsBetween from './features/between.js';
85
import supportsCreateTable from './features/createTable.js';
96
import supportsDropTable from './features/dropTable.js';
107
import supportsJoin from './features/join.js';
118
import supportsOperators from './features/operators.js';
129
import supportsSchema from './features/schema.js';
1310
import supportsStrings from './features/strings.js';
14-
import supportsReturning from './features/returning.js';
1511
import supportsConstraints from './features/constraints.js';
16-
import supportsDeleteFrom from './features/deleteFrom.js';
17-
import supportsComments from './features/comments.js';
18-
import supportsCommentOn from './features/commentOn.js';
1912
import supportsIdentifiers from './features/identifiers.js';
2013
import supportsParams from './options/param.js';
21-
import supportsArrayAndMapAccessors from './features/arrayAndMapAccessors.js';
22-
import supportsWindow from './features/window.js';
2314
import supportsSetOperations from './features/setOperations.js';
2415
import supportsLimiting from './features/limiting.js';
25-
import supportsInsertInto from './features/insertInto.js';
2616
import supportsUpdate from './features/update.js';
2717
import supportsTruncateTable from './features/truncateTable.js';
2818
import supportsCreateView from './features/createView.js';
29-
import supportsOnConflict from './features/onConflict.js';
3019
import supportsIsDistinctFrom from './features/isDistinctFrom.js';
3120
import supportsArrayLiterals from './features/arrayLiterals.js';
3221
import supportsDataTypeCase from './options/dataTypeCase.js';
@@ -36,30 +25,16 @@ describe('PostgreSqlFormatter', () => {
3625
const language = 'postgresql';
3726
const format: FormatFn = (query, cfg = {}) => originalFormat(query, { ...cfg, language });
3827

39-
behavesLikeSqlFormatter(format);
4028
behavesLikePostgresqlFormatter(format);
41-
supportsComments(format, { nestedBlockComments: true });
42-
supportsCommentOn(format);
4329
supportsCreateView(format, { orReplace: true, materialized: true, ifNotExists: true });
4430
supportsCreateTable(format, { ifNotExists: true });
4531
supportsDropTable(format, { ifExists: true });
4632
supportsConstraints(format, ['NO ACTION', 'RESTRICT', 'CASCADE', 'SET NULL', 'SET DEFAULT']);
4733
supportsArrayLiterals(format, { withArrayPrefix: true });
48-
supportsArrayAndMapAccessors(format);
49-
supportsAlterTable(format, {
50-
addColumn: true,
51-
dropColumn: true,
52-
renameTo: true,
53-
renameColumn: true,
54-
});
55-
supportsDeleteFrom(format);
56-
supportsInsertInto(format);
57-
supportsOnConflict(format);
5834
supportsUpdate(format, { whereCurrentOf: true });
5935
supportsTruncateTable(format, { withoutTable: true });
6036
supportsStrings(format, ["''-qq", "U&''", "X''", "B''", "E''", '$$']);
6137
supportsIdentifiers(format, [`""-qq`, 'U&""']);
62-
supportsBetween(format);
6338
supportsSchema(format);
6439
// Missing: '::' type cast (tested separately)
6540
supportsOperators(
@@ -160,9 +135,7 @@ describe('PostgreSqlFormatter', () => {
160135
supportsIsDistinctFrom(format);
161136
supportsJoin(format);
162137
supportsSetOperations(format);
163-
supportsReturning(format);
164138
supportsParams(format, { numbered: ['$'] });
165-
supportsWindow(format);
166139
supportsLimiting(format, { limit: true, offset: true, fetchFirst: true, fetchNext: true });
167140
supportsDataTypeCase(format);
168141

0 commit comments

Comments
 (0)