diff options
author | Darik Gamble <darik.gamble@gmail.com> | 2015-02-09 12:17:22 -0500 |
---|---|---|
committer | Darik Gamble <darik.gamble@gmail.com> | 2015-02-09 12:59:37 -0500 |
commit | 6f134c67b6c89c2985e29bd5bc4c809cc16c06a5 (patch) | |
tree | e5c90fcc384d9e5041fe68de4ee98ee0b995526c | |
parent | 2f5e0b7476381f5fda9e240d6e0e4f9c35261211 (diff) | |
download | sqlparse-6f134c67b6c89c2985e29bd5bc4c809cc16c06a5.tar.gz |
Add a bunch of extra tests for assigning aliases without the AS keyword
-rw-r--r-- | tests/test_grouping.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/test_grouping.py b/tests/test_grouping.py index 33f44ae..c598258 100644 --- a/tests/test_grouping.py +++ b/tests/test_grouping.py @@ -346,3 +346,43 @@ def test_nested_begin(): assert inner.tokens[0].value == 'BEGIN' assert inner.tokens[-1].value == 'END' assert isinstance(inner, sql.Begin) + + +def test_aliased_column_without_as(): + p = sqlparse.parse('foo bar')[0].tokens + assert len(p) == 1 + assert p[0].get_real_name() == 'foo' + assert p[0].get_alias() == 'bar' + + p = sqlparse.parse('foo.bar baz')[0].tokens[0] + assert p.get_parent_name() == 'foo' + assert p.get_real_name() == 'bar' + assert p.get_alias() == 'baz' + + +def test_qualified_function(): + p = sqlparse.parse('foo()')[0].tokens[0] + assert p.get_parent_name() is None + assert p.get_real_name() == 'foo' + + p = sqlparse.parse('foo.bar()')[0].tokens[0] + assert p.get_parent_name() == 'foo' + assert p.get_real_name() == 'bar' + + +def test_aliased_function_without_as(): + p = sqlparse.parse('foo() bar')[0].tokens[0] + assert p.get_parent_name() is None + assert p.get_real_name() == 'foo' + assert p.get_alias() == 'bar' + + p = sqlparse.parse('foo.bar() baz')[0].tokens[0] + assert p.get_parent_name() == 'foo' + assert p.get_real_name() == 'bar' + assert p.get_alias() == 'baz' + + +def test_aliased_literal_without_as(): + p = sqlparse.parse('1 foo')[0].tokens + assert len(p) == 1 + assert p[0].get_alias() == 'foo'
\ No newline at end of file |