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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
import pytest
from prompt_toolkit.completion import Completion
from prompt_toolkit.document import Document
from utils import completions_to_set
@pytest.fixture
def completer():
import pgcli.pgcompleter as pgcompleter
return pgcompleter.PGCompleter(smart_completion=False)
@pytest.fixture
def complete_event():
from mock import Mock
return Mock()
def test_empty_string_completion(completer, complete_event):
text = ""
position = 0
result = completions_to_set(
completer.get_completions(
Document(text=text, cursor_position=position), complete_event
)
)
assert result == completions_to_set(map(Completion, completer.all_completions))
def test_select_keyword_completion(completer, complete_event):
text = "SEL"
position = len("SEL")
result = completions_to_set(
completer.get_completions(
Document(text=text, cursor_position=position), complete_event
)
)
assert result == completions_to_set([Completion(text="SELECT", start_position=-3)])
def test_function_name_completion(completer, complete_event):
text = "SELECT MA"
position = len("SELECT MA")
result = completions_to_set(
completer.get_completions(
Document(text=text, cursor_position=position), complete_event
)
)
assert result == completions_to_set(
[
Completion(text="MATERIALIZED VIEW", start_position=-2),
Completion(text="MAX", start_position=-2),
Completion(text="MAXEXTENTS", start_position=-2),
Completion(text="MAKE_DATE", start_position=-2),
Completion(text="MAKE_TIME", start_position=-2),
Completion(text="MAKE_TIMESTAMPTZ", start_position=-2),
Completion(text="MAKE_INTERVAL", start_position=-2),
Completion(text="MASKLEN", start_position=-2),
Completion(text="MAKE_TIMESTAMP", start_position=-2),
]
)
def test_column_name_completion(completer, complete_event):
text = "SELECT FROM users"
position = len("SELECT ")
result = completions_to_set(
completer.get_completions(
Document(text=text, cursor_position=position), complete_event
)
)
assert result == completions_to_set(map(Completion, completer.all_completions))
def test_alter_well_known_keywords_completion(completer, complete_event):
text = "ALTER "
position = len(text)
result = completions_to_set(
completer.get_completions(
Document(text=text, cursor_position=position),
complete_event,
smart_completion=True,
)
)
assert result > completions_to_set(
[
Completion(text="DATABASE", display_meta="keyword"),
Completion(text="TABLE", display_meta="keyword"),
Completion(text="SYSTEM", display_meta="keyword"),
]
)
assert (
completions_to_set([Completion(text="CREATE", display_meta="keyword")])
not in result
)
def test_special_name_completion(completer, complete_event):
text = "\\"
position = len("\\")
result = completions_to_set(
completer.get_completions(
Document(text=text, cursor_position=position), complete_event
)
)
# Special commands will NOT be suggested during naive completion mode.
assert result == completions_to_set([])
def test_datatype_name_completion(completer, complete_event):
text = "SELECT price::IN"
position = len("SELECT price::IN")
result = completions_to_set(
completer.get_completions(
Document(text=text, cursor_position=position),
complete_event,
smart_completion=True,
)
)
assert result == completions_to_set(
[
Completion(text="INET", display_meta="datatype"),
Completion(text="INT", display_meta="datatype"),
Completion(text="INT2", display_meta="datatype"),
Completion(text="INT4", display_meta="datatype"),
Completion(text="INT8", display_meta="datatype"),
Completion(text="INTEGER", display_meta="datatype"),
Completion(text="INTERNAL", display_meta="datatype"),
Completion(text="INTERVAL", display_meta="datatype"),
]
)
|