Add :sort command
This commit is contained in:
@@ -2,17 +2,7 @@ import pytest
|
||||
|
||||
from testing.runner import and_exit
|
||||
from testing.runner import run
|
||||
|
||||
|
||||
def trigger_command_mode(h):
|
||||
# in order to enter a steady state, trigger an unknown key first and then
|
||||
# press escape to open the command mode. this is necessary as `Escape` is
|
||||
# the start of "escape sequences" and sending characters too quickly will
|
||||
# be interpreted as a single keypress
|
||||
h.press('^J')
|
||||
h.await_text('unknown key')
|
||||
h.press('Escape')
|
||||
h.await_text_missing('unknown key')
|
||||
from testing.runner import trigger_command_mode
|
||||
|
||||
|
||||
def test_quit_via_colon_q():
|
||||
|
||||
45
tests/sort_test.py
Normal file
45
tests/sort_test.py
Normal file
@@ -0,0 +1,45 @@
|
||||
import pytest
|
||||
|
||||
from testing.runner import and_exit
|
||||
from testing.runner import run
|
||||
from testing.runner import trigger_command_mode
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def unsorted(tmpdir):
|
||||
f = tmpdir.join('f')
|
||||
f.write('d\nb\nc\na\n')
|
||||
return f
|
||||
|
||||
|
||||
def test_sort_entire_file(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() == 'a\nb\nc\nd\n'
|
||||
|
||||
|
||||
def test_sort_selection(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_sort_selection_does_not_include_eof(unsorted):
|
||||
with run(str(unsorted)) as h, and_exit(h):
|
||||
for _ in range(5):
|
||||
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() == 'a\nb\nc\nd\n'
|
||||
Reference in New Issue
Block a user