diff --git a/tests/command_mode_test.py b/tests/command_mode_test.py index 536b73d..7fe31d6 100644 --- a/tests/command_mode_test.py +++ b/tests/command_mode_test.py @@ -1,3 +1,5 @@ +import pytest + from testing.runner import and_exit from testing.runner import run @@ -42,27 +44,37 @@ def test_key_navigation_in_command_mode(): h.await_cursor_position(x=11, y=23) h.await_text('\nhello world\n') - h.press('Bspace') - h.await_cursor_position(x=10, y=23) - h.await_text('\nhello worl\n') - h.press('Home') - h.press('Bspace') # does nothing at beginning - h.await_cursor_position(x=0, y=23) - h.await_text('\nhello worl\n') - h.press('DC') h.await_cursor_position(x=0, y=23) - h.await_text('\nello worl\n') + h.await_text('\nello world\n') # unknown keys don't do anything h.press('^J') - h.await_text('\nello worl\n') + h.await_text('\nello world\n') h.press('Enter') +@pytest.mark.parametrize('key', ('BSpace', '^H')) +def test_command_mode_backspace(key): + with run() as h, and_exit(h): + trigger_command_mode(h) + h.press('hello world') + h.await_text('\nhello world\n') + + h.press(key) + h.await_text('\nhello worl\n') + + h.press('Home') + h.press(key) # does nothing at beginning + h.await_cursor_position(x=0, y=23) + h.await_text('\nhello worl\n') + + h.press('^C') + + def test_command_mode_ctrl_k(): with run() as h, and_exit(h): trigger_command_mode(h) diff --git a/tests/search_test.py b/tests/search_test.py index fbebba5..461ce15 100644 --- a/tests/search_test.py +++ b/tests/search_test.py @@ -204,6 +204,24 @@ def test_search_multiple_sessions_append_to_history(xdg_data_home): ) +@pytest.mark.parametrize('key', ('BSpace', '^H')) +def test_search_reverse_search_history_backspace(xdg_data_home, key): + xdg_data_home.join('babi/history/search').ensure().write( + 'line_5\n' + 'line_3\n' + 'line_1\n', + ) + with run() as h, and_exit(h): + h.press('^W') + h.press('^R') + h.await_text('search(reverse-search)``:') + h.press('linea') + h.await_text('search(failed reverse-search)`linea`: line_1') + h.press(key) + h.await_text('search(reverse-search)`line`: line_1') + h.press('^C') + + def test_search_reverse_search_history(xdg_data_home, ten_lines): xdg_data_home.join('babi/history/search').ensure().write( 'line_5\n' @@ -216,10 +234,6 @@ def test_search_reverse_search_history(xdg_data_home, ten_lines): h.await_text('search(reverse-search)``:') h.press('line') h.await_text('search(reverse-search)`line`: line_1') - h.press('a') - h.await_text('search(failed reverse-search)`linea`: line_1') - h.press('BSpace') - h.await_text('search(reverse-search)`line`: line_1') h.press('^R') h.await_text('search(reverse-search)`line`: line_3') h.press('Enter') diff --git a/tests/text_editing_test.py b/tests/text_editing_test.py index 5e19bf7..cddf85f 100644 --- a/tests/text_editing_test.py +++ b/tests/text_editing_test.py @@ -1,3 +1,5 @@ +import pytest + from testing.runner import and_exit from testing.runner import run @@ -14,7 +16,7 @@ def test_basic_text_editing(tmpdir): def test_backspace_at_beginning_of_file(): with run() as h, and_exit(h): - h.press('Bspace') + h.press('BSpace') h.await_text_missing('unknown key') assert h.screenshot().strip().splitlines()[1:] == [] assert '*' not in h.screenshot() @@ -27,7 +29,7 @@ def test_backspace_joins_lines(tmpdir): with run(str(f)) as h, and_exit(h): h.await_text('foo') h.press('Down') - h.press('Bspace') + h.press('BSpace') h.await_text('foobar') h.await_text('f *') h.await_cursor_position(x=3, y=1) @@ -43,13 +45,14 @@ def test_backspace_at_end_of_file_still_allows_scrolling_down(tmpdir): with run(str(f)) as h, and_exit(h): h.await_text('hello world') h.press('Down') - h.press('Bspace') + h.press('BSpace') h.press('Down') h.await_cursor_position(x=0, y=2) assert '*' not in h.screenshot() -def test_backspace_deletes_text(tmpdir): +@pytest.mark.parametrize('key', ('BSpace', '^H')) +def test_backspace_deletes_text(tmpdir, key): f = tmpdir.join('f') f.write('ohai there') @@ -57,7 +60,7 @@ def test_backspace_deletes_text(tmpdir): h.await_text('ohai there') for _ in range(3): h.press('Right') - h.press('Bspace') + h.press(key) h.await_text('ohi') h.await_text('f *') h.await_cursor_position(x=2, y=1) diff --git a/tests/undo_redo_test.py b/tests/undo_redo_test.py index c6600c0..449a2ec 100644 --- a/tests/undo_redo_test.py +++ b/tests/undo_redo_test.py @@ -39,7 +39,7 @@ def test_undo_redo_action_interrupts_actions(): with run() as h, and_exit(h): h.press('hello') h.await_text('hello') - h.press('Bspace') + h.press('BSpace') h.await_text_missing('hello') h.press('M-u') h.await_text('hello')