-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathtest_naive_completion.py
More file actions
81 lines (62 loc) · 2.46 KB
/
Copy pathtest_naive_completion.py
File metadata and controls
81 lines (62 loc) · 2.46 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import pytest
from prompt_toolkit.completion import Completion
from prompt_toolkit.document import Document
@pytest.fixture
def completer():
import dbsqlcli.completer as sqlcompleter
return sqlcompleter.DBSQLCompleter(smart_completion=False)
@pytest.fixture
def complete_event():
from unittest.mock import Mock
return Mock()
def test_empty_string_completion(completer, complete_event):
text = ""
position = 0
result = completer.get_completions(
Document(text=text, cursor_position=position), complete_event
)
assert result == list(map(Completion, sorted(completer.all_completions)))
def test_select_keyword_completion(completer, complete_event):
text = "SEL"
position = len("SEL")
result = completer.get_completions(
Document(text=text, cursor_position=position), complete_event
)
assert result == list([Completion(text="SELECT", start_position=-3)])
def test_function_name_completion(completer, complete_event):
text = "select map_con"
position = len("select map_con")
result = completer.get_completions(
Document(text=text, cursor_position=position), complete_event
)
assert result == [
Completion(text="map_concat", start_position=-7),
Completion(text="map_contains_key", start_position=-7),
]
def test_column_name_completion(completer, complete_event):
text = "SELECT FROM users"
position = len("SELECT ")
result = completer.get_completions(
Document(text=text, cursor_position=position), complete_event
)
assert result == list(map(Completion, sorted(completer.all_completions)))
def test_various_join_completions(completer, complete_event):
for join_type in ["INNER", "OUTER", "CROSS", "LEFT", "RIGHT", "FULL"]:
text = "SELECT foo FROM bar " + join_type + " "
position = len(text)
result = completer.get_completions(
Document(text=text, cursor_position=position),
complete_event,
smart_completion=True,
)
assert Completion(text="JOIN") in result
def test_outer_join_completion(completer, complete_event):
for join_type in ["LEFT", "RIGHT", "FULL"]:
text = "SELECT foo FROM bar " + join_type + " "
position = len(text)
result = completer.get_completions(
Document(text=text, cursor_position=position),
complete_event,
smart_completion=True,
)
assert Completion(text="OUTER JOIN") in result