|
| 1 | +package com.trivadis.plsql.formatter.settings.tests.issues; |
| 2 | + |
| 3 | +import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; |
| 4 | +import org.junit.jupiter.api.Test; |
| 5 | +import org.junit.jupiter.api.TestInstance; |
| 6 | + |
| 7 | +@TestInstance(TestInstance.Lifecycle.PER_CLASS) |
| 8 | +public class Issue_265_wrong_indent_in_insert extends ConfiguredTestFormatter { |
| 9 | + @Test |
| 10 | + public void insert_from_subquery() { |
| 11 | + var input = """ |
| 12 | + insert into t1 |
| 13 | + select object_type, count(*) |
| 14 | + from ( |
| 15 | + select 'table' as object_type, table_name as object_name |
| 16 | + from user_tables |
| 17 | + union all |
| 18 | + select 'view', view_name |
| 19 | + from user_views |
| 20 | + union all |
| 21 | + select 'sequence', sequence_name |
| 22 | + from user_sequences |
| 23 | + ) |
| 24 | + group by object_type; |
| 25 | + """; |
| 26 | + formatAndAssert(input); |
| 27 | + } |
| 28 | + |
| 29 | + @Test |
| 30 | + public void insert_from_with_clause() { |
| 31 | + var input = """ |
| 32 | + insert into t2 |
| 33 | + with |
| 34 | + objects as ( |
| 35 | + select 'table' as object_type, table_name as object_name |
| 36 | + from user_tables |
| 37 | + union all |
| 38 | + select 'view', view_name |
| 39 | + from user_views |
| 40 | + union all |
| 41 | + select 'sequence', sequence_name |
| 42 | + from user_sequences |
| 43 | + ) |
| 44 | + select object_type, count(*) |
| 45 | + from objects |
| 46 | + group by object_type; |
| 47 | + / |
| 48 | + """; |
| 49 | + formatAndAssert(input); |
| 50 | + } |
| 51 | + |
| 52 | + @Test |
| 53 | + public void insert_from_with_clause_with_subquery() { |
| 54 | + var input = """ |
| 55 | + insert into t3 |
| 56 | + with |
| 57 | + combined as ( |
| 58 | + select object_type, count(*) |
| 59 | + from ( |
| 60 | + select 'table' as object_type, table_name as object_name |
| 61 | + from user_tables |
| 62 | + union all |
| 63 | + select 'view', view_name |
| 64 | + from user_views |
| 65 | + union all |
| 66 | + select 'sequence', sequence_name |
| 67 | + from user_sequences |
| 68 | + ) |
| 69 | + group by object_type |
| 70 | + ) |
| 71 | + select * |
| 72 | + from combined; |
| 73 | + / |
| 74 | + """; |
| 75 | + formatAndAssert(input); |
| 76 | + } |
| 77 | + |
| 78 | +} |
0 commit comments