Add indent / dedent

Resolves #27
This commit is contained in:
Anthony Sottile
2020-01-05 09:00:28 -08:00
parent b08f533554
commit 22db250ab8
2 changed files with 165 additions and 0 deletions

101
tests/indent_test.py Normal file
View File

@@ -0,0 +1,101 @@
from testing.runner import and_exit
from testing.runner import run
def test_indent_at_beginning_of_line():
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_indent_not_full_tab():
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_indent_fixes_eof():
with run() as h, and_exit(h):
h.press('Tab')
h.press('Down')
h.await_cursor_position(x=0, y=2)
def test_indent_selection(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_indent_selection_does_not_extend_mid_line_selection(ten_lines):
with run(str(ten_lines)) as h, and_exit(h):
h.press('Right')
h.press('S-Right')
h.press('Tab')
h.await_text('\n line_0\n')
h.await_cursor_position(x=6, y=1)
h.press('^K')
h.await_text('\n lne_0\n')
def test_indent_selection_leaves_blank_lines(tmpdir):
f = tmpdir.join('f')
f.write('1\n\n2\n\n3\n')
with run(str(f)) as h, and_exit(h):
for _ in range(3):
h.press('S-Down')
h.press('Tab')
h.press('^S')
assert f.read() == ' 1\n\n 2\n\n3\n'
def test_dedent_no_indentation():
with run() as h, and_exit(h):
h.press('a')
h.press('BTab')
h.await_text('\na\n')
h.await_cursor_position(x=1, y=1)
def test_dedent_exactly_one_indent():
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_dedent_selection(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_selection_does_not_make_selection_negative():
with run() as h, and_exit(h):
h.press('Tab')
h.press('hello')
h.press('Home')
h.press('Right')
h.press('S-Right')
h.press('BTab')
h.await_text('\nhello\n')
h.press('S-Right')
h.press('^K')
h.await_text('\nello\n')