summaryrefslogtreecommitdiffstats
path: root/tests/test_transpile.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_transpile.py')
-rw-r--r--tests/test_transpile.py65
1 files changed, 59 insertions, 6 deletions
diff --git a/tests/test_transpile.py b/tests/test_transpile.py
index 01b8205..942053e 100644
--- a/tests/test_transpile.py
+++ b/tests/test_transpile.py
@@ -49,6 +49,12 @@ class TestTranspile(unittest.TestCase):
leading_comma=True,
pretty=True,
)
+ self.validate(
+ "SELECT FOO, /*x*/\nBAR, /*y*/\nBAZ",
+ "SELECT\n FOO -- x\n , BAR -- y\n , BAZ",
+ leading_comma=True,
+ pretty=True,
+ )
# without pretty, this should be a no-op
self.validate(
"SELECT FOO, BAR, BAZ",
@@ -63,24 +69,61 @@ class TestTranspile(unittest.TestCase):
self.validate("SELECT 3>=3", "SELECT 3 >= 3")
def test_comments(self):
- self.validate("SELECT 1 FROM foo -- comment", "SELECT 1 FROM foo")
- self.validate("SELECT 1 /* inline */ FROM foo -- comment", "SELECT 1 FROM foo")
-
+ self.validate("SELECT 1 FROM foo -- comment", "SELECT 1 FROM foo /* comment */")
+ self.validate("SELECT --+5\nx FROM foo", "/* +5 */ SELECT x FROM foo")
+ self.validate("SELECT --!5\nx FROM foo", "/* !5 */ SELECT x FROM foo")
+ self.validate(
+ "SELECT 1 /* inline */ FROM foo -- comment",
+ "SELECT 1 /* inline */ FROM foo /* comment */",
+ )
+ self.validate(
+ "SELECT FUN(x) /*x*/, [1,2,3] /*y*/", "SELECT FUN(x) /* x */, ARRAY(1, 2, 3) /* y */"
+ )
self.validate(
"""
SELECT 1 -- comment
FROM foo -- comment
""",
- "SELECT 1 FROM foo",
+ "SELECT 1 /* comment */ FROM foo /* comment */",
)
-
self.validate(
"""
SELECT 1 /* big comment
like this */
FROM foo -- comment
""",
- "SELECT 1 FROM foo",
+ """SELECT 1 /* big comment
+ like this */ FROM foo /* comment */""",
+ )
+ self.validate(
+ "select x from foo -- x",
+ "SELECT x FROM foo /* x */",
+ )
+ self.validate(
+ """
+ /* multi
+ line
+ comment
+ */
+ SELECT
+ tbl.cola /* comment 1 */ + tbl.colb /* comment 2 */,
+ CAST(x AS INT), # comment 3
+ y -- comment 4
+ FROM
+ bar /* comment 5 */,
+ tbl # comment 6
+ """,
+ """/* multi
+ line
+ comment
+ */
+SELECT
+ tbl.cola /* comment 1 */ + tbl.colb /* comment 2 */,
+ CAST(x AS INT), -- comment 3
+ y -- comment 4
+FROM bar /* comment 5 */, tbl /* comment 6 */""",
+ read="mysql",
+ pretty=True,
)
def test_types(self):
@@ -146,6 +189,16 @@ class TestTranspile(unittest.TestCase):
def test_ignore_nulls(self):
self.validate("SELECT COUNT(x RESPECT NULLS)", "SELECT COUNT(x)")
+ def test_with(self):
+ self.validate(
+ "WITH a AS (SELECT 1) WITH b AS (SELECT 2) SELECT *",
+ "WITH a AS (SELECT 1), b AS (SELECT 2) SELECT *",
+ )
+ self.validate(
+ "WITH a AS (SELECT 1), WITH b AS (SELECT 2) SELECT *",
+ "WITH a AS (SELECT 1), b AS (SELECT 2) SELECT *",
+ )
+
def test_time(self):
self.validate("TIMESTAMP '2020-01-01'", "CAST('2020-01-01' AS TIMESTAMP)")
self.validate("TIMESTAMP WITH TIME ZONE '2020-01-01'", "CAST('2020-01-01' AS TIMESTAMPTZ)")