Completed
Push — master ( 2bc9f2...ef56ad )
by Lambda
01:45
created

test_previous_match_without_match()   A

Complexity

Conditions 4

Size

Total Lines 8

Duplication

Lines 8
Ratio 100 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 4
dl 8
loc 8
rs 9.2
c 1
b 1
f 0
1
from unittest.mock import MagicMock, patch
2
from neovim_prompt.history import History
3
import pytest
4
5
6
@pytest.fixture
7
def prompt(nvim, context):
8
    history_candidates = (
9
        'foo',
10
        'bar',
11
        'foobar',
12
        'hoge',
13
        'barhoge',
14
        'foobarhoge',
15
    )
16
17
    def histnr(histname):
18
        return len(history_candidates)
19
20
    def histget(histname, index):
21
        if index == 0:
22
            return ''
23
        return history_candidates[-(index+1)]
24
25
    def call(fname, *args):
26
        if fname == 'histnr':
27
            return histnr(*args)
28
        elif fname == 'histget':
29
            return histget(*args)
30
31
    Prompt = MagicMock(spec='neovim_prompt.prompt.Prompt')
32
    prompt = Prompt(nvim, context)
33
34
    prompt.nvim.call = MagicMock()
35
    prompt.nvim.call.side_effect = call
36
    return prompt
37
38
39
def test_current(prompt):
40
    prompt.text = 'fool'
41
    prompt.caret.get_backward_text.return_value = 'fo'
42
    history = History(prompt)
43
    assert history.current() == 'fool'
44
45
46 View Code Duplication
def test_previous(prompt):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
47
    prompt.text = 'fool'
48
    prompt.caret.get_backward_text.return_value = 'fo'
49
    history = History(prompt)
50
    assert history.current() == 'fool'
51
52
    assert history.previous() == 'foo'
53
    assert history.current() == 'foo'
54
55
    assert history.previous() == 'bar'
56
    assert history.current() == 'bar'
57
58
    assert history.previous() == 'foobar'
59
    assert history.current() == 'foobar'
60
61
    assert history.previous() == 'hoge'
62
    assert history.current() == 'hoge'
63
64
    assert history.previous() == 'barhoge'
65
    assert history.current() == 'barhoge'
66
67
    assert history.previous() == 'foobarhoge'
68
    assert history.current() == 'foobarhoge'
69
70
    assert history.previous() == 'foobarhoge'
71
    assert history.current() == 'foobarhoge'
72
73
74 View Code Duplication
def test_next(prompt):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
75
    prompt.text = 'fool'
76
    prompt.caret.get_backward_text.return_value = 'fo'
77
    history = History(prompt)
78
    [history.previous() for i in range(6)]
79
    assert history.current() == 'foobarhoge'
80
81
    assert history.next() == 'barhoge'
82
    assert history.current() == 'barhoge'
83
84
    assert history.next() == 'hoge'
85
    assert history.current() == 'hoge'
86
87
    assert history.next() == 'foobar'
88
    assert history.current() == 'foobar'
89
90
    assert history.next() == 'bar'
91
    assert history.current() == 'bar'
92
93
    assert history.next() == 'foo'
94
    assert history.current() == 'foo'
95
96
    assert history.next() == 'fool'
97
    assert history.current() == 'fool'
98
99
    assert history.next() == 'fool'
100
    assert history.current() == 'fool'
101
102
103 View Code Duplication
def test_previous_match(prompt):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
104
    prompt.text = 'fool'
105
    prompt.caret.get_backward_text.return_value = 'fo'
106
    history = History(prompt)
107
    assert history.current() == 'fool'
108
109
    assert history.previous_match() == 'foo'
110
    assert history.current() == 'foo'
111
112
    assert history.previous_match() == 'foobar'
113
    assert history.current() == 'foobar'
114
115
    assert history.previous_match() == 'foobarhoge'
116
    assert history.current() == 'foobarhoge'
117
118
    assert history.previous_match() == 'foobarhoge'
119
    assert history.current() == 'foobarhoge'
120
121
122 View Code Duplication
def test_previous_match_without_match(prompt):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
123
    prompt.text = 'fool'
124
    prompt.caret.get_backward_text.return_value = 'Hello'
125
    history = History(prompt)
126
    assert history.current() == 'fool'
127
128
    assert history.previous_match() == 'fool'
129
    assert history.current() == 'fool'
130
131
132
def test_next_match(prompt):
133
    prompt.text = 'fool'
134
    prompt.caret.get_backward_text.return_value = 'fo'
135
    history = History(prompt)
136
    [history.previous() for i in range(6)]
137
    assert history.current() == 'foobarhoge'
138
139
    assert history.next_match() == 'foobar'
140
    assert history.current() == 'foobar'
141
142
    assert history.next_match() == 'foo'
143
    assert history.current() == 'foo'
144
145
    assert history.next_match() == 'fool'
146
    assert history.current() == 'fool'
147
148
    assert history.next_match() == 'fool'
149
    assert history.current() == 'fool'
150
151
152
def test_next_match_without_match(prompt):
153
    prompt.text = 'fool'
154
    prompt.caret.get_backward_text.return_value = 'Hello'
155
    history = History(prompt)
156
    assert history.current() == 'fool'
157
158
    assert history.next_match() == 'fool'
159
    assert history.current() == 'fool'
160