summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test_parse.py7
-rw-r--r--tests/test_regressions.py28
2 files changed, 35 insertions, 0 deletions
diff --git a/tests/test_parse.py b/tests/test_parse.py
index e14c9e2..05141a4 100644
--- a/tests/test_parse.py
+++ b/tests/test_parse.py
@@ -106,3 +106,10 @@ class SQLParseTest(TestCaseBase):
t = sqlparse.parse('foo.key')[0].tokens
self.assertEqual(len(t), 1)
self.assert_(isinstance(t[0], sqlparse.sql.Identifier))
+
+
+def test_quoted_identifier():
+ t = sqlparse.parse('select x.y as "z" from foo')[0].tokens
+ assert isinstance(t[2], sqlparse.sql.Identifier)
+ assert t[2].get_name() == 'z'
+ assert t[2].get_real_name() == 'y'
diff --git a/tests/test_regressions.py b/tests/test_regressions.py
index 86b6292..e1c2c89 100644
--- a/tests/test_regressions.py
+++ b/tests/test_regressions.py
@@ -106,3 +106,31 @@ class RegressionTests(TestCaseBase):
' (SELECT id,\n'
' name\n'
' FROM bar) as foo'))
+
+
+def test_issue78():
+ # the bug author provided this nice examples, let's use them!
+ def _get_identifier(sql):
+ p = sqlparse.parse(sql)[0]
+ return p.tokens[2]
+ results = (('get_name', 'z'),
+ ('get_real_name', 'y'),
+ ('get_parent_name', 'x'),
+ ('get_alias', 'z'),
+ ('get_typecast', 'text'))
+ variants = (
+ 'select x.y::text as z from foo',
+ 'select x.y::text as "z" from foo',
+ 'select x."y"::text as z from foo',
+ 'select x."y"::text as "z" from foo',
+ 'select "x".y::text as z from foo',
+ 'select "x".y::text as "z" from foo',
+ 'select "x"."y"::text as z from foo',
+ 'select "x"."y"::text as "z" from foo',
+ )
+ for variant in variants:
+ i = _get_identifier(variant)
+ assert isinstance(i, sql.Identifier)
+ for func_name, result in results:
+ func = getattr(i, func_name)
+ assert func() == result