diff --git a/sqlparse/engine/statement_splitter.py b/sqlparse/engine/statement_splitter.py index bc57d170..c3e637d0 100644 --- a/sqlparse/engine/statement_splitter.py +++ b/sqlparse/engine/statement_splitter.py @@ -150,14 +150,13 @@ def _change_splitlevel(self, ttype, value): def process(self, stream): """Process the stream""" - EOS_TTYPE = T.Whitespace, T.Comment.Single + EOS_TTYPE = T.Whitespace, T.Comment.Single, T.Comment.Multiline # Run over all stream tokens for ttype, value in stream: # Yield token if we finished a statement and there's no whitespaces # It will count newline token as a non whitespace. In this context # whitespace ignores newlines. - # why don't multi line comments also count? if self.consume_ws and ttype not in EOS_TTYPE: yield sql.Statement(self.tokens) diff --git a/tests/test_split_trailing_comments.py b/tests/test_split_trailing_comments.py new file mode 100644 index 00000000..3fe78a53 --- /dev/null +++ b/tests/test_split_trailing_comments.py @@ -0,0 +1,18 @@ +import sqlparse + + +def test_split_keeps_trailing_block_comment_with_statement(): + sql = "SELECT 1; /* trailing */\nSELECT 2;" + + assert sqlparse.split(sql) == [ + "SELECT 1; /* trailing */", + "SELECT 2;", + ] + + +def test_split_trailing_comments_are_consistent(): + block = "SELECT 1; /* trailing */\nSELECT 2;" + line = "SELECT 1; -- trailing\nSELECT 2;" + + assert sqlparse.split(block)[0] == "SELECT 1; /* trailing */" + assert sqlparse.split(line)[0] == "SELECT 1; -- trailing"