summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Slenders <jonathan@slenders.be>2016-10-16 19:48:01 +0200
committerJonathan Slenders <jonathan@slenders.be>2016-10-16 19:48:01 +0200
commit9d84a2a09684fcda761599ffc98a987797b2c75a (patch)
treea3e5f534a96858e9f52bbd0296fa6d1d346c6e2f
parent5ab81d7aa5a8081725fd21563b489713719ab7dd (diff)
Added unit tests for Visual block editing in Vi mode.
-rw-r--r--tests/test_cli.py40
1 files changed, 38 insertions, 2 deletions
diff --git a/tests/test_cli.py b/tests/test_cli.py
index 32bca469..5f6bddc1 100644
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@ -28,7 +28,7 @@ def _history():
def _feed_cli_with_input(text, editing_mode=EditingMode.EMACS, clipboard=None,
- history=None):
+ history=None, multiline=False):
"""
Create a CommandLineInterface, feed it with the given user input and return
the CLI object.
@@ -45,7 +45,7 @@ def _feed_cli_with_input(text, editing_mode=EditingMode.EMACS, clipboard=None,
cli = CommandLineInterface(
application=Application(
buffer=Buffer(accept_action=AcceptAction.RETURN_DOCUMENT,
- history=history),
+ history=history, is_multiline=multiline),
editing_mode=editing_mode,
clipboard=clipboard or InMemoryClipboard(),
key_bindings_registry=KeyBindingManager.for_prompt().registry,
@@ -489,3 +489,39 @@ def test_vi_digraphs():
# C-K xxy (Unknown digraph.)
result, cli = feed('hello\x0bxxy\n')
assert result.text == 'helloy'
+
+
+def test_vi_block_editing():
+ " Test Vi Control-V style block insertion. "
+ feed = partial(_feed_cli_with_input, editing_mode=EditingMode.VI,
+ multiline=True)
+
+ operations = (
+ # Three lines of text.
+ '-line1\n-line2\n-line3\n-line4\n-line5\n-line6'
+ # Go to the second character of the second line.
+ '\x1bkkkkkkkj0l'
+ # Enter Visual block mode.
+ '\x16'
+ # Go down two more lines.
+ 'jj'
+ # Go 3 characters to the right.
+ 'lll'
+ # Go to insert mode.
+ 'insert' # (Will be replaced.)
+ # Insert stars.
+ '***'
+ # Escape again.
+ '\x1b\n')
+
+ # Control-I
+ result, cli = feed(operations.replace('insert', 'I'))
+
+ assert (result.text ==
+ '-line1\n-***line2\n-***line3\n-***line4\n-line5\n-line6')
+
+ # Control-A
+ result, cli = feed(operations.replace('insert', 'A'))
+
+ assert (result.text ==
+ '-line1\n-line***2\n-line***3\n-line***4\n-line5\n-line6')