@@ -169,3 +169,216 @@ string' AS str
169169 "A literal string with a newline should be kept as is. The contents of the string should not be indented."
170170 ) ;
171171}
172+
173+ #[ test]
174+ #[ ignore = "https://github.com/apache/datafusion-sqlparser-rs/issues/1850" ]
175+ fn test_pretty_print_insert_values ( ) {
176+ assert_eq ! (
177+ prettify( "INSERT INTO my_table (a, b, c) VALUES (1, 2, 3), (4, 5, 6)" ) ,
178+ r#"
179+ INSERT INTO my_table (a, b, c)
180+ VALUES
181+ (1, 2, 3),
182+ (4, 5, 6)
183+ "#
184+ . trim( )
185+ ) ;
186+ }
187+
188+ #[ test]
189+ #[ ignore = "https://github.com/apache/datafusion-sqlparser-rs/issues/1850" ]
190+ fn test_pretty_print_insert_select ( ) {
191+ assert_eq ! (
192+ prettify( "INSERT INTO my_table (a, b) SELECT x, y FROM source_table" ) ,
193+ r#"
194+ INSERT INTO my_table (a, b)
195+ SELECT
196+ x,
197+ y
198+ FROM
199+ source_table
200+ "#
201+ . trim( )
202+ ) ;
203+ }
204+
205+ #[ test]
206+ #[ ignore = "https://github.com/apache/datafusion-sqlparser-rs/issues/1850" ]
207+ fn test_pretty_print_update ( ) {
208+ assert_eq ! (
209+ prettify( "UPDATE my_table SET a = 1, b = 2 WHERE x > 0" ) ,
210+ r#"
211+ UPDATE my_table
212+ SET
213+ a = 1,
214+ b = 2
215+ WHERE
216+ x > 0
217+ "#
218+ . trim( )
219+ ) ;
220+ }
221+
222+ #[ test]
223+ #[ ignore = "https://github.com/apache/datafusion-sqlparser-rs/issues/1850" ]
224+ fn test_pretty_print_delete ( ) {
225+ assert_eq ! (
226+ prettify( "DELETE FROM my_table WHERE x > 0" ) ,
227+ r#"
228+ DELETE FROM my_table
229+ WHERE
230+ x > 0
231+ "#
232+ . trim( )
233+ ) ;
234+ }
235+
236+ #[ test]
237+ #[ ignore = "https://github.com/apache/datafusion-sqlparser-rs/issues/1850" ]
238+ fn test_pretty_print_create_table ( ) {
239+ assert_eq ! (
240+ prettify( "CREATE TABLE my_table (id INT PRIMARY KEY, name VARCHAR(255) NOT NULL, CONSTRAINT fk_other FOREIGN KEY (id) REFERENCES other_table(id))" ) ,
241+ r#"
242+ CREATE TABLE my_table (
243+ id INT PRIMARY KEY,
244+ name VARCHAR(255) NOT NULL,
245+ CONSTRAINT fk_other FOREIGN KEY (id) REFERENCES other_table(id)
246+ )
247+ "#
248+ . trim( )
249+ ) ;
250+ }
251+
252+ #[ test]
253+ #[ ignore = "https://github.com/apache/datafusion-sqlparser-rs/issues/1850" ]
254+ fn test_pretty_print_create_view ( ) {
255+ assert_eq ! (
256+ prettify( "CREATE VIEW my_view AS SELECT a, b FROM my_table WHERE x > 0" ) ,
257+ r#"
258+ CREATE VIEW my_view AS
259+ SELECT
260+ a,
261+ b
262+ FROM
263+ my_table
264+ WHERE
265+ x > 0
266+ "#
267+ . trim( )
268+ ) ;
269+ }
270+
271+ #[ test]
272+ #[ ignore = "https://github.com/apache/datafusion-sqlparser-rs/issues/1850" ]
273+ fn test_pretty_print_create_function ( ) {
274+ assert_eq ! (
275+ prettify( "CREATE FUNCTION my_func() RETURNS INT BEGIN SELECT COUNT(*) INTO @count FROM my_table; RETURN @count; END" ) ,
276+ r#"
277+ CREATE FUNCTION my_func() RETURNS INT
278+ BEGIN
279+ SELECT COUNT(*) INTO @count FROM my_table;
280+ RETURN @count;
281+ END
282+ "#
283+ . trim( )
284+ ) ;
285+ }
286+
287+ #[ test]
288+ #[ ignore = "https://github.com/apache/datafusion-sqlparser-rs/issues/1850" ]
289+ fn test_pretty_print_json_table ( ) {
290+ assert_eq ! (
291+ prettify( "SELECT * FROM JSON_TABLE(@json, '$[*]' COLUMNS (id INT PATH '$.id', name VARCHAR(255) PATH '$.name')) AS jt" ) ,
292+ r#"
293+ SELECT
294+ *
295+ FROM
296+ JSON_TABLE(
297+ @json,
298+ '$[*]' COLUMNS (
299+ id INT PATH '$.id',
300+ name VARCHAR(255) PATH '$.name'
301+ )
302+ ) AS jt
303+ "#
304+ . trim( )
305+ ) ;
306+ }
307+
308+ #[ test]
309+ #[ ignore = "https://github.com/apache/datafusion-sqlparser-rs/issues/1850" ]
310+ fn test_pretty_print_transaction_blocks ( ) {
311+ assert_eq ! (
312+ prettify( "BEGIN; UPDATE my_table SET x = 1; COMMIT;" ) ,
313+ r#"
314+ BEGIN;
315+ UPDATE my_table SET x = 1;
316+ COMMIT;
317+ "#
318+ . trim( )
319+ ) ;
320+ }
321+
322+ #[ test]
323+ #[ ignore = "https://github.com/apache/datafusion-sqlparser-rs/issues/1850" ]
324+ fn test_pretty_print_control_flow ( ) {
325+ assert_eq ! (
326+ prettify( "IF x > 0 THEN SELECT 'positive'; ELSE SELECT 'negative'; END IF;" ) ,
327+ r#"
328+ IF x > 0 THEN
329+ SELECT 'positive';
330+ ELSE
331+ SELECT 'negative';
332+ END IF;
333+ "#
334+ . trim( )
335+ ) ;
336+ }
337+
338+ #[ test]
339+ #[ ignore = "https://github.com/apache/datafusion-sqlparser-rs/issues/1850" ]
340+ fn test_pretty_print_merge ( ) {
341+ assert_eq ! (
342+ prettify( "MERGE INTO target_table t USING source_table s ON t.id = s.id WHEN MATCHED THEN UPDATE SET t.value = s.value WHEN NOT MATCHED THEN INSERT (id, value) VALUES (s.id, s.value)" ) ,
343+ r#"
344+ MERGE INTO target_table t
345+ USING source_table s ON t.id = s.id
346+ WHEN MATCHED THEN
347+ UPDATE SET t.value = s.value
348+ WHEN NOT MATCHED THEN
349+ INSERT (id, value) VALUES (s.id, s.value)
350+ "#
351+ . trim( )
352+ ) ;
353+ }
354+
355+ #[ test]
356+ #[ ignore = "https://github.com/apache/datafusion-sqlparser-rs/issues/1850" ]
357+ fn test_pretty_print_create_index ( ) {
358+ assert_eq ! (
359+ prettify( "CREATE INDEX idx_name ON my_table (column1, column2)" ) ,
360+ r#"
361+ CREATE INDEX idx_name
362+ ON my_table (column1, column2)
363+ "#
364+ . trim( )
365+ ) ;
366+ }
367+
368+ #[ test]
369+ #[ ignore = "https://github.com/apache/datafusion-sqlparser-rs/issues/1850" ]
370+ fn test_pretty_print_explain ( ) {
371+ assert_eq ! (
372+ prettify( "EXPLAIN ANALYZE SELECT * FROM my_table WHERE x > 0" ) ,
373+ r#"
374+ EXPLAIN ANALYZE
375+ SELECT
376+ *
377+ FROM
378+ my_table
379+ WHERE
380+ x > 0
381+ "#
382+ . trim( )
383+ ) ;
384+ }
0 commit comments