-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtest_line_info.py
More file actions
39 lines (36 loc) · 1.17 KB
/
test_line_info.py
File metadata and controls
39 lines (36 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from protowhat.failure import TestFail as TF
from protowhat.Feedback import Feedback
from protowhat.Reporter import Reporter
from protowhat.selectors import Dispatcher
from sqlwhat.State import State, PARSER_MODULES
from antlr_tsql import ast
import pytest
pos_names = ["line_start", "column_start", "line_end", "column_end"]
@pytest.mark.parametrize(
"sql_cmd,start,pos",
[
# pos is 4-tuple (line_start, column_start, line_end, column_end)
("SELECT x FROM y", "tsql_file", [1, 1, 1, 15]),
("SELECT x FROM yy", "tsql_file", [1, 1, 1, 16]),
(" SELECT x FROM y", "tsql_file", [1, 2, 1, 16]),
("\nSELECT x FROM y", "tsql_file", [2, 1, 2, 15]),
("\nSELECT x FROM y\nSELECT a FROM b", "tsql_file", [2, 1, 3, 15]),
],
)
def test_line_info(sql_cmd, start, pos):
state = State(
sql_cmd,
"",
"",
None,
None,
{},
{},
Reporter(),
ast_dispatcher=Dispatcher.from_module(PARSER_MODULES["mssql"]),
)
try:
state.report("failure message")
except TF as tf:
for ii, k in enumerate(pos_names):
assert tf.feedback.get_highlight()[k] == pos[ii]