blob: edd3f2f5903d2d6d89c66fa7916bdcdfa8281592 (
plain) (
blame)
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
|
import pytest
from prompt_toolkit.buffer import Buffer
from prompt_toolkit.history import InMemoryHistory
@pytest.fixture
def _history():
"Prefilled history."
history = InMemoryHistory()
history.append_string("alpha beta gamma delta")
history.append_string("one two three four")
return history
# Test yank_last_arg.
def test_empty_history():
buf = Buffer()
buf.yank_last_arg()
assert buf.document.current_line == ""
def test_simple_search(_history):
buff = Buffer(history=_history)
buff.yank_last_arg()
assert buff.document.current_line == "four"
def test_simple_search_with_quotes(_history):
_history.append_string("""one two "three 'x' four"\n""")
buff = Buffer(history=_history)
buff.yank_last_arg()
assert buff.document.current_line == '''"three 'x' four"'''
def test_simple_search_with_arg(_history):
buff = Buffer(history=_history)
buff.yank_last_arg(n=2)
assert buff.document.current_line == "three"
def test_simple_search_with_arg_out_of_bounds(_history):
buff = Buffer(history=_history)
buff.yank_last_arg(n=8)
assert buff.document.current_line == ""
def test_repeated_search(_history):
buff = Buffer(history=_history)
buff.yank_last_arg()
buff.yank_last_arg()
assert buff.document.current_line == "delta"
def test_repeated_search_with_wraparound(_history):
buff = Buffer(history=_history)
buff.yank_last_arg()
buff.yank_last_arg()
buff.yank_last_arg()
assert buff.document.current_line == "four"
# Test yank_last_arg.
def test_yank_nth_arg(_history):
buff = Buffer(history=_history)
buff.yank_nth_arg()
assert buff.document.current_line == "two"
def test_repeated_yank_nth_arg(_history):
buff = Buffer(history=_history)
buff.yank_nth_arg()
buff.yank_nth_arg()
assert buff.document.current_line == "beta"
def test_yank_nth_arg_with_arg(_history):
buff = Buffer(history=_history)
buff.yank_nth_arg(n=2)
assert buff.document.current_line == "three"
|