def test_search_history_extra_blank_lines(run, xdg_data_home): with run() as h, and_exit(h): h.press('^W') h.press_and_enter('hello') with run() as h, and_exit(h): pass contents = xdg_data_home.join('babi/history/search').read() assert contents == 'hello\n'
def test_search_multiple_sessions_append_to_history(run, xdg_data_home): xdg_data_home.join('babi/history/search').ensure().write( 'orig\n' 'history\n', ) with run() as h1, and_exit(h1): with run() as h2, and_exit(h2): h2.press('^W') h2.press_and_enter('h2 history') h1.press('^W') h1.press_and_enter('h1 history') contents = xdg_data_home.join('babi/history/search').read() assert contents == ('orig\n' 'history\n' 'h2 history\n' 'h1 history\n')
def test_search_not_found(run, ten_lines): with run(str(ten_lines)) as h, and_exit(h): h.press('^W') h.await_text('search:') h.press_and_enter('this will not match') h.await_text('no matches') h.await_cursor_position(x=0, y=1)
def test_search_reverse_search_resizing(run): with run() as h, and_exit(h): h.press('^W') h.press('^R') with h.resize(width=24, height=24): h.await_text('search(reverse-se…:') h.press('^C')
def test_search_reverse_search_history_cancel(run): with run() as h, and_exit(h): h.press('^W') h.press('^R') h.await_text('search(reverse-search)``:') h.press('^C') h.await_text('cancelled')
def test_search_find_next_line(run, ten_lines): with run(str(ten_lines)) as h, and_exit(h): h.await_cursor_position(x=0, y=1) h.press('^W') h.await_text('search:') h.press_and_enter('^line_') h.await_cursor_position(x=0, y=2)
def test_search_history_recorded(run): with run() as h, and_exit(h): h.press('^W') h.await_text('search:') h.press_and_enter('asdf') h.await_text('no matches') h.press('^W') h.press('Up') h.await_text('search [asdf]: asdf') h.press('BSpace') h.press('test') h.await_text('search [asdf]: asdtest') h.press('Down') h.await_text_missing('asdtest') h.press('Down') # can't go past the end h.press('Up') h.await_text('asdtest') h.press('Up') # can't go past the beginning h.await_text('asdtest') h.press('Enter') h.await_text('no matches') h.press('^W') h.press('Up') h.await_text('search [asdtest]: asdtest') h.press('Up') h.await_text('search [asdtest]: asdf') h.press('^C')
def test_trailing_whitespace_does_not_highlight_line_continuation(run, tmpdir): f = tmpdir.join('f') f.write(f'{" " * 30}\nhello\n') with run(str(f), term='screen-256color', width=20) as h, and_exit(h): h.await_text('hello') h.assert_screen_attr_equals(1, [(-1, 1, 0)] * 19 + [(-1, -1, 0)])
def test_ctrl_up_moves_screen_up_one_line(run, ten_lines): with run(str(ten_lines), height=5) as h, and_exit(h): h.press('^Down') h.press('^Up') h.await_text('line_0') h.await_text('line_2') h.await_cursor_position(x=0, y=2)
def test_go_to_line_line(run, ten_lines): def _jump_to_line(n): h.press('^_') h.await_text('enter line number:') h.press_and_enter(str(n)) h.await_text_missing('enter line number:') with run(str(ten_lines), height=9) as h, and_exit(h): # still on screen _jump_to_line(3) h.await_cursor_position(x=0, y=3) # should go to beginning of file _jump_to_line(0) h.await_cursor_position(x=0, y=1) # should go to end of the file _jump_to_line(999) h.await_cursor_position(x=0, y=4) h.assert_screen_line_equals(3, 'line_9') # should also go to the end of the file _jump_to_line(-1) h.await_cursor_position(x=0, y=4) h.assert_screen_line_equals(3, 'line_9') # should go to beginning of file _jump_to_line(-999) h.await_cursor_position(x=0, y=1) h.assert_cursor_line_equals('line_0')
def test_key_navigation_in_command_mode(run): with run() as h, and_exit(h): trigger_command_mode(h) h.press('hello world') h.await_cursor_position(x=11, y=23) h.press('Left') h.await_cursor_position(x=10, y=23) h.press('Right') h.await_cursor_position(x=11, y=23) h.press('Home') h.await_cursor_position(x=0, y=23) h.press('End') h.await_cursor_position(x=11, y=23) h.press('^A') h.await_cursor_position(x=0, y=23) h.press('^E') h.await_cursor_position(x=11, y=23) h.press('DC') # does nothing at end h.await_cursor_position(x=11, y=23) h.await_text('\nhello world\n') h.press('Home') h.press('DC') h.await_cursor_position(x=0, y=23) h.await_text('\nello world\n') # unknown keys don't do anything h.press('^J') h.await_text('\nello world\n') h.press('Enter')
def test_ctrl_right_triggering_scroll(run, jump_word_file): with run(str(jump_word_file), height=4) as h, and_exit(h): h.press('Down') h.await_cursor_position(x=0, y=2) h.press('^Right') h.await_cursor_position(x=0, y=1) h.assert_cursor_line_equals('hi')
def test_indent_at_beginning_of_line(run): with run() as h, and_exit(h): h.press('hello') h.press('Home') h.press('Tab') h.await_text('\n hello\n') h.await_cursor_position(x=4, y=1)
def test_save_no_filename_specified_cancel(run, k): with run() as h, and_exit(h): h.press('hello world') h.press('^S') h.await_text('enter filename:') h.press(k) h.await_text('cancelled')
def test_save_via_ctrl_o_position(run): with run('filename') as h, and_exit(h): h.press('hello world') h.press('^O') h.await_text('enter filename: filename') h.await_cursor_position(x=24, y=23) h.press('^C')
def test_syntax_highlighting_to_edge_of_screen(run, tmpdir): f = tmpdir.join('f.demo') f.write(f'# {"x" * 18}') with run(str(f), term='screen-256color', width=20) as h, and_exit(h): h.await_text('# xxx') h.assert_screen_attr_equals(1, [(243, 40, 0)] * 20)
def test_indent_not_full_tab(run): with run() as h, and_exit(h): h.press('h') h.press('Tab') h.press('ello') h.await_text('h ello') h.await_cursor_position(x=8, y=1)
def test_save_via_ctrl_o_cancelled(run, key): with run() as h, and_exit(h): h.press('hello world') h.press('^O') h.await_text('enter filename:') h.press(key) h.await_text('cancelled')
def test_cut_end_of_file_noop_extra_cut(run): with run() as h, and_exit(h): h.press('hi') h.press('^K') h.press('^K') h.press('^U') h.await_text('hi')
def test_indentation_using_tabs(run, tmpdir): f = tmpdir.join('f') f.write(f'123456789\n\t12\t{"x" * 20}\n') with run(str(f), width=20) as h, and_exit(h): h.await_text('123456789\n 12 xxxxxxxxxxx»\n') h.press('Down') h.await_cursor_position(x=0, y=2) h.press('Up') h.await_cursor_position(x=0, y=1) h.press('Right') h.await_cursor_position(x=1, y=1) h.press('Down') h.await_cursor_position(x=0, y=2) h.press('Up') h.await_cursor_position(x=1, y=1) h.press('Down') h.await_cursor_position(x=0, y=2) h.press('Right') h.await_cursor_position(x=4, y=2) h.press('Up') h.await_cursor_position(x=4, y=1)
def test_redo_cleared_after_action(run, tmpdir): with run() as h, and_exit(h): h.press('hello') h.press('M-u') h.press('world') h.press('M-U') h.await_text('nothing to redo!')
def test_mixed_newlines(run, tmpdir): f = tmpdir.join('f') f.write_binary(b'foo\nbar\r\n') with run(str(f)) as h, and_exit(h): # should start as modified h.await_text('f *') h.await_text(r"mixed newlines will be converted to '\n'")
def test_dedent_selection(run, tmpdir): f = tmpdir.join('f') f.write('1\n 2\n 3\n') with run(str(f)) as h, and_exit(h): for _ in range(3): h.press('S-Down') h.press('BTab') h.await_text('\n1\n2\n 3\n')
def test_dedent_exactly_one_indent(run): with run() as h, and_exit(h): h.press('Tab') h.press('a') h.await_text('\n a\n') h.press('BTab') h.await_text('\na\n') h.await_cursor_position(x=1, y=1)
def test_indent_selection(run, ten_lines): with run(str(ten_lines)) as h, and_exit(h): h.press('S-Right') h.press('Tab') h.await_text('\n line_0\n') h.await_cursor_position(x=5, y=1) h.press('^K') h.await_text('\nine_0\n')
def test_basic_text_editing(run, tmpdir): with run() as h, and_exit(h): h.press('hello world') h.await_text('hello world') h.press('Down') h.press('bye!') h.await_text('bye!') h.await_text('hello world\nbye!\n')
def test_reverse_sort_entire_file(run, unsorted): with run(str(unsorted)) as h, and_exit(h): trigger_command_mode(h) h.press_and_enter(':sort!') h.await_text('sorted!') h.await_cursor_position(x=0, y=1) h.press('^S') assert unsorted.read() == 'd\nc\nb\na\n'
def test_save_on_exit_cancel_yn(run): with run() as h, and_exit(h): h.press('hello') h.await_text('hello') h.press('^X') h.await_text('file is modified - save [yes, no]?') h.press('^C') h.await_text('cancelled')
def test_syntax_highlighting_with_tabs(run, tmpdir): f = tmpdir.join('f.demo') f.write('\t# 12345678901234567890\n') with run(str(f), term='screen-256color', width=20) as h, and_exit(h): h.await_text('1234567890') expected = 4 * [(236, 40, 0)] + 15 * [(243, 40, 0)] + [(236, 40, 0)] h.assert_screen_attr_equals(1, expected)
def test_page_up_does_not_go_negative(run, ten_lines): with run(str(ten_lines), height=10) as h, and_exit(h): for _ in range(8): h.press('Down') h.await_cursor_position(x=0, y=4) h.press('^Y') h.await_cursor_position(x=0, y=1) h.assert_cursor_line_equals('line_0')