Skip to content

Commit b51663c

Browse files
test last_word, add failing test case that caused crash
1 parent 3332f4f commit b51663c

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

bpython/curtsiesfrontend/repl.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -628,11 +628,8 @@ def process_key_event(self, e):
628628

629629
def get_last_word(self):
630630

631-
def last_word(line):
632-
return line.split().pop() if line else ''
633-
634-
previous_word = last_word(self.rl_history.entry)
635-
word = last_word(self.rl_history.back())
631+
previous_word = _last_word(self.rl_history.entry)
632+
word = _last_word(self.rl_history.back())
636633
line = self.current_line
637634
self._set_current_line(line[:len(line) - len(previous_word)] + word,
638635
reset_rl_history=False)
@@ -1522,6 +1519,10 @@ def tabs_to_spaces(line):
15221519
return line.replace('\t', ' ')
15231520

15241521

1522+
def _last_word(line):
1523+
return line.split().pop() if line else ''
1524+
1525+
15251526
def compress_paste_event(paste_event):
15261527
"""If all events in a paste event are identical and not simple characters,
15271528
returns one of them

bpython/test/test_curtsies_repl.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ def test_get_last_word(self):
7777
self.repl.get_last_word()
7878
self.assertEqual(self.repl.current_line, 'abcde3')
7979

80+
def test_last_word(self):
81+
self.assertEquals(curtsiesrepl._last_word(''), '')
82+
self.assertEquals(curtsiesrepl._last_word(' '), '')
83+
self.assertEquals(curtsiesrepl._last_word('a'), 'a')
84+
self.assertEquals(curtsiesrepl._last_word('a b'), 'b')
85+
8086
# this is the behavior of bash - not currently implemented
8187
@unittest.skip
8288
def test_get_last_word_with_prev_line(self):

0 commit comments

Comments
 (0)