forked from bpython/bpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_manual_readline.py
More file actions
206 lines (177 loc) · 6.94 KB
/
test_manual_readline.py
File metadata and controls
206 lines (177 loc) · 6.94 KB
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
from bpython.curtsiesfrontend.manual_readline import *
import unittest
class TestManualReadline(unittest.TestCase):
def setUp(self):
self._line = "this is my test string"
def tearDown(self):
pass
def test_left_arrow_at_zero(self):
pos = 0
expected = (pos, self._line)
result = left_arrow(pos, self._line)
self.assertEquals(expected, result)
def test_left_arrow_at_non_zero(self):
for i in xrange(1, len(self._line)):
expected = (i-1, self._line)
result = left_arrow(i, self._line)
self.assertEqual(expected, result)
def test_right_arrow_at_end(self):
pos = len(self._line)
expected = (pos, self._line)
result = right_arrow(pos, self._line)
self.assertEquals(expected, result)
def test_right_arrow_at_non_end(self):
for i in xrange(len(self._line) - 1):
expected = (i + 1, self._line)
result = right_arrow(i, self._line)
self.assertEquals(expected, result)
def test_beginning_of_line(self):
expected = (0, self._line)
for i in xrange(len(self._line)):
result = beginning_of_line(i, self._line)
self.assertEquals(expected, result)
def test_end_of_line(self):
expected = (len(self._line), self._line)
for i in xrange(len(self._line)):
result = end_of_line(i, self._line)
self.assertEquals(expected, result)
def test_forward_word(self):
line = "going from here to_here"
#012345678901234567890123
start_pos = 11
next_word_pos = 15
expected = (next_word_pos, line)
result = forward_word(start_pos, line)
self.assertEquals(expected, result)
start_pos = 15
next_word_pos = 23
expected = (next_word_pos, line)
result = forward_word(start_pos, line)
self.assertEquals(expected, result)
def test_forward_word_tabs(self):
line = "going from here to_here"
#01234567890123456789012345678
start_pos = 11
next_word_pos = 15
expected = (next_word_pos, line)
result = forward_word(start_pos, line)
self.assertEquals(expected, result)
start_pos = 15
next_word_pos = 28
expected = (next_word_pos, line)
result = forward_word(start_pos, line)
self.assertEquals(expected, result)
def test_forward_word_end(self):
line = "going from here to_here"
#012345678901234567890123
start_pos = 16
next_word_pos = 23
expected = (next_word_pos, line)
result = forward_word(start_pos, line)
self.assertEquals(expected, result)
start_pos = 22
next_word_pos = 23
expected = (next_word_pos, line)
result = forward_word(start_pos, line)
self.assertEquals(expected, result)
start_pos = 23
next_word_pos = 23
expected = (next_word_pos, line)
result = forward_word(start_pos, line)
self.assertEquals(expected, result)
def test_forward_word_empty(self):
line = ""
#0
start_pos = 0
next_word_pos = 0
expected = (next_word_pos, line)
result = forward_word(start_pos, line)
self.assertEquals(expected, result)
def test_back_word(self):
line = "going to here from_here"
start_pos = 14
prev_word_pos = 9
self.assertEquals(line[start_pos], 'f')
self.assertEquals(line[prev_word_pos], 'h')
expected = (prev_word_pos, line)
result = back_word(start_pos, line)
self.assertEquals(expected, result)
def test_last_word_pos(self):
line = "a word"
expected = 2
result = last_word_pos(line)
self.assertEquals(expected, result)
def test_last_word_pos_single_word(self):
line = "word"
expected = 0
result = last_word_pos(line)
self.assertEquals(expected, result)
def test_delete(self):
line = "deletion line"
pos = 3
expected = (3, "deltion line")
result = delete(pos, line)
self.assertEquals(expected, result)
def test_delete_from_cursor_back(self):
line = "everything before this will be deleted"
expected = (0, "this will be deleted")
result = delete_from_cursor_back(line.find("this"), line)
self.assertEquals(expected, result)
def test_delete_from_cursor_forward(self):
line = "everything after this will be deleted"
pos = line.find("this")
expected = (pos, "everything after ")
result = delete_from_cursor_forward(line.find("this"), line)
self.assertEquals(expected, result)
def test_delete_rest_of_word(self):
self.try_stages(['z|s;df asdf d s;a;a',
'z|;df asdf d s;a;a',
'z| asdf d s;a;a',
'z| d s;a;a',
'z| s;a;a',
'z|;a;a',
'z|;a',
'z|'], delete_rest_of_word)
def test_delete_word_to_cursor(self):
self.try_stages([
' a;d sdf ;a;s;d; fjksald|a',
' a;d sdf ;a;s;d; |a',
' a;d sdf |a',
' a;d |a',
' |a',
'|a',
], delete_word_to_cursor)
def test_yank_prev_killed_text(self):
pass
def test_yank_prev_prev_killed_text(self):
pass
def try_stages(self, strings, func):
if not all('|' in s for s in strings):
raise ValueError("Need to use '|' to specify cursor")
stages = [(s.index('|'), s.replace('|', '')) for s in strings]
for (initial_pos, initial), (final_pos, final) in zip(stages[:-1], stages[1:]):
self.assertEquals(func(initial_pos, initial), (final_pos, final))
def test_transpose_character_before_cursor(self):
self.try_stages(["as|df asdf",
"ads|f asdf",
"adfs| asdf",
"adf s|asdf",
"adf as|sdf"], transpose_character_before_cursor)
def test_transpose_word_before_cursor(self):
pass
def test_backspace(self):
self.assertEquals(backspace(2, 'as'), (1, 'a'))
self.assertEquals(backspace(3, 'as '), (2, 'as'))
def test_delete_word_from_cursor_back(self):
self.try_stages([
"asd;fljk asd;lfjas;dlkfj asdlk jasdf;ljk|",
"asd;fljk asd;lfjas;dlkfj asdlk jasdf;|",
"asd;fljk asd;lfjas;dlkfj asdlk |",
"asd;fljk asd;lfjas;dlkfj |",
"asd;fljk asd;lfjas;|",
"asd;fljk asd;|",
"asd;fljk |",
"asd;|",
"|"], delete_word_from_cursor_back)
if __name__ == '__main__':
unittest.main()