@@ -3,6 +3,7 @@ import dedent from 'dedent-js';
3
3
import { format as originalFormat , FormatFn } from '../src/sqlFormatter.js' ;
4
4
5
5
import behavesLikeSqlFormatter from './behavesLikeSqlFormatter.js' ;
6
+ import behavesLikePostgresqlFormatter from './behavesLikePostgresqlFormatter.js' ;
6
7
import supportsAlterTable from './features/alterTable.js' ;
7
8
import supportsBetween from './features/between.js' ;
8
9
import supportsCreateTable from './features/createTable.js' ;
@@ -34,6 +35,7 @@ describe('DuckDBFormatter', () => {
34
35
const format : FormatFn = ( query , cfg = { } ) => originalFormat ( query , { ...cfg , language } ) ;
35
36
36
37
behavesLikeSqlFormatter ( format ) ;
38
+ behavesLikePostgresqlFormatter ( format ) ;
37
39
supportsComments ( format , { nestedBlockComments : true } ) ;
38
40
supportsCommentOn ( format ) ;
39
41
supportsCreateView ( format , { orReplace : true , ifNotExists : true } ) ;
@@ -130,33 +132,6 @@ describe('DuckDBFormatter', () => {
130
132
supportsLimiting ( format , { limit : true , offset : true } ) ;
131
133
supportsDataTypeCase ( format ) ;
132
134
133
- it ( 'allows $ character as part of identifiers' , ( ) => {
134
- expect ( format ( 'SELECT foo$, some$$ident' ) ) . toBe ( dedent `
135
- SELECT
136
- foo$,
137
- some$$ident
138
- ` ) ;
139
- } ) ;
140
-
141
- it ( 'formats type-cast operator without spaces' , ( ) => {
142
- expect ( format ( 'SELECT 2 :: numeric AS foo;' ) ) . toBe ( dedent `
143
- SELECT
144
- 2::numeric AS foo;
145
- ` ) ;
146
- } ) ;
147
-
148
- // issue #144 (unsolved)
149
- // This is currently far from ideal.
150
- it ( 'formats SELECT DISTINCT ON () syntax' , ( ) => {
151
- expect ( format ( 'SELECT DISTINCT ON (c1, c2) c1, c2 FROM tbl;' ) ) . toBe ( dedent `
152
- SELECT DISTINCT
153
- ON (c1, c2) c1,
154
- c2
155
- FROM
156
- tbl;
157
- ` ) ;
158
- } ) ;
159
-
160
135
it ( 'formats TIMESTAMP WITH TIME ZONE syntax' , ( ) => {
161
136
expect (
162
137
format ( `
@@ -170,112 +145,6 @@ describe('DuckDBFormatter', () => {
170
145
` ) ;
171
146
} ) ;
172
147
173
- // Regression test for issue #624
174
- it ( 'supports array slice operator' , ( ) => {
175
- expect ( format ( 'SELECT foo[:5], bar[1:], baz[1:5], zap[:];' ) ) . toBe ( dedent `
176
- SELECT
177
- foo[:5],
178
- bar[1:],
179
- baz[1:5],
180
- zap[:];
181
- ` ) ;
182
- } ) ;
183
-
184
- it ( 'formats ALTER TABLE ... ALTER COLUMN' , ( ) => {
185
- expect (
186
- format (
187
- `ALTER TABLE t ALTER COLUMN foo SET DATA TYPE VARCHAR;
188
- ALTER TABLE t ALTER COLUMN foo SET DEFAULT 5;
189
- ALTER TABLE t ALTER COLUMN foo DROP DEFAULT;
190
- ALTER TABLE t ALTER COLUMN foo SET NOT NULL;
191
- ALTER TABLE t ALTER COLUMN foo DROP NOT NULL;`
192
- )
193
- ) . toBe ( dedent `
194
- ALTER TABLE t
195
- ALTER COLUMN foo
196
- SET DATA TYPE VARCHAR;
197
-
198
- ALTER TABLE t
199
- ALTER COLUMN foo
200
- SET DEFAULT 5;
201
-
202
- ALTER TABLE t
203
- ALTER COLUMN foo
204
- DROP DEFAULT;
205
-
206
- ALTER TABLE t
207
- ALTER COLUMN foo
208
- SET NOT NULL;
209
-
210
- ALTER TABLE t
211
- ALTER COLUMN foo
212
- DROP NOT NULL;
213
- ` ) ;
214
- } ) ;
215
-
216
- // Issue #685
217
- it ( 'allows TYPE to be used as an identifier' , ( ) => {
218
- expect ( format ( `SELECT type, modified_at FROM items;` ) ) . toBe ( dedent `
219
- SELECT
220
- type,
221
- modified_at
222
- FROM
223
- items;
224
- ` ) ;
225
- } ) ;
226
-
227
- // Issue #156, #709
228
- it ( 'does not recognize common fields names as keywords' , ( ) => {
229
- expect (
230
- format ( `SELECT id, type, name, location, label, password FROM release;` , {
231
- keywordCase : 'upper' ,
232
- } )
233
- ) . toBe ( dedent `
234
- SELECT
235
- id,
236
- type,
237
- name,
238
- location,
239
- label,
240
- password
241
- FROM
242
- release;
243
- ` ) ;
244
- } ) ;
245
-
246
- it ( 'formats DEFAULT VALUES clause' , ( ) => {
247
- expect (
248
- format ( `INSERT INTO items default values RETURNING id;` , {
249
- keywordCase : 'upper' ,
250
- } )
251
- ) . toBe ( dedent `
252
- INSERT INTO
253
- items
254
- DEFAULT VALUES
255
- RETURNING
256
- id;
257
- ` ) ;
258
- } ) ;
259
-
260
- // Issue #726
261
- it ( 'treats TEXT as data-type (not as plain keyword)' , ( ) => {
262
- expect (
263
- format ( `CREATE TABLE foo (items text);` , {
264
- dataTypeCase : 'upper' ,
265
- } )
266
- ) . toBe ( dedent `
267
- CREATE TABLE foo (items TEXT);
268
- ` ) ;
269
-
270
- expect (
271
- format ( `CREATE TABLE foo (text VARCHAR(100));` , {
272
- keywordCase : 'upper' ,
273
- } )
274
- ) . toBe ( dedent `
275
- CREATE TABLE foo (text VARCHAR(100));
276
- ` ) ;
277
- } ) ;
278
-
279
148
it ( 'formats JSON data type' , ( ) => {
280
149
expect (
281
150
format ( `CREATE TABLE foo (bar json, baz json);` , {
0 commit comments