branch: externals/sql-indent
commit ea22c4c43062ed519cf666233a6432a4a57e6a2c
Author: Alex Harsanyi <[email protected]>
Commit: Alex Harsanyi <[email protected]>

    Add test cases for sample indentation mode
    
    Based on a sample SQL indentation example provided by the SQL mode 
maintainer.
---
 sql-indent-test.el  |  31 ++++++++++++++
 test-data/m-io.eld  |   1 +
 test-data/m-syn.eld | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 test-data/m.sql     |  48 +++++++++++++++++++++
 4 files changed, 199 insertions(+)

diff --git a/sql-indent-test.el b/sql-indent-test.el
index 48ce7c4..9ba6baa 100644
--- a/sql-indent-test.el
+++ b/sql-indent-test.el
@@ -186,6 +186,30 @@ information read from DATA-FILE (as generated by
 
 ;;..................................................... the actual tests ....
 
+;; See https://gist.github.com/alex-hhh/834a91621680e826a27b2b08463eb12f
+
+(defvar m-indentation-offsets-alist
+  `((select-clause                 0)
+    (insert-clause                 0)
+    (delete-clause                 0)
+    (update-clause                 0)
+    (in-insert-clause              +)
+    (in-select-clause              sqlind-lineup-to-clause-end
+                                   sqlind-lineup-close-paren-to-open)
+    (nested-statement-continuation sqlind-lineup-into-nested-statement
+                                   sqlind-align-comma
+                                   sqlind-lineup-close-paren-to-open)
+    (select-column                 sqlind-indent-select-column
+                                   sqlind-align-comma)
+    (select-column-continuation    sqlind-indent-select-column
+                                   sqlind-lineup-close-paren-to-open)
+    (select-table-continuation     sqlind-indent-select-table
+                                   sqlind-lineup-joins-to-anchor
+                                   sqlind-lineup-open-paren-to-anchor
+                                   sqlind-lineup-close-paren-to-open
+                                   sqlind-align-comma)
+    ,@sqlind-default-indentation-offsets-alist))
+
 (ert-deftest sqlind-ert-pr17 ()
   (sqlind-ert-check-file-syntax "test-data/pr17.sql" "test-data/pr17-syn.eld"))
 
@@ -210,3 +234,10 @@ information read from DATA-FILE (as generated by
 (ert-deftest sqlind-ert-pr7 ()
   (sqlind-ert-check-file-syntax "test-data/pr7.sql" "test-data/pr7-syn.eld"))
 
+(ert-deftest sqlind-ert-m-syn ()
+  (sqlind-ert-check-file-syntax "test-data/m.sql" "test-data/m-syn.eld"))
+
+(ert-deftest sqlind-ert-m-io ()
+  (sqlind-ert-check-file-indentation
+   "test-data/m.sql" "test-data/m-io.eld"
+   m-indentation-offsets-alist 4))
diff --git a/test-data/m-io.eld b/test-data/m-io.eld
new file mode 100644
index 0000000..403dd43
--- /dev/null
+++ b/test-data/m-io.eld
@@ -0,0 +1 @@
+(0 4 4 6 6 4 0 4 4 4 4 4 4 4 10 4 4 4 8 4 4 0 0 10 16 16 16 16 20 20 20 16 12 
16 10 1 5 0 0 0 6 6 2 6 0 4 0 4 0)
diff --git a/test-data/m-syn.eld b/test-data/m-syn.eld
new file mode 100644
index 0000000..472fd34
--- /dev/null
+++ b/test-data/m-syn.eld
@@ -0,0 +1,119 @@
+(((toplevel . 1))
+ (((in-insert-clause "insert into")
+   . 1)
+  (statement-continuation . 1))
+ (((in-insert-clause "insert into")
+   . 1)
+  (statement-continuation . 1))
+ ((nested-statement-continuation . 25)
+  (statement-continuation . 25))
+ ((nested-statement-continuation . 25)
+  (statement-continuation . 25))
+ ((nested-statement-continuation . 25)
+  (statement-continuation . 25))
+ ((insert-clause . 1)
+  (statement-continuation . 1))
+ ((select-column . 80)
+  (statement-continuation . 1))
+ ((select-column . 80)
+  (statement-continuation . 1))
+ ((select-column . 80)
+  (statement-continuation . 1))
+ ((select-column . 80)
+  (statement-continuation . 1))
+ ((select-column . 80)
+  (statement-continuation . 1))
+ ((select-column . 80)
+  (statement-continuation . 1))
+ ((select-column-continuation . 80)
+  (statement-continuation . 1))
+ ((nested-statement-continuation . 242)
+  (statement-continuation . 242))
+ ((nested-statement-continuation . 242)
+  (statement-continuation . 242))
+ ((select-column . 80)
+  (statement-continuation . 1))
+ ((select-column-continuation . 80)
+  (statement-continuation . 1))
+ ((nested-statement-continuation . 327)
+  (statement-continuation . 327))
+ ((nested-statement-continuation . 327)
+  (statement-continuation . 327))
+ ((select-column . 80)
+  (statement-continuation . 1))
+ ((select-clause . 80)
+  (statement-continuation . 1))
+ ((select-table-continuation . 411)
+  (statement-continuation . 1))
+ ((select-table-continuation . 433)
+  (nested-statement-continuation . 423)
+  (statement-continuation . 423))
+ ((select-column . 461)
+  (nested-statement-continuation . 459)
+  (statement-continuation . 459))
+ ((select-column . 461)
+  (nested-statement-continuation . 459)
+  (statement-continuation . 459))
+ ((select-column . 461)
+  (nested-statement-continuation . 459)
+  (statement-continuation . 459))
+ ((select-column-continuation . 461)
+  (nested-statement-continuation . 459)
+  (statement-continuation . 459))
+ ((nested-statement-continuation . 614)
+  (statement-continuation . 614))
+ ((nested-statement-continuation . 614)
+  (statement-continuation . 614))
+ ((nested-statement-continuation . 614)
+  (statement-continuation . 614))
+ ((nested-statement-continuation . 614)
+  (statement-continuation . 614))
+ ((select-clause . 461)
+  (nested-statement-continuation . 459)
+  (statement-continuation . 459))
+ ((select-table-continuation . 795)
+  (nested-statement-continuation . 459)
+  (statement-continuation . 459))
+ ((select-table-continuation . 795)
+  (nested-statement-continuation . 459)
+  (statement-continuation . 459))
+ ((select-clause . 424)
+  (nested-statement-continuation . 423)
+  (statement-continuation . 423))
+ (((in-select-clause "where")
+   . 873)
+  (nested-statement-continuation . 423)
+  (statement-continuation . 423))
+ (((in-select-clause "where")
+   . 873)
+  (nested-statement-continuation . 423)
+  (statement-continuation . 423))
+ ((select-table-continuation . 411)
+  (statement-continuation . 1))
+ ((select-table-continuation . 411)
+  (statement-continuation . 1))
+ ((select-column . 940)
+  (nested-statement-continuation . 938)
+  (statement-continuation . 938))
+ ((select-column . 940)
+  (nested-statement-continuation . 938)
+  (statement-continuation . 938))
+ ((select-clause . 940)
+  (nested-statement-continuation . 938)
+  (statement-continuation . 938))
+ ((select-table-continuation . 1002)
+  (nested-statement-continuation . 938)
+  (statement-continuation . 938))
+ ((select-table-continuation . 1002)
+  (nested-statement-continuation . 938)
+  (statement-continuation . 938))
+ ((select-table-continuation . 411)
+  (statement-continuation . 1))
+ ((select-clause . 80)
+  (statement-continuation . 1))
+ (((in-select-clause "group by")
+   . 1067)
+  (statement-continuation . 1))
+ (((in-select-clause "group by")
+   . 1067)
+  (statement-continuation . 1)))
diff --git a/test-data/m.sql b/test-data/m.sql
new file mode 100644
index 0000000..3990c5f
--- /dev/null
+++ b/test-data/m.sql
@@ -0,0 +1,48 @@
+INSERT INTO 
+  xyzxx 
+  ( aaa, bbb, ccc 
+  , ddd, eee, fff, ggg 
+  , hhh 
+  ) 
+SELECT 
+  aaa 
+  , MAX (m.b1) AS bbb 
+  , MIN (m.b1) AS ccc 
+  , COALESCE (MAX (n.c2), 0)  AS ddd 
+  , COALESCE (MIN (n.c2), 0)  AS eee 
+  , MAX (m.b1) OVER 
+    (     PARTITION BY c2 
+    ORDER BY aaa DESC 
+    ) AS fff 
+  , MIN (m.b1) OVER 
+    (   PARTITION BY c2 
+    ORDER BY aaa DESC 
+    ) AS ggg 
+  , AVG (n.c2)  AS hhh 
+  FROM 
+      (SELECT * FROM 
+                    ( SELECT 
+                        aaa 
+                        , jjj + kkk  AS b1 
+                        , ROW_NUMBER () OVER 
+                          (   PARTITION BY qqq 
+                          ORDER BY 
+                          rrr 
+                          , sss 
+                          ) AS rn 
+                        FROM 
+                            mno 
+                            ) 
+        WHERE 
+          rn = 1 
+          )  m 
+      INNER JOIN 
+      ( SELECT 
+          aaa 
+          , nnn + ooo AS c2 
+          FROM 
+              pqr 
+              ) n 
+      USING (aaa), 
+ GROUP BY 
+   aaa 

Reply via email to