summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSoloman Weng <soloman1124@gmail.com>2018-03-26 09:38:57 +1000
committerSoloman Weng <soloman1124@gmail.com>2018-03-26 09:38:57 +1000
commit0fe6e3bac797bdedeeb0714dac080645377f29e2 (patch)
tree78800776867696941e79417eb1e6b4ba59926e38
parentfb52a01b6467896c38872046ca06ac6a38353ebb (diff)
downloadsqlparse-0fe6e3bac797bdedeeb0714dac080645377f29e2.tar.gz
Deal with long function params
-rw-r--r--sqlparse/filters/reindent.py7
-rw-r--r--tests/test_format.py12
2 files changed, 17 insertions, 2 deletions
diff --git a/sqlparse/filters/reindent.py b/sqlparse/filters/reindent.py
index 45d1270..3088d6f 100644
--- a/sqlparse/filters/reindent.py
+++ b/sqlparse/filters/reindent.py
@@ -167,7 +167,9 @@ class ReindentFilter(object):
end_at = self.offset + sum(len(i.value) + 1 for i in identifiers)
adjusted_offset = 0
- if end_at > (self.wrap_after - self.offset) and self._last_func:
+ if (self.wrap_after > 0
+ and end_at > (self.wrap_after - self.offset)
+ and self._last_func):
adjusted_offset = -len(self._last_func.value) - 1
with offset(self, adjusted_offset), indent(self):
@@ -177,7 +179,8 @@ class ReindentFilter(object):
for token in identifiers:
# Add 1 for the "," separator
position += len(token.value) + 1
- if position > (self.wrap_after - self.offset):
+ if (self.wrap_after > 0
+ and position > (self.wrap_after - self.offset)):
adjust = 0
tlist.insert_before(token, self.nl(offset=adjust))
position = 0
diff --git a/tests/test_format.py b/tests/test_format.py
index 342fe09..72af62e 100644
--- a/tests/test_format.py
+++ b/tests/test_format.py
@@ -453,6 +453,18 @@ class TestFormatReindent(object):
" col3",
"from my_table"])
+ def test_long_identifier_list_with_functions(self):
+ f = lambda sql: sqlparse.format(sql, reindent=True, wrap_after=30)
+ s = ("select 'abc' as foo, json_build_object('a', a,"
+ "'b', b, 'c', c, 'd', d, 'e', e) as col2"
+ "col3 from my_table")
+ assert f(s) == '\n'.join([
+ "select 'abc' as foo,",
+ " json_build_object('a',",
+ " a, 'b', b, 'c', c, 'd', d,",
+ " 'e', e) as col2col3",
+ "from my_table"])
+
def test_case(self):
f = lambda sql: sqlparse.format(sql, reindent=True)
s = 'case when foo = 1 then 2 when foo = 3 then 4 else 5 end'