summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAdam Greenhall <agreenhall@lyft.com>2015-09-12 14:49:47 -0700
committerVictor Uriarte <victor.m.uriarte@intel.com>2016-06-06 06:31:35 -0700
commit2928a7c8f1192b8376795368825c2cf2dae243c3 (patch)
tree00e1eb738b20012ed671e0e36ee27c99f619ee14 /tests
parent4c70aeaa2a8b1652553cc5a10bd593694cb3073f (diff)
downloadsqlparse-2928a7c8f1192b8376795368825c2cf2dae243c3.tar.gz
Add filter `Spaces around Operators`
Diffstat (limited to 'tests')
-rw-r--r--tests/test_format.py34
-rw-r--r--tests/test_grouping.py4
2 files changed, 38 insertions, 0 deletions
diff --git a/tests/test_format.py b/tests/test_format.py
index 8151bb4..22ab5b6 100644
--- a/tests/test_format.py
+++ b/tests/test_format.py
@@ -294,6 +294,40 @@ class TestFormatReindentAligned(TestCaseBase):
]))
+class TestSpacesAroundOperators(TestCaseBase):
+ @staticmethod
+ def formatter(sql):
+ return sqlparse.format(sql, use_space_around_operators=True)
+
+ def test_basic(self):
+ sql = 'select a+b as d from table where (c-d)%2= 1 and e> 3.0/4 and z^2 <100'
+ self.ndiffAssertEqual(
+ self.formatter(sql),
+ 'select a + b as d from table where (c - d) % 2 = 1 and e > 3.0 / 4 and z ^ 2 < 100'
+ )
+
+ def test_bools(self):
+ sql = 'select * from table where a &&b or c||d'
+ self.ndiffAssertEqual(
+ self.formatter(sql),
+ 'select * from table where a && b or c || d'
+ )
+
+ def test_nested(self):
+ sql = 'select *, case when a-b then c end from table'
+ self.ndiffAssertEqual(
+ self.formatter(sql),
+ 'select *, case when a - b then c end from table'
+ )
+
+ def test_wildcard_vs_mult(self):
+ sql = 'select a*b-c from table'
+ self.ndiffAssertEqual(
+ self.formatter(sql),
+ 'select a * b - c from table'
+ )
+
+
class TestFormatReindent(TestCaseBase):
def test_option(self):
diff --git a/tests/test_grouping.py b/tests/test_grouping.py
index 1971fb7..40a35cf 100644
--- a/tests/test_grouping.py
+++ b/tests/test_grouping.py
@@ -150,6 +150,10 @@ class TestGrouping(TestCaseBase):
self.assert_(isinstance(p.tokens[0].tokens[0], sql.Identifier))
self.assert_(isinstance(p.tokens[0].tokens[3], sql.Identifier))
+ def test_identifiers_with_operators(self):
+ p = sqlparse.parse('a+b as c from table where (d-e)%2= 1')[0]
+ self.assertEqual(len([x for x in p.flatten() if x.ttype == sqlparse.tokens.Name]), 5)
+
def test_identifier_list_with_order(self): # issue101
p = sqlparse.parse('1, 2 desc, 3')[0]
self.assert_(isinstance(p.tokens[0], sql.IdentifierList))