summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndi Albrecht <albrecht.andi@gmail.com>2009-05-05 06:48:11 +0200
committerAndi Albrecht <albrecht.andi@gmail.com>2009-05-05 06:48:11 +0200
commitc8c23529249f4554f61b79121e78ff5192dc3bbe (patch)
tree2c801fe3566e2b074e7b5a4ea8aaaa2c2ce0af0b
parente9d921676a44b93d7d92978f8008cfdd9c5ca8b9 (diff)
downloadsqlparse-c8c23529249f4554f61b79121e78ff5192dc3bbe.tar.gz
Improved check for duplicated newlines (targets issue3).
-rw-r--r--sqlparse/filters.py7
-rw-r--r--tests/test_format.py5
2 files changed, 10 insertions, 2 deletions
diff --git a/sqlparse/filters.py b/sqlparse/filters.py
index 91258ff..f1163ca 100644
--- a/sqlparse/filters.py
+++ b/sqlparse/filters.py
@@ -4,6 +4,7 @@ import re
from sqlparse.engine import grouping
from sqlparse import tokens as T
+from sqlparse import sql
class Filter(object):
@@ -171,8 +172,10 @@ class ReindentFilter(Filter):
if prev and prev.is_whitespace():
tlist.tokens.pop(tlist.token_index(prev))
offset += 1
- if prev and (str(prev).endswith('\n')
- or str(prev).endswith('\r')):
+ if (prev
+ and isinstance(prev, sql.Comment)
+ and (str(prev).endswith('\n')
+ or str(prev).endswith('\r'))):
nl = tlist.token_next(token)
else:
nl = self.nl()
diff --git a/tests/test_format.py b/tests/test_format.py
index 9b296a3..7cfb7fe 100644
--- a/tests/test_format.py
+++ b/tests/test_format.py
@@ -169,5 +169,10 @@ class TestFormatReindent(TestCaseBase):
self.ndiffAssertEqual(f(s), '\n'.join(['select c1',
'from foo',
'order by c1']))
+ s = 'select c1 from t1 where (c1 = 1) order by c1'
+ self.ndiffAssertEqual(f(s), '\n'.join(['select c1',
+ 'from t1',
+ 'where (c1 = 1)',
+ 'order by c1']))