|
| 1 | +import pytest |
| 2 | +from mssqlcli.mssqlbuffer import _is_complete |
| 3 | + |
| 4 | + |
| 5 | +class TestMssqlCliMultiline: |
| 6 | + testdata = [ |
| 7 | + (None, False), |
| 8 | + ('', False), |
| 9 | + ('select 1 /* open comment!\ngo', False), |
| 10 | + ('select 1\ngo -- another comment', True), |
| 11 | + ('select 1; select 2, "open quote: go', False), |
| 12 | + ('select 1\n"go"', False), |
| 13 | + ('select 1; GO', False), |
| 14 | + ('SELECT 4;\nGO', True), |
| 15 | + ('select 1\n select 2;\ngo', True), |
| 16 | + ('select 1;', False), |
| 17 | + ('select 1 go', False), |
| 18 | + ('select 1\ngo go go', False), |
| 19 | + ('GO select 1', False), |
| 20 | + ('GO', True) |
| 21 | + # tests below to be enabled when sqlparse supports retaining newlines |
| 22 | + # when stripping comments (tracking here: |
| 23 | + # https://github.com/andialbrecht/sqlparse/issues/484): |
| 24 | + # ('select 3 /* another open comment\n*/ GO', True), |
| 25 | + # ('select 1\n*/go', False), |
| 26 | + # ('select 1 /*\nmultiple lines!\n*/go', True) |
| 27 | + ] |
| 28 | + |
| 29 | + @staticmethod |
| 30 | + @pytest.mark.parametrize("query_str, is_complete", testdata) |
| 31 | + def test_multiline_completeness(query_str, is_complete): |
| 32 | + """ |
| 33 | + Tests the _is_complete helper method, which parses a T-SQL multiline |
| 34 | + statement on each newline and determines whether the script should |
| 35 | + execute. |
| 36 | + """ |
| 37 | + assert _is_complete(query_str) == is_complete |
0 commit comments