summaryrefslogtreecommitdiffstats
path: root/test/test_naive_completion.py
blob: 32b2abdf8a6a47e128de9b812baa48fd69556c61 (plain)
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
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 unittest.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()