summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAndi Albrecht <albrecht.andi@gmail.com>2012-11-03 13:05:25 +0100
committerAndi Albrecht <albrecht.andi@gmail.com>2012-11-03 13:05:25 +0100
commit39ddba76709cc36dda0e9519efe7316d5ff5f12f (patch)
tree93a62f9a1626077ba4c558e442a67be7e7ea39e2 /tests
parent813782f5f842023c5dcc9658f27f957ca83955eb (diff)
downloadsqlparse-39ddba76709cc36dda0e9519efe7316d5ff5f12f.tar.gz
Improve handling of quoted indentifiers (fixes issue78).
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