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_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_comment_some_code_with_alternate_comment_character(run, ten_lines): with run(str(ten_lines)) as h, and_exit(h): h.press('S-Down') trigger_command_mode(h) h.press_and_enter(':comment //') h.await_text('// line_0\n// line_1\nline_2\n')
def test_empty_command_is_noop(run): with run() as h, and_exit(h): h.press('hello ') trigger_command_mode(h) h.press('Enter') h.press('world') h.await_text('hello world') h.await_text_missing('invalid command')
def test_vim_force_exit(run, tmpdir): f = tmpdir.join('f') with run(str(f)) as h: h.press('hello') h.await_text('hello') trigger_command_mode(h) h.press_and_enter(':q!') h.await_exit()
def test_comment_some_code(run, ten_lines): with run(str(ten_lines)) as h, and_exit(h): h.press('S-Down') trigger_command_mode(h) h.press_and_enter(':comment') h.await_text('# line_0\n# line_1\nline_2\n')
def test_sort_selection(run, unsorted): with run(str(unsorted)) as h, and_exit(h): h.press('S-Down') 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() == 'b\nd\nc\na\n'
def test_save_via_command_mode(run, tmpdir): f = tmpdir.join('f') with run(str(f)) as h, and_exit(h): h.press('hello world') trigger_command_mode(h) h.press_and_enter(':w') assert f.read() == 'hello world\n'
def test_uncomment_single_line(run, ten_lines): with run(str(ten_lines)) as h, and_exit(h): h.press('#') h.await_text('#line_0\nline_1\n') trigger_command_mode(h) h.press_and_enter(':comment') h.await_text('line_0\nline_1\n')
def test_cancel_command_mode(run): with run() as h, and_exit(h): h.press('hello ') trigger_command_mode(h) h.press(':q') h.press('^C') h.press('world') h.await_text('hello world') h.await_text_missing('invalid command')
def test_remove_comment_with_comment_elsewhere_in_line(run, tmpdir, comment): f = tmpdir.join('f') f.write(f'{comment}print("not a # comment here!")\n') with run(str(f)) as h, and_exit(h): trigger_command_mode(h) h.press_and_enter(':comment') h.await_text('\nprint("not a # comment here!")\n')
def test_vim_save_on_exit_cancel_yn(run): with run() as h, and_exit(h): h.press('hello') h.await_text('hello') trigger_command_mode(h) h.press_and_enter(':q') h.await_text('file is modified - save [yes, no]?') h.press('^C') h.await_text('cancelled')
def test_command_mode_ctrl_k(run): with run() as h, and_exit(h): trigger_command_mode(h) h.press('hello world') h.await_text('\nhello world\n') h.press('^Left') h.press('Left') h.press('^K') h.await_text('\nhello\n') h.press('Enter')
def test_set_tabstop(run, setting): with run() as h, and_exit(h): h.press('a') h.press('Left') trigger_command_mode(h) h.press_and_enter(f':{setting} 2') h.await_text('updated!') h.press('Tab') h.await_text('\n a') h.await_cursor_position(x=2, y=1)
def test_add_comment_moves_cursor(run, ten_lines): with run(str(ten_lines)) as h, and_exit(h): h.press('End') h.await_cursor_position(x=6, y=1) trigger_command_mode(h) h.press_and_enter(':comment') h.await_cursor_position(x=8, y=1)
def test_repeated_command_mode_does_not_show_previous_command(run, tmpdir): f = tmpdir.join('f') with run(str(f)) as h, and_exit(h): h.press('ohai') trigger_command_mode(h) h.press_and_enter(':w') trigger_command_mode(h) h.await_text_missing(':w') h.press('Enter')
def test_write_and_quit(run, tmpdir): f = tmpdir.join('f') with run(str(f)) as h, and_exit(h): h.press('hello world') trigger_command_mode(h) h.press_and_enter(':wq') h.await_exit() assert f.read() == 'hello world\n'
def test_set_invalid_tabstop(run, tabsize): with run() as h, and_exit(h): h.press('a') h.press('Left') trigger_command_mode(h) h.press_and_enter(f':tabstop {tabsize}') h.await_text(f'invalid size: {tabsize}') h.press('Tab') h.await_text(' a') h.await_cursor_position(x=4, y=1)
def test_comment_partially_uncommented(run, ten_lines): with run(str(ten_lines)) as h, and_exit(h): h.press('Down') h.press('#') h.press('Up') h.press('S-Down') h.await_text('line_0\n#line_1\nline_2') trigger_command_mode(h) h.press_and_enter(':comment') h.await_text('# line_0\n# #line_1\nline_2\n')
def test_comment_empty_line_trailing_whitespace(run, tmpdir): f = tmpdir.join('f') f.write('1\n\n2\n') with run(str(f)) as h, and_exit(h): h.press('S-Down') h.press('S-Down') trigger_command_mode(h) h.press_and_enter(':comment') h.await_text('# 1\n#\n# 2')
def test_dedent_selection_with_noexpandtabs(run, tmpdir): f = tmpdir.join('f') f.write('1\n\t2\n\t\t3\n') with run(str(f)) as h, and_exit(h): trigger_command_mode(h) h.press_and_enter(':noexpandtabs') h.await_text('updated!') for _ in range(3): h.press('S-Down') h.press('BTab') h.press('^S') assert f.read() == '1\n2\n\t3\n'
def test_set_expandtabs(run, tmpdir): f = tmpdir.join('f') f.write('a') with run(str(f)) as h, and_exit(h): h.press('Left') trigger_command_mode(h) h.press_and_enter(':expandtabs') h.await_text('updated!') h.press('Tab') h.press('^S') assert f.read() == ' a\n'
def test_vim_save_on_exit(run, tmpdir): f = tmpdir.join('f') with run(str(f)) as h: h.press('hello') h.await_text('hello') trigger_command_mode(h) h.press_and_enter(':q') h.await_text('file is modified - save [yes, no]?') h.press('y') h.await_text(f'enter filename: ') h.press('Enter') h.await_exit()
def test_indent_with_expandtabs(run, tmpdir): f = tmpdir.join('f') f.write('a\nb\nc') with run(str(f)) as h, and_exit(h): trigger_command_mode(h) h.press_and_enter(':noexpandtabs') h.await_text('updated!') for _ in range(3): h.press('S-Down') h.press('Tab') h.press('^S') assert f.read() == '\ta\n\tb\n\tc\n'
def test_sort_does_not_include_blank_line_after(run, tmpdir): f = tmpdir.join('f') f.write('b\na\n\nd\nc\n') with run(str(f)) as h, and_exit(h): h.press('S-Down') h.press('S-Down') 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 f.read() == 'a\nb\n\nd\nc\n'
def test_do_not_move_if_cursor_before_comment(run, tmpdir): f = tmpdir.join('f') f.write('\t\tfoo') with run(str(f)) as h, and_exit(h): h.press('Right') h.await_cursor_position(x=4, y=1) trigger_command_mode(h) h.press_and_enter(':comment') h.await_cursor_position(x=4, y=1)
def test_comment_some_code_with_indentation(run, three_lines_with_indentation): with run(str(three_lines_with_indentation)) as h, and_exit(h): h.press('S-Down') trigger_command_mode(h) h.press_and_enter(':comment') h.await_text('# line_0\n# line_1\n line_2\n') h.press('S-Up') trigger_command_mode(h) h.press_and_enter(':comment') h.await_text('line_0\n line_1\n line_2\n')
def test_command_mode_backspace(run, 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_control_left(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=6, y=23) h.press('^Left') h.await_cursor_position(x=0, y=23) h.press('^Left') h.await_cursor_position(x=0, y=23) h.press('Right') h.await_cursor_position(x=1, y=23) h.press('^Left') h.await_cursor_position(x=0, y=23) h.press('^C')
def test_resizing_and_scrolling_in_command_mode(run): with run(width=20) as h, and_exit(h): h.press('a' * 15) h.await_text(f'\n{"a" * 15}\n') trigger_command_mode(h) h.press('b' * 15) h.await_text(f'\n{"b" * 15}\n') with h.resize(width=16, height=24): h.await_text('\n«aaaaaa\n') # the text contents h.await_text('\n«bbbbbb\n') # the text contents h.await_cursor_position(x=7, y=23) h.press('Left') h.await_cursor_position(x=14, y=23) h.await_text(f'\n{"b" * 15}\n') h.press('Enter')