diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2021-02-08 11:28:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2021-02-08 11:28:14 +0000 |
commit | b678a621c57a6d3fdfac14bdbbef0ed743ab1742 (patch) | |
tree | 5481c14ce75dfda9c55721de033992b45ab0e1dc /test/test_naive_completion.py | |
parent | Initial commit. (diff) | |
download | mycli-b678a621c57a6d3fdfac14bdbbef0ed743ab1742.tar.xz mycli-b678a621c57a6d3fdfac14bdbbef0ed743ab1742.zip |
Adding upstream version 1.22.2.upstream/1.22.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/test_naive_completion.py')
-rw-r--r-- | test/test_naive_completion.py | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/test/test_naive_completion.py b/test/test_naive_completion.py new file mode 100644 index 0000000..14c1bf5 --- /dev/null +++ b/test/test_naive_completion.py @@ -0,0 +1,63 @@ +import pytest +from prompt_toolkit.completion import Completion +from prompt_toolkit.document import Document + + +@pytest.fixture +def completer(): + import mycli.sqlcompleter as sqlcompleter + return sqlcompleter.SQLCompleter(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 = list(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 = list(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 MA' + position = len('SELECT MA') + result = list(completer.get_completions( + Document(text=text, cursor_position=position), + complete_event)) + assert result == list([ + Completion(text='MASTER', start_position=-2), + Completion(text='MAX', start_position=-2)]) + + +def test_column_name_completion(completer, complete_event): + text = 'SELECT FROM users' + position = len('SELECT ') + result = list(completer.get_completions( + Document(text=text, cursor_position=position), + complete_event)) + assert result == list(map(Completion, sorted(completer.all_completions))) + + +def test_special_name_completion(completer, complete_event): + text = '\\' + position = len('\\') + result = set(completer.get_completions( + Document(text=text, cursor_position=position), + complete_event)) + # Special commands will NOT be suggested during naive completion mode. + assert result == set() |