Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sqlparse/filters/others.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def _get_insert_token(token):
if prev_ is not None and not prev_.match(T.Punctuation, '('):
tlist.tokens.insert(tidx, _get_insert_token(token))
tlist.tokens.remove(token)
tidx -= 1
else:
tlist.tokens[tidx] = _get_insert_token(token)

Expand Down
12 changes: 12 additions & 0 deletions tests/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ def test_strip_comments_single(self):
'from foo--comment\nf'
res = sqlparse.format(sql, strip_comments=True)
assert res == 'select a\nfrom foo\nf'
sql = '--A;--B;'
res = ''
assert res == sqlparse.format(sql, strip_comments=True)
sql = '--A;\n--B;'
res = ''
assert res == sqlparse.format(sql, strip_comments=True)

def test_strip_comments_invalid_option(self):
sql = 'select-- foo\nfrom -- bar\nwhere'
Expand All @@ -77,6 +83,12 @@ def test_strip_comments_multi(self):
sql = '/*\n * sql starts here\n */\nselect'
res = sqlparse.format(sql, strip_comments=True)
assert res == 'select'
sql = '/* sql starts here */'
res = sqlparse.format(sql, strip_comments=True)
assert res == ''
sql = '/* sql starts here */\n/* or here */'
res = sqlparse.format(sql, strip_comments=True, strip_whitespace=True)
assert res == ''
sql = 'select (/* sql starts here */ select 2)'
res = sqlparse.format(sql, strip_comments=True, strip_whitespace=True)
assert res == 'select (select 2)'
Expand Down