diff options
author | Jonathan Slenders <jonathan@slenders.be> | 2017-01-01 13:38:58 +0100 |
---|---|---|
committer | Jonathan Slenders <jonathan@slenders.be> | 2017-04-02 15:41:04 +0200 |
commit | 26a6274f3f6f584c24fdcb44e416c1fbed2cdc0f (patch) | |
tree | 9a5e9a71dad9699db49a8e80a5fd985f2ea016bf /tests | |
parent | 8c3b54dfa382dbcc57b2d86ac3f37927b3fcd6bf (diff) |
prompt_toolkit 2.0 refactoring: rewrite of the architecture (part 1).
(>74 commits squashed)
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_buffer.py | 6 | ||||
-rw-r--r-- | tests/test_cli.py | 287 | ||||
-rw-r--r-- | tests/test_filter.py | 48 | ||||
-rw-r--r-- | tests/test_inputstream.py | 4 | ||||
-rw-r--r-- | tests/test_key_binding.py | 22 | ||||
-rw-r--r-- | tests/test_shortcuts.py | 2 | ||||
-rw-r--r-- | tests/test_style.py | 10 | ||||
-rw-r--r-- | tests/test_token.py | 29 | ||||
-rw-r--r-- | tests/test_utils.py | 5 | ||||
-rw-r--r-- | tests/test_vt100_output.py | 19 | ||||
-rw-r--r-- | tests/test_yank_nth_arg.py | 47 |
11 files changed, 264 insertions, 215 deletions
diff --git a/tests/test_buffer.py b/tests/test_buffer.py index a9cff190..71b60f3e 100644 --- a/tests/test_buffer.py +++ b/tests/test_buffer.py @@ -1,13 +1,17 @@ from __future__ import unicode_literals from prompt_toolkit.buffer import Buffer +from prompt_toolkit.eventloop.defaults import create_event_loop import pytest @pytest.fixture def _buffer(): - return Buffer() + loop = create_event_loop() + buff = Buffer(loop) + yield buff + loop.close() def test_initial(_buffer): diff --git a/tests/test_cli.py b/tests/test_cli.py index 68ca3d03..b108ba2c 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,21 +1,21 @@ # encoding: utf-8 """ -These are almost end-to-end tests. They create a CommandLineInterface -instance, feed it with some input and check the result. +These are almost end-to-end tests. They create a Prompt, feed it with some +input and check the result. """ from __future__ import unicode_literals -from prompt_toolkit.application import Application -from prompt_toolkit.buffer import Buffer, AcceptAction + +from functools import partial from prompt_toolkit.clipboard import InMemoryClipboard, ClipboardData -from prompt_toolkit.enums import DEFAULT_BUFFER, EditingMode -from prompt_toolkit.eventloop.posix import PosixEventLoop +from prompt_toolkit.enums import EditingMode +from prompt_toolkit.filters import ViInsertMode from prompt_toolkit.history import InMemoryHistory -from prompt_toolkit.input import PipeInput -from prompt_toolkit.interface import CommandLineInterface -from prompt_toolkit.key_binding.manager import KeyBindingManager +from prompt_toolkit.input.vt100 import PipeInput +from prompt_toolkit.input.vt100_parser import ANSI_SEQUENCES +from prompt_toolkit.key_binding.bindings.named_commands import prefix_meta +from prompt_toolkit.key_binding.key_bindings import KeyBindings from prompt_toolkit.output import DummyOutput -from prompt_toolkit.terminal.vt100_input import ANSI_SEQUENCES -from functools import partial +from prompt_toolkit.shortcuts import Prompt import pytest @@ -27,50 +27,39 @@ def _history(): return h -def _feed_cli_with_input(text, editing_mode=EditingMode.EMACS, clipboard=None, - history=None, multiline=False, check_line_ending=True, - pre_run_callback=None): +def _feed_cli_with_input( + text, editing_mode=EditingMode.EMACS, clipboard=None, history=None, + multiline=False, check_line_ending=True, extra_key_bindings=None): """ - Create a CommandLineInterface, feed it with the given user input and return - the CLI object. + Create a Prompt, feed it with the given user input and return the CLI + object. - This returns a (result, CLI) tuple. + This returns a (result, Application) tuple. """ # If the given text doesn't end with a newline, the interface won't finish. if check_line_ending: - assert text.endswith('\n') + assert text.endswith('\r') + + inp = PipeInput() - loop = PosixEventLoop() try: - inp = PipeInput() inp.send_text(text) - cli = CommandLineInterface( - application=Application( - buffer=Buffer(accept_action=AcceptAction.RETURN_DOCUMENT, - history=history, is_multiline=multiline), - editing_mode=editing_mode, - clipboard=clipboard or InMemoryClipboard(), - key_bindings_registry=KeyBindingManager.for_prompt().registry, - ), - eventloop=loop, - input=inp, - output=DummyOutput()) - - if pre_run_callback: - pre_run_callback(cli) - - result = cli.run() - return result, cli + p = Prompt(input=inp, output=DummyOutput(), editing_mode=editing_mode, + history=history, multiline=multiline, clipboard=clipboard, + extra_key_bindings=extra_key_bindings) + + result = p.prompt() + return p._default_buffer.document, p.app + finally: - loop.close() inp.close() def test_simple_text_input(): # Simple text input, followed by enter. - result, cli = _feed_cli_with_input('hello\n') + result, cli = _feed_cli_with_input('hello\r') assert result.text == 'hello' - assert cli.buffers[DEFAULT_BUFFER].text == 'hello' + assert cli.current_buffer.text == 'hello' def test_emacs_cursor_movements(): @@ -78,128 +67,126 @@ def test_emacs_cursor_movements(): Test cursor movements with Emacs key bindings. """ # ControlA (beginning-of-line) - result, cli = _feed_cli_with_input('hello\x01X\n') + result, cli = _feed_cli_with_input('hello\x01X\r') assert result.text == 'Xhello' # ControlE (end-of-line) - result, cli = _feed_cli_with_input('hello\x01X\x05Y\n') + result, cli = _feed_cli_with_input('hello\x01X\x05Y\r') assert result.text == 'XhelloY' # ControlH or \b - result, cli = _feed_cli_with_input('hello\x08X\n') + result, cli = _feed_cli_with_input('hello\x08X\r') assert result.text == 'hellX' # Delete. (Left, left, delete) - result, cli = _feed_cli_with_input('hello\x1b[D\x1b[D\x1b[3~\n') + result, cli = _feed_cli_with_input('hello\x1b[D\x1b[D\x1b[3~\r') assert result.text == 'helo' # Left. - result, cli = _feed_cli_with_input('hello\x1b[DX\n') + result, cli = _feed_cli_with_input('hello\x1b[DX\r') assert result.text == 'hellXo' # ControlA, right - result, cli = _feed_cli_with_input('hello\x01\x1b[CX\n') + result, cli = _feed_cli_with_input('hello\x01\x1b[CX\r') assert result.text == 'hXello' # ControlA, right - result, cli = _feed_cli_with_input('hello\x01\x1b[CX\n') + result, cli = _feed_cli_with_input('hello\x01\x1b[CX\r') assert result.text == 'hXello' # ControlB (backward-char) - result, cli = _feed_cli_with_input('hello\x02X\n') + result, cli = _feed_cli_with_input('hello\x02X\r') assert result.text == 'hellXo' # ControlF (forward-char) - result, cli = _feed_cli_with_input('hello\x01\x06X\n') + result, cli = _feed_cli_with_input('hello\x01\x06X\r') assert result.text == 'hXello' # ControlC: raise KeyboardInterrupt. with pytest.raises(KeyboardInterrupt): - result, cli = _feed_cli_with_input('hello\x03\n') - assert result.text == 'hello' + result, cli = _feed_cli_with_input('hello\x03\r') # ControlD without any input: raises EOFError. with pytest.raises(EOFError): - result, cli = _feed_cli_with_input('\x04\n') - assert result.text == 'hello' + result, cli = _feed_cli_with_input('\x04\r') # ControlD: delete after cursor. - result, cli = _feed_cli_with_input('hello\x01\x04\n') + result, cli = _feed_cli_with_input('hello\x01\x04\r') assert result.text == 'ello' # ControlD at the end of the input ssshould not do anything. - result, cli = _feed_cli_with_input('hello\x04\n') + result, cli = _feed_cli_with_input('hello\x04\r') assert result.text == 'hello' # Left, Left, ControlK (kill-line) - result, cli = _feed_cli_with_input('hello\x1b[D\x1b[D\x0b\n') + result, cli = _feed_cli_with_input('hello\x1b[D\x1b[D\x0b\r') assert result.text == 'hel' # Left, Left Esc- ControlK (kill-line, but negative) - result, cli = _feed_cli_with_input('hello\x1b[D\x1b[D\x1b-\x0b\n') + result, cli = _feed_cli_with_input('hello\x1b[D\x1b[D\x1b-\x0b\r') assert result.text == 'lo' # ControlL: should not influence the result. - result, cli = _feed_cli_with_input('hello\x0c\n') + result, cli = _feed_cli_with_input('hello\x0c\r') assert result.text == 'hello' # ControlRight (forward-word) - result, cli = _feed_cli_with_input('hello world\x01X\x1b[1;5CY\n') + result, cli = _feed_cli_with_input('hello world\x01X\x1b[1;5CY\r') assert result.text == 'XhelloY world' # ContrlolLeft (backward-word) - result, cli = _feed_cli_with_input('hello world\x1b[1;5DY\n') + result, cli = _feed_cli_with_input('hello world\x1b[1;5DY\r') assert result.text == 'hello Yworld' # <esc>-f with argument. (forward-word) - result, cli = _feed_cli_with_input('hello world abc def\x01\x1b3\x1bfX\n') + result, cli = _feed_cli_with_input('hello world abc def\x01\x1b3\x1bfX\r') assert result.text == 'hello world abcX def' # <esc>-f with negative argument. (forward-word) - result, cli = _feed_cli_with_input('hello world abc def\x1b-\x1b3\x1bfX\n') + result, cli = _feed_cli_with_input('hello world abc def\x1b-\x1b3\x1bfX\r') assert result.text == 'hello Xworld abc def' # <esc>-b with argument. (backward-word) - result, cli = _feed_cli_with_input('hello world abc def\x1b3\x1bbX\n') + result, cli = _feed_cli_with_input('hello world abc def\x1b3\x1bbX\r') assert result.text == 'hello Xworld abc def' # <esc>-b with negative argument. (backward-word) - result, cli = _feed_cli_with_input('hello world abc def\x01\x1b-\x1b3\x1bbX\n') + result, cli = _feed_cli_with_input('hello world abc def\x01\x1b-\x1b3\x1bbX\r') assert result.text == 'hello world abc Xdef' # ControlW (kill-word / unix-word-rubout) - result, cli = _feed_cli_with_input('hello world\x17\n') + result, cli = _feed_cli_with_input('hello world\x17\r') assert result.text == 'hello ' assert cli.clipboard.get_data().text == 'world' - result, cli = _feed_cli_with_input('test hello world\x1b2\x17\n') + result, cli = _feed_cli_with_input('test hello world\x1b2\x17\r') assert result.text == 'test ' # Escape Backspace (unix-word-rubout) - result, cli = _feed_cli_with_input('hello world\x1b\x7f\n') + result, cli = _feed_cli_with_input('hello world\x1b\x7f\r') assert result.text == 'hello ' assert cli.clipboard.get_data().text == 'world' - result, cli = _feed_cli_with_input('hello world\x1b\x08\n') + result, cli = _feed_cli_with_input('hello world\x1b\x08\r') assert result.text == 'hello ' assert cli.clipboard.get_data().text == 'world' # Backspace (backward-delete-char) - result, cli = _feed_cli_with_input('hello world\x7f\n') + result, cli = _feed_cli_with_input('hello world\x7f\r') assert result.text == 'hello worl' assert result.cursor_position == len('hello worl') - result, cli = _feed_cli_with_input('hello world\x08\n') + result, cli = _feed_cli_with_input('hello world\x08\r') assert result.text == 'hello worl' assert result.cursor_position == len('hello worl') # Delete (delete-char) - result, cli = _feed_cli_with_input('hello world\x01\x1b[3~\n') + result, cli = _feed_cli_with_input('hello world\x01\x1b[3~\r') assert result.text == 'ello world' assert result.cursor_position == 0 # Escape-\\ (delete-horizontal-space) - result, cli = _feed_cli_with_input('hello world\x1b8\x02\x1b\\\n') + result, cli = _feed_cli_with_input('hello world\x1b8\x02\x1b\\\r') assert result.text == 'helloworld' assert result.cursor_position == len('hello') @@ -207,122 +194,122 @@ def test_emacs_cursor_movements(): def test_emacs_yank(): # ControlY (yank) c = InMemoryClipboard(ClipboardData('XYZ')) - result, cli = _feed_cli_with_input('hello\x02\x19\n', clipboard=c) + result, cli = _feed_cli_with_input('hello\x02\x19\r', clipboard=c) assert result.text == 'hellXYZo' assert result.cursor_position == len('hellXYZ') def test_quoted_insert(): # ControlQ - ControlB (quoted-insert) - result, cli = _feed_cli_with_input('hello\x11\x02\n') + result, cli = _feed_cli_with_input('hello\x11\x02\r') assert result.text == 'hello\x02' def test_transformations(): # Meta-c (capitalize-word) - result, cli = _feed_cli_with_input('hello world\01\x1bc\n') + result, cli = _feed_cli_with_input('hello world\01\x1bc\r') assert result.text == 'Hello world' assert result.cursor_position == len('Hello') # Meta-u (uppercase-word) - result, cli = _feed_cli_with_input('hello world\01\x1bu\n') + result, cli = _feed_cli_with_input('hello world\01\x1bu\r') assert result.text == 'HELLO world' assert result.cursor_position == len('Hello') # Meta-u (downcase-word) - result, cli = _feed_cli_with_input('HELLO WORLD\01\x1bl\n') + result, cli = _feed_cli_with_input('HELLO WORLD\01\x1bl\r') assert result.text == 'hello WORLD' assert result.cursor_position == len('Hello') # ControlT (transpose-chars) - result, cli = _feed_cli_with_input('hello\x14\n') + result, cli = _feed_cli_with_input('hello\x14\r') assert result.text == 'helol' assert result.cursor_position == len('hello') # Left, Left, Control-T (transpose-chars) - result, cli = _feed_cli_with_input('abcde\x1b[D\x1b[D\x14\n') + result, cli = _feed_cli_with_input('abcde\x1b[D\x1b[D\x14\r') assert result.text == 'abdce' assert result.cursor_position == len('abcd') def test_emacs_other_bindings(): # Transpose characters. - result, cli = _feed_cli_with_input('abcde\x14X\n') # Ctrl-T + result, cli = _feed_cli_with_input('abcde\x14X\r') # Ctrl-T assert result.text == 'abcedX' # Left, Left, Transpose. (This is slightly different.) - result, cli = _feed_cli_with_input('abcde\x1b[D\x1b[D\x14X\n') + result, cli = _feed_cli_with_input('abcde\x1b[D\x1b[D\x14X\r') assert result.text == 'abdcXe' # Clear before cursor. - result, cli = _feed_cli_with_input('hello\x1b[D\x1b[D\x15X\n') + result, cli = _feed_cli_with_input('hello\x1b[D\x1b[D\x15X\r') assert result.text == 'Xlo' # unix-word-rubout: delete word before the cursor. # (ControlW). - result, cli = _feed_cli_with_input('hello world test\x17X\n') + result, cli = _feed_cli_with_input('hello world test\x17X\r') assert result.text == 'hello world X' - result, cli = _feed_cli_with_input('hello world /some/very/long/path\x17X\n') + result, cli = _feed_cli_with_input('hello world /some/very/long/path\x17X\r') assert result.text == 'hello world X' # (with argument.) - result, cli = _feed_cli_with_input('hello world test\x1b2\x17X\n') + result, cli = _feed_cli_with_input('hello world test\x1b2\x17X\r') assert result.text == 'hello X' - result, cli = _feed_cli_with_input('hello world /some/very/long/path\x1b2\x17X\n') + result, cli = _feed_cli_with_input('hello world /some/very/long/path\x1b2\x17X\r') assert result.text == 'hello X' # backward-kill-word: delete word before the cursor. # (Esc-ControlH). - result, cli = _feed_cli_with_input('hello world /some/very/long/path\x1b\x08X\n') + result, cli = _feed_cli_with_input('hello world /some/very/long/path\x1b\x08X\r') assert result.text == 'hello world /some/very/long/X' # (with arguments.) - result, cli = _feed_cli_with_input('hello world /some/very/long/path\x1b3\x1b\x08X\n') + result, cli = _feed_cli_with_input('hello world /some/very/long/path\x1b3\x1b\x08X\r') assert result.text == 'hello world /some/very/X' def test_controlx_controlx(): # At the end: go to the start of the line. - result, cli = _feed_cli_with_input('hello world\x18\x18X\n') + result, cli = _feed_cli_with_input('hello world\x18\x18X\r') assert result.text == 'Xhello world' assert result.cursor_position == 1 # At the start: go to the end of the line. - result, cli = _feed_cli_with_input('hello world\x01\x18\x18X\n') + result, cli = _feed_cli_with_input('hello world\x01\x18\x18X\r') assert result.text == 'hello worldX' # Left, Left Control-X Control-X: go to the end of the line. - result, cli = _feed_cli_with_input('hello world\x1b[D\x1b[D\x18\x18X\n') + result, cli = _feed_cli_with_input('hello world\x1b[D\x1b[D\x18\x18X\r') assert result.text == 'hello worldX' def test_emacs_history_bindings(): # Adding a new item to the history. history = _history() - result, cli = _feed_cli_with_input('new input\n', history=history) + result, cli = _feed_cli_with_input('new input\r', history=history) assert result.text == 'new input' history.strings[-1] == 'new input' # Go up in history, and accept the last item. - result, cli = _feed_cli_with_input('hello\x1b[A\n', history=history) + result, cli = _feed_cli_with_input('hello\x1b[A\r', history=history) assert result.text == 'new input' # Esc< (beginning-of-history) - result, cli = _feed_cli_with_input('hello\x1b<\n', history=history) + result, cli = _feed_cli_with_input('hello\x1b<\r', history=history) assert result.text == 'line1 first input' # Esc> (end-of-history) - result, cli = _feed_cli_with_input('another item\x1b[A\x1b[a\x1b>\n', history=history) + result, cli = _feed_cli_with_input('another item\x1b[A\x1b[a\x1b>\r', history=history) assert result.text == 'another item' # ControlUp (previous-history) - result, cli = _feed_cli_with_input('\x1b[1;5A\n', history=history) + result, cli = _feed_cli_with_input('\x1b[1;5A\r', history=history) assert result.text == 'another item' # Esc< ControlDown (beginning-of-history, next-history) - result, cli = _feed_cli_with_input('\x1b<\x1b[1;5B\n', history=history) + result, cli = _feed_cli_with_input('\x1b<\x1b[1;5B\r', history=history) assert result.text == 'line2 second input' @@ -330,11 +317,11 @@ def test_emacs_reverse_search(): history = _history() # ControlR (reverse-search-history) - result, cli = _feed_cli_with_input('\x12input\n\n', history=history) + result, cli = _feed_cli_with_input('\x12input\r\r', history=history) assert result.text == 'line3 third input' # Hitting ControlR twice. - result, cli = _feed_cli_with_input('\x12input\x12\n\n', history=history) + result, cli = _feed_cli_with_input('\x12input\x12\r\r', history=history) assert result.text == 'line2 second input' @@ -343,27 +330,27 @@ def test_emacs_arguments(): Test various combinations of arguments in Emacs mode. """ # esc 4 - result, cli = _feed_cli_with_input('\x1b4x\n') + result, cli = _feed_cli_with_input('\x1b4x\r') assert result.text == 'xxxx' # esc 4 4 - result, cli = _feed_cli_with_input('\x1b44x\n') + result, cli = _feed_cli_with_input('\x1b44x\r') assert result.text == 'x' * 44 # esc 4 esc 4 - result, cli = _feed_cli_with_input('\x1b4\x1b4x\n') + result, cli = _feed_cli_with_input('\x1b4\x1b4x\r') assert result.text == 'x' * 44 # esc - right (-1 position to the right, equals 1 to the left.) - result, cli = _feed_cli_with_input('aaaa\x1b-\x1b[Cbbbb\n') + result, cli = _feed_cli_with_input('aaaa\x1b-\x1b[Cbbbb\r') assert result.text == 'aaabbbba' # esc - 3 right - result, cli = _feed_cli_with_input('aaaa\x1b-3\x1b[Cbbbb\n') + result, cli = _feed_cli_with_input('aaaa\x1b-3\x1b[Cbbbb\r') assert result.text == 'abbbbaaa' # esc - - - 3 right - result, cli = _feed_cli_with_input('aaaa\x1b---3\x1b[Cbbbb\n') + result, cli = _feed_cli_with_input('aaaa\x1b---3\x1b[Cbbbb\r') assert result.text == 'abbbbaaa' @@ -378,13 +365,13 @@ def test_emacs_arguments_for_all_commands(): if key != '\x1b[200~': try: # Note: we add an 'X' after the key, because Ctrl-Q (quoted-insert) - # expects something to follow. We add an additional \n, because + # expects something to follow. We add an additional \r, because # Ctrl-R and Ctrl-S (reverse-search) expect that. result, cli = _feed_cli_with_input( - 'hello\x1b4' + key + 'X\n\n') + 'hello\x1b4' + key + 'X\r\r') result, cli = _feed_cli_with_input( - 'hello\x1b-' + key + 'X\n\n') + 'hello\x1b-' + key + 'X\r\r') except KeyboardInterrupt: # This exception should only be raised for Ctrl-C assert key == '\x03' @@ -405,16 +392,16 @@ def test_emacs_kill_ring(): '\x19' ) - result, cli = _feed_cli_with_input(operations + '\n') + result, cli = _feed_cli_with_input(operations + '\r') assert result.text == 'ghi' - result, cli = _feed_cli_with_input(operations + '\x1by\n') + result, cli = _feed_cli_with_input(operations + '\x1by\r') assert result.text == 'def' - result, cli = _feed_cli_with_input(operations + '\x1by\x1by\n') + result, cli = _feed_cli_with_input(operations + '\x1by\x1by\r') assert result.text == 'abc' - result, cli = _feed_cli_with_input(operations + '\x1by\x1by\x1by\n') + result, cli = _feed_cli_with_input(operations + '\x1by\x1by\x1by\r') assert result.text == 'ghi' @@ -424,7 +411,7 @@ def test_emacs_insert_comment(): assert result.text == '#hello' result, cli = _feed_cli_with_input( - 'hello\nworld\x1b#', check_line_ending=False, multiline=True) + 'hello\rworld\x1b#', check_line_ending=False, multiline=True) assert result.text == '#hello\n#world' @@ -437,7 +424,7 @@ def test_emacs_record_macro(): ' ' '\x18e' # Execute macro. '\x18e' # Execute macro. - '\n' + '\r' ) result, cli = _feed_cli_with_input(operations) @@ -446,29 +433,27 @@ def test_emacs_record_macro(): def test_prefix_meta(): # Test the prefix-meta command. - def setup_keybindings(cli): - from prompt_toolkit.key_binding.bindings.named_commands import prefix_meta - from prompt_toolkit.filters import ViInsertMode - cli.application.key_bindings_registry.add_binding('j', 'j', filter=ViInsertMode())(prefix_meta) + b = KeyBindings() + b.add('j', 'j', filter=ViInsertMode())(prefix_meta) result, cli = _feed_cli_with_input( - 'hellojjIX\n', pre_run_callback=setup_keybindings, editing_mode=EditingMode.VI) + 'hellojjIX\r', extra_key_bindings=b, editing_mode=EditingMode.VI) assert result.text == 'Xhello' def test_bracketed_paste(): - result, cli = _feed_cli_with_input('\x1b[200~hello world\x1b[201~\n') + result, cli = _feed_cli_with_input('\x1b[200~hello world\x1b[201~\r') assert result.text == 'hello world' - result, cli = _feed_cli_with_input('\x1b[200~hello\nworld\x1b[201~\x1b\n') + result, cli = _feed_cli_with_input('\x1b[200~hello\rworld\x1b[201~\x1b\r') assert result.text == 'hello\nworld' # With \r\n endings. - result, cli = _feed_cli_with_input('\x1b[200~hello\r\nworld\x1b[201~\x1b\n') + result, cli = _feed_cli_with_input('\x1b[200~hello\r\nworld\x1b[201~\x1b\r') assert result.text == 'hello\nworld' - # With \r endings. - result, cli = _feed_cli_with_input('\x1b[200~hello\rworld\x1b[201~\x1b\n') + # With \n endings. + result, cli = _feed_cli_with_input('\x1b[200~hello\nworld\x1b[201~\x1b\r') assert result.text == 'hello\nworld' @@ -478,44 +463,44 @@ def test_vi_cursor_movements(): """ feed = partial(_feed_cli_with_input, editing_mode=EditingMode.VI) - result, cli = feed('\x1b\n') + result, cli = feed('\x1b\r') assert result.text == '' assert cli.editing_mode == EditingMode.VI # Esc h a X - result, cli = feed('hello\x1bhaX\n') + result, cli = feed('hello\x1bhaX\r') assert result.text == 'hellXo' # Esc I X - result, cli = feed('hello\x1bIX\n') + result, cli = feed('hello\x1bIX\r') assert result.text == 'Xhello' # Esc I X - result, cli = feed('hello\x1bIX\n') + result, cli = feed('hello\x1bIX\r') assert result.text == 'Xhello' # Esc 2hiX - result, cli = feed('hello\x1b2hiX\n') + result, cli = feed('hello\x1b2hiX\r') assert result.text == 'heXllo' # Esc 2h2liX - result, cli = feed('hello\x1b2h2liX\n') + result, cli = feed('hello\x1b2h2liX\r') assert result.text == 'hellXo' # Esc \b\b - result, cli = feed('hello\b\b\n') + result, cli = feed('hello\b\b\r') assert result.text == 'hel' # Esc \b\b - result, cli = feed('hello\b\b\n') + result, cli = feed('hello\b\b\r') assert result.text == 'hel' # Esc 2h D - result, cli = feed('hello\x1b2hD\n') + result, cli = feed('hello\x1b2hD\r') assert result.text == 'he' - # Esc 2h rX \n - result, cli = feed('hello\x1b2hrX\n') + # Esc 2h rX \r + result, cli = feed('hello\x1b2hrX\r') assert result.text == 'heXlo' @@ -523,15 +508,15 @@ def test_vi_operators(): feed = partial(_feed_cli_with_input, editing_mode=EditingMode.VI) # Esc g~0 - result, cli = feed('hello\x1bg~0\n') + result, cli = feed('hello\x1bg~0\r') assert result.text == 'HELLo' # Esc gU0 - result, cli = feed('hello\x1bgU0\n') + result, cli = feed('hello\x1bgU0\r') assert result.text == 'HELLo' # Esc d0 - result, cli = feed('hello\x1bd0\n') + result, cli = feed('hello\x1bd0\r') assert result.text == 'o' @@ -539,23 +524,23 @@ def test_vi_text_objects(): feed = partial(_feed_cli_with_input, editing_mode=EditingMode.VI) # Esc gUgg - result, cli = feed('hello\x1bgUgg\n') + result, cli = feed('hello\x1bgUgg\r') assert result.text == 'HELLO' # Esc gUU - result, cli = feed('hello\x1bgUU\n') + result, cli = feed('hello\x1bgUU\r') assert result.text == 'HELLO' # Esc di( - result, cli = feed('before(inside)after\x1b8hdi(\n') + result, cli = feed('before(inside)after\x1b8hdi(\r') assert result.text == 'before()after' # Esc di[ - result, cli = feed('before[inside]after\x1b8hdi[\n') + result, cli = feed('before[inside]after\x1b8hdi[\r') assert result.text == 'before[]after' # Esc da( - result, cli = feed('before(inside)after\x1b8hda(\n') + result, cli = feed('before(inside)after\x1b8hda(\r') assert result.text == 'beforeafter' @@ -563,19 +548,19 @@ def test_vi_digraphs(): feed = partial(_feed_cli_with_input, editing_mode=EditingMode.VI) # C-K o/ - result, cli = feed('hello\x0bo/\n') + result, cli = feed('hello\x0bo/\r') assert result.text == 'helloø' # C-K /o (reversed input.) - result, cli = feed('hello\x0b/o\n') + result, cli = feed('hello\x0b/o\r') assert result.text == 'helloø' # C-K e: - result, cli = feed('hello\x0be:\n') + result, cli = feed('hello\x0be:\r') assert result.text == 'helloë' # C-K xxy (Unknown digraph.) - result, cli = feed('hello\x0bxxy\n') + result, cli = feed('hello\x0bxxy\r') assert result.text == 'helloy' @@ -586,7 +571,7 @@ def test_vi_block_editing(): operations = ( # Three lines of text. - '-line1\n-line2\n-line3\n-line4\n-line5\n-line6' + '-line1\r-line2\r-line3\r-line4\r-line5\r-line6' # Go to the second character of the second line. '\x1bkkkkkkkj0l' # Enter Visual block mode. @@ -600,7 +585,7 @@ def test_vi_block_editing(): # Insert stars. '***' # Escape again. - '\x1b\n') + '\x1b\r') # Control-I result, cli = feed(operations.replace('insert', 'I')) @@ -619,11 +604,11 @@ def test_vi_character_paste(): feed = partial(_feed_cli_with_input, editing_mode=EditingMode.VI) # Test 'p' character paste. - result, cli = feed('abcde\x1bhhxp\n') + result, cli = feed('abcde\x1bhhxp\r') assert result.text == 'abdce' assert result.cursor_position == 3 # Test 'P' character paste. - result, cli = feed('abcde\x1bhhxP\n') + result, cli = feed('abcde\x1bhhxP\r') assert result.text == 'abcde' assert result.cursor_position == 2 diff --git a/tests/test_filter.py b/tests/test_filter.py index 5aee62a9..aed6e4d3 100644 --- a/tests/test_filter.py +++ b/tests/test_filter.py @@ -1,7 +1,7 @@ from __future__ import unicode_literals from prompt_toolkit.filters import Condition, Never, Always, Filter -from prompt_toolkit.filters.types import CLIFilter, SimpleFilter -from prompt_toolkit.filters.utils import to_cli_filter, to_simple_filter +from prompt_toolkit.filters.types import AppFilter, SimpleFilter +from prompt_toolkit.filters.utils import to_app_filter, to_simple_filter from prompt_toolkit.filters.cli import HasArg, HasFocus, HasSelection import pytest @@ -93,52 +93,52 @@ def test_and(): assert c3() == (a and b) -def test_cli_filter(): +def test_app_filter(): c1 = Condition(lambda cli: True) - assert isinstance(c1, CLIFilter) + assert isinstance(c1, AppFilter) assert not isinstance(c1, SimpleFilter) c2 = Condition(lambda: True) - assert not isinstance(c2, CLIFilter) + assert not isinstance(c2, AppFilter) assert isinstance(c2, SimpleFilter) c3 = c1 | c2 - assert not isinstance(c3, CLIFilter) + assert not isinstance(c3, AppFilter) assert not isinstance(c3, SimpleFilter) c4 = Condition(lambda cli: True) c5 = Condition(lambda cli: True) c6 = c4 & c5 c7 = c4 | c5 - assert isinstance(c6, CLIFilter) - assert isinstance(c7, CLIFilter) + assert isinstance(c6, AppFilter) + assert isinstance(c7, AppFilter) assert not isinstance(c6, SimpleFilter) assert not isinstance(c7, SimpleFilter) c8 = Condition(lambda *args: True) - assert isinstance(c8, CLIFilter) + assert isinstance(c8, AppFilter) assert isinstance(c8, SimpleFilter) -def test_to_cli_filter(): - f1 = to_cli_filter(True) - f2 = to_cli_filter(False) - f3 = to_cli_filter(Condition(lambda cli: True)) - f4 = to_cli_filter(Condition(lambda cli: False)) +def test_to_app_filter(): + f1 = to_app_filter(True) + f2 = to_app_filter(False) + f3 = to_app_filter(Condition(lambda cli: True)) + f4 = to_app_filter(Condition(lambda cli: False)) - assert isinstance(f1, CLIFilter) - assert isinstance(f2, CLIFilter) - assert isinstance(f3, CLIFilter) - assert isinstance(f4, CLIFilter) + assert isinstance(f1, AppFilter) + assert isinstance(f2, AppFilter) + assert isinstance(f3, AppFilter) + assert isinstance(f4, AppFilter) assert f1(None) assert not f2(None) assert f3(None) assert not f4(None) with pytest.raises(TypeError): - to_cli_filter(4) + to_app_filter(4) with pytest.raises(TypeError): - to_cli_filter(Condition(lambda: True)) + to_app_filter(Condition(lambda: True)) def test_to_simple_filter(): @@ -162,7 +162,7 @@ def test_to_simple_filter(): to_simple_filter(Condition(lambda cli: True)) -def test_cli_filters(): - assert isinstance(HasArg(), CLIFilter) - assert isinstance(HasFocus('BUFFER_NAME'), CLIFilter) - assert isinstance(HasSelection(), CLIFilter) +def test_app_filters(): + assert isinstance(HasArg(), AppFilter) + assert isinstance(HasFocus('BUFFER_NAME'), AppFilter) + assert isinstance(HasSelection(), AppFilter) diff --git a/tests/test_inputstream.py b/tests/test_inputstream.py index de10c0f9..31770355 100644 --- a/tests/test_inputstream.py +++ b/tests/test_inputstream.py @@ -1,6 +1,6 @@ from __future__ import unicode_literals -from prompt_toolkit.terminal.vt100_input import InputStream +from prompt_toolkit.input.vt100 import Vt100Parser from prompt_toolkit.keys import Keys import pytest @@ -22,7 +22,7 @@ def processor(): @pytest.fixture def stream(processor): - return InputStream(processor.feed_key) + return Vt100Parser(processor.feed_key) def test_control_keys(processor, stream): diff --git a/tests/test_key_binding.py b/tests/test_key_binding.py index 04f6b5f8..4878756e 100644 --- a/tests/test_key_binding.py +++ b/tests/test_key_binding.py @@ -1,7 +1,7 @@ from __future__ import unicode_literals -from prompt_toolkit.key_binding.input_processor import InputProcessor, KeyPress -from prompt_toolkit.key_binding.registry import Registry +from prompt_toolkit.key_binding.key_processor import KeyProcessor, KeyPress +from prompt_toolkit.key_binding.key_bindings import KeyBindings from prompt_toolkit.keys import Keys import pytest @@ -24,21 +24,21 @@ def handlers(): @pytest.fixture -def registry(handlers): - registry = Registry() - registry.add_binding( +def bindings(handlers): + bindings = KeyBindings() + bindings.add( Keys.ControlX, Keys.ControlC)(handlers.controlx_controlc) - registry.add_binding(Keys.ControlX)(handlers.control_x) - registry.add_binding(Keys.ControlD)(handlers.control_d) - registry.add_binding( + bindings.add(Keys.ControlX)(handlers.control_x) + bindings.add(Keys.ControlD)(handlers.control_d) + bindings.add( Keys.ControlSquareClose, Keys.Any)(handlers.control_square_close_any) - return registry + return bindings @pytest.fixture -def processor(registry): - return InputProcessor(registry, lambda: None) +def processor(bindings): + return KeyProcessor(bindings, lambda: None) de |