]> git.phdru.name Git - sqlconvert.git/commitdiff
Fix(process_tokens): Check if parser didn't produce any statements at all
authorOleg Broytman <phd@phdru.name>
Sat, 16 Jan 2021 19:22:36 +0000 (22:22 +0300)
committerOleg Broytman <phd@phdru.name>
Sat, 16 Jan 2021 20:15:38 +0000 (23:15 +0300)
sqlconvert/process_tokens.py
tests/test_process_tokens.py

index cb14467ccf958b478d888714ebaa6240e10fede2..414c5ca5a024bd783205655526897e87aa872ddf 100644 (file)
@@ -54,6 +54,8 @@ class StatementGrouper(object):
 
     def process_lines(self):
         statements = parse(''.join(self.lines), encoding=self.encoding)
+        if not statements:
+            return
         last_stmt = statements[-1]
         for i in xrange(len(last_stmt.tokens) - 1, 0, -1):
             token = last_stmt.tokens[i]
index 0cc431ccb0614098ce5fd0c5ec72e99c508db2e6..d74cb47a0bd5fcfac108d3163fa1e2a9fad94ccc 100644 (file)
@@ -8,8 +8,8 @@ from sqlconvert.process_tokens import is_newline_statement, StatementGrouper
 
 
 def test_newline_statement():
-    parsed = parse("\n")[0]
-    assert is_newline_statement(parsed)
+    parsed = parse("\n")
+    assert not parsed or is_newline_statement(parsed[0])
 
 
 def test_encoding():