summaryrefslogtreecommitdiffstats
path: root/tests/test_transpile.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-08-14 10:12:13 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-08-14 10:12:13 +0000
commitcdffd0b29d5b072639bb02118d6828f4d1b76099 (patch)
tree57ec0b75c40e40a33060b63599bbba6f0af27ae8 /tests/test_transpile.py
parentAdding upstream version 17.11.0. (diff)
downloadsqlglot-upstream/17.12.0.tar.xz
sqlglot-upstream/17.12.0.zip
Adding upstream version 17.12.0.upstream/17.12.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--tests/test_transpile.py56
1 files changed, 55 insertions, 1 deletions
diff --git a/tests/test_transpile.py b/tests/test_transpile.py
index 3f284c9..e58ed86 100644
--- a/tests/test_transpile.py
+++ b/tests/test_transpile.py
@@ -90,6 +90,19 @@ class TestTranspile(unittest.TestCase):
self.validate("SELECT 3>=3", "SELECT 3 >= 3")
def test_comments(self):
+ self.validate("SELECT\n foo\n/* comments */\n;", "SELECT foo /* comments */")
+ self.validate(
+ "SELECT * FROM a INNER /* comments */ JOIN b",
+ "SELECT * FROM a /* comments */ INNER JOIN b",
+ )
+ self.validate(
+ "SELECT * FROM a LEFT /* comment 1 */ OUTER /* comment 2 */ JOIN b",
+ "SELECT * FROM a /* comment 1 */ /* comment 2 */ LEFT OUTER JOIN b",
+ )
+ self.validate(
+ "SELECT CASE /* test */ WHEN a THEN b ELSE c END",
+ "SELECT CASE WHEN a THEN b ELSE c END /* test */",
+ )
self.validate("SELECT 1 /*/2 */", "SELECT 1 /* /2 */")
self.validate("SELECT */*comment*/", "SELECT * /* comment */")
self.validate(
@@ -308,6 +321,7 @@ DROP TABLE IF EXISTS db.tba""",
)
self.validate(
"""
+ -- comment4
CREATE TABLE db.tba AS
SELECT a, b, c
FROM tb_01
@@ -316,8 +330,10 @@ DROP TABLE IF EXISTS db.tba""",
a = 1 AND b = 2 --comment6
-- and c = 1
-- comment7
+ ;
""",
- """CREATE TABLE db.tba AS
+ """/* comment4 */
+CREATE TABLE db.tba AS
SELECT
a,
b,
@@ -329,6 +345,44 @@ WHERE
/* comment7 */""",
pretty=True,
)
+ self.validate(
+ """
+ SELECT
+ -- This is testing comments
+ col,
+ -- 2nd testing comments
+ CASE WHEN a THEN b ELSE c END as d
+ FROM t
+ """,
+ """SELECT
+ col, /* This is testing comments */
+ CASE WHEN a THEN b ELSE c END /* 2nd testing comments */ AS d
+FROM t""",
+ pretty=True,
+ )
+ self.validate(
+ """
+ SELECT * FROM a
+ -- comments
+ INNER JOIN b
+ """,
+ """SELECT
+ *
+FROM a
+/* comments */
+INNER JOIN b""",
+ pretty=True,
+ )
+ self.validate(
+ "SELECT * FROM a LEFT /* comment 1 */ OUTER /* comment 2 */ JOIN b",
+ """SELECT
+ *
+FROM a
+/* comment 1 */
+/* comment 2 */
+LEFT OUTER JOIN b""",
+ pretty=True,
+ )
def test_types(self):
self.validate("INT 1", "CAST(1 AS INT)")