summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test_format.py11
-rw-r--r--tests/test_grouping.py11
2 files changed, 22 insertions, 0 deletions
diff --git a/tests/test_format.py b/tests/test_format.py
index c33ac93..17bdc17 100644
--- a/tests/test_format.py
+++ b/tests/test_format.py
@@ -267,3 +267,14 @@ class TestOutputFormat(TestCaseBase):
sql = 'select * from foo;'
f = lambda sql: sqlparse.format(sql, output_format='sql')
self.ndiffAssertEqual(f(sql), 'select * from foo;')
+
+
+def test_format_column_ordering(): # issue89
+ sql = 'select * from foo order by c1 desc, c2, c3;'
+ formatted = sqlparse.format(sql, reindent=True)
+ expected = '\n'.join(['select *',
+ 'from foo',
+ 'order by c1 desc,',
+ ' c2,',
+ ' c3;'])
+ assert formatted == expected
diff --git a/tests/test_grouping.py b/tests/test_grouping.py
index 345e62f..674982f 100644
--- a/tests/test_grouping.py
+++ b/tests/test_grouping.py
@@ -231,3 +231,14 @@ def test_identifier_string_concat():
p = sqlparse.parse('\'foo\' || bar')[0]
assert len(p.tokens) == 1
assert isinstance(p.tokens[0], sql.Identifier)
+
+
+def test_identifier_consumes_ordering(): # issue89
+ p = sqlparse.parse('select * from foo order by c1 desc, c2, c3')[0]
+ assert isinstance(p.tokens[-1], sql.IdentifierList)
+ ids = list(p.tokens[-1].get_identifiers())
+ assert len(ids) == 3
+ assert ids[0].get_name() == 'c1'
+ assert ids[0].get_ordering() == 'DESC'
+ assert ids[1].get_name() == 'c2'
+ assert ids[1].get_ordering() is None