test_cli.py 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  1. # encoding: utf-8
  2. """
  3. These are almost end-to-end tests. They create a CommandLineInterface
  4. instance, feed it with some input and check the result.
  5. """
  6. from __future__ import unicode_literals
  7. from prompt_toolkit.application import Application
  8. from prompt_toolkit.buffer import Buffer, AcceptAction
  9. from prompt_toolkit.clipboard import InMemoryClipboard, ClipboardData
  10. from prompt_toolkit.enums import DEFAULT_BUFFER, EditingMode
  11. from prompt_toolkit.eventloop.posix import PosixEventLoop
  12. from prompt_toolkit.history import InMemoryHistory
  13. from prompt_toolkit.input import PipeInput
  14. from prompt_toolkit.interface import CommandLineInterface
  15. from prompt_toolkit.key_binding.manager import KeyBindingManager
  16. from prompt_toolkit.output import DummyOutput
  17. from prompt_toolkit.terminal.vt100_input import ANSI_SEQUENCES
  18. from functools import partial
  19. import pytest
  20. def _history():
  21. h = InMemoryHistory()
  22. h.append('line1 first input')
  23. h.append('line2 second input')
  24. h.append('line3 third input')
  25. return h
  26. def _feed_cli_with_input(text, editing_mode=EditingMode.EMACS, clipboard=None,
  27. history=None, multiline=False, check_line_ending=True,
  28. pre_run_callback=None):
  29. """
  30. Create a CommandLineInterface, feed it with the given user input and return
  31. the CLI object.
  32. This returns a (result, CLI) tuple.
  33. """
  34. # If the given text doesn't end with a newline, the interface won't finish.
  35. if check_line_ending:
  36. assert text.endswith('\n')
  37. loop = PosixEventLoop()
  38. try:
  39. inp = PipeInput()
  40. inp.send_text(text)
  41. cli = CommandLineInterface(
  42. application=Application(
  43. buffer=Buffer(accept_action=AcceptAction.RETURN_DOCUMENT,
  44. history=history, is_multiline=multiline),
  45. editing_mode=editing_mode,
  46. clipboard=clipboard or InMemoryClipboard(),
  47. key_bindings_registry=KeyBindingManager.for_prompt().registry,
  48. ),
  49. eventloop=loop,
  50. input=inp,
  51. output=DummyOutput())
  52. if pre_run_callback:
  53. pre_run_callback(cli)
  54. result = cli.run()
  55. return result, cli
  56. finally:
  57. loop.close()
  58. inp.close()
  59. def test_simple_text_input():
  60. # Simple text input, followed by enter.
  61. result, cli = _feed_cli_with_input('hello\n')
  62. assert result.text == 'hello'
  63. assert cli.buffers[DEFAULT_BUFFER].text == 'hello'
  64. def test_emacs_cursor_movements():
  65. """
  66. Test cursor movements with Emacs key bindings.
  67. """
  68. # ControlA (beginning-of-line)
  69. result, cli = _feed_cli_with_input('hello\x01X\n')
  70. assert result.text == 'Xhello'
  71. # ControlE (end-of-line)
  72. result, cli = _feed_cli_with_input('hello\x01X\x05Y\n')
  73. assert result.text == 'XhelloY'
  74. # ControlH or \b
  75. result, cli = _feed_cli_with_input('hello\x08X\n')
  76. assert result.text == 'hellX'
  77. # Delete. (Left, left, delete)
  78. result, cli = _feed_cli_with_input('hello\x1b[D\x1b[D\x1b[3~\n')
  79. assert result.text == 'helo'
  80. # Left.
  81. result, cli = _feed_cli_with_input('hello\x1b[DX\n')
  82. assert result.text == 'hellXo'
  83. # ControlA, right
  84. result, cli = _feed_cli_with_input('hello\x01\x1b[CX\n')
  85. assert result.text == 'hXello'
  86. # ControlA, right
  87. result, cli = _feed_cli_with_input('hello\x01\x1b[CX\n')
  88. assert result.text == 'hXello'
  89. # ControlB (backward-char)
  90. result, cli = _feed_cli_with_input('hello\x02X\n')
  91. assert result.text == 'hellXo'
  92. # ControlF (forward-char)
  93. result, cli = _feed_cli_with_input('hello\x01\x06X\n')
  94. assert result.text == 'hXello'
  95. # ControlC: raise KeyboardInterrupt.
  96. with pytest.raises(KeyboardInterrupt):
  97. result, cli = _feed_cli_with_input('hello\x03\n')
  98. assert result.text == 'hello'
  99. # ControlD without any input: raises EOFError.
  100. with pytest.raises(EOFError):
  101. result, cli = _feed_cli_with_input('\x04\n')
  102. assert result.text == 'hello'
  103. # ControlD: delete after cursor.
  104. result, cli = _feed_cli_with_input('hello\x01\x04\n')
  105. assert result.text == 'ello'
  106. # ControlD at the end of the input ssshould not do anything.
  107. result, cli = _feed_cli_with_input('hello\x04\n')
  108. assert result.text == 'hello'
  109. # Left, Left, ControlK (kill-line)
  110. result, cli = _feed_cli_with_input('hello\x1b[D\x1b[D\x0b\n')
  111. assert result.text == 'hel'
  112. # Left, Left Esc- ControlK (kill-line, but negative)
  113. result, cli = _feed_cli_with_input('hello\x1b[D\x1b[D\x1b-\x0b\n')
  114. assert result.text == 'lo'
  115. # ControlL: should not influence the result.
  116. result, cli = _feed_cli_with_input('hello\x0c\n')
  117. assert result.text == 'hello'
  118. # ControlRight (forward-word)
  119. result, cli = _feed_cli_with_input('hello world\x01X\x1b[1;5CY\n')
  120. assert result.text == 'XhelloY world'
  121. # ContrlolLeft (backward-word)
  122. result, cli = _feed_cli_with_input('hello world\x1b[1;5DY\n')
  123. assert result.text == 'hello Yworld'
  124. # <esc>-f with argument. (forward-word)
  125. result, cli = _feed_cli_with_input('hello world abc def\x01\x1b3\x1bfX\n')
  126. assert result.text == 'hello world abcX def'
  127. # <esc>-f with negative argument. (forward-word)
  128. result, cli = _feed_cli_with_input('hello world abc def\x1b-\x1b3\x1bfX\n')
  129. assert result.text == 'hello Xworld abc def'
  130. # <esc>-b with argument. (backward-word)
  131. result, cli = _feed_cli_with_input('hello world abc def\x1b3\x1bbX\n')
  132. assert result.text == 'hello Xworld abc def'
  133. # <esc>-b with negative argument. (backward-word)
  134. result, cli = _feed_cli_with_input('hello world abc def\x01\x1b-\x1b3\x1bbX\n')
  135. assert result.text == 'hello world abc Xdef'
  136. # ControlW (kill-word / unix-word-rubout)
  137. result, cli = _feed_cli_with_input('hello world\x17\n')
  138. assert result.text == 'hello '
  139. assert cli.clipboard.get_data().text == 'world'
  140. result, cli = _feed_cli_with_input('test hello world\x1b2\x17\n')
  141. assert result.text == 'test '
  142. # Escape Backspace (unix-word-rubout)
  143. result, cli = _feed_cli_with_input('hello world\x1b\x7f\n')
  144. assert result.text == 'hello '
  145. assert cli.clipboard.get_data().text == 'world'
  146. result, cli = _feed_cli_with_input('hello world\x1b\x08\n')
  147. assert result.text == 'hello '
  148. assert cli.clipboard.get_data().text == 'world'
  149. # Backspace (backward-delete-char)
  150. result, cli = _feed_cli_with_input('hello world\x7f\n')
  151. assert result.text == 'hello worl'
  152. assert result.cursor_position == len('hello worl')
  153. result, cli = _feed_cli_with_input('hello world\x08\n')
  154. assert result.text == 'hello worl'
  155. assert result.cursor_position == len('hello worl')
  156. # Delete (delete-char)
  157. result, cli = _feed_cli_with_input('hello world\x01\x1b[3~\n')
  158. assert result.text == 'ello world'
  159. assert result.cursor_position == 0
  160. # Escape-\\ (delete-horizontal-space)
  161. result, cli = _feed_cli_with_input('hello world\x1b8\x02\x1b\\\n')
  162. assert result.text == 'helloworld'
  163. assert result.cursor_position == len('hello')
  164. def test_emacs_yank():
  165. # ControlY (yank)
  166. c = InMemoryClipboard(ClipboardData('XYZ'))
  167. result, cli = _feed_cli_with_input('hello\x02\x19\n', clipboard=c)
  168. assert result.text == 'hellXYZo'
  169. assert result.cursor_position == len('hellXYZ')
  170. def test_quoted_insert():
  171. # ControlQ - ControlB (quoted-insert)
  172. result, cli = _feed_cli_with_input('hello\x11\x02\n')
  173. assert result.text == 'hello\x02'
  174. def test_transformations():
  175. # Meta-c (capitalize-word)
  176. result, cli = _feed_cli_with_input('hello world\01\x1bc\n')
  177. assert result.text == 'Hello world'
  178. assert result.cursor_position == len('Hello')
  179. # Meta-u (uppercase-word)
  180. result, cli = _feed_cli_with_input('hello world\01\x1bu\n')
  181. assert result.text == 'HELLO world'
  182. assert result.cursor_position == len('Hello')
  183. # Meta-u (downcase-word)
  184. result, cli = _feed_cli_with_input('HELLO WORLD\01\x1bl\n')
  185. assert result.text == 'hello WORLD'
  186. assert result.cursor_position == len('Hello')
  187. # ControlT (transpose-chars)
  188. result, cli = _feed_cli_with_input('hello\x14\n')
  189. assert result.text == 'helol'
  190. assert result.cursor_position == len('hello')
  191. # Left, Left, Control-T (transpose-chars)
  192. result, cli = _feed_cli_with_input('abcde\x1b[D\x1b[D\x14\n')
  193. assert result.text == 'abdce'
  194. assert result.cursor_position == len('abcd')
  195. def test_emacs_other_bindings():
  196. # Transpose characters.
  197. result, cli = _feed_cli_with_input('abcde\x14X\n') # Ctrl-T
  198. assert result.text == 'abcedX'
  199. # Left, Left, Transpose. (This is slightly different.)
  200. result, cli = _feed_cli_with_input('abcde\x1b[D\x1b[D\x14X\n')
  201. assert result.text == 'abdcXe'
  202. # Clear before cursor.
  203. result, cli = _feed_cli_with_input('hello\x1b[D\x1b[D\x15X\n')
  204. assert result.text == 'Xlo'
  205. # unix-word-rubout: delete word before the cursor.
  206. # (ControlW).
  207. result, cli = _feed_cli_with_input('hello world test\x17X\n')
  208. assert result.text == 'hello world X'
  209. result, cli = _feed_cli_with_input('hello world /some/very/long/path\x17X\n')
  210. assert result.text == 'hello world X'
  211. # (with argument.)
  212. result, cli = _feed_cli_with_input('hello world test\x1b2\x17X\n')
  213. assert result.text == 'hello X'
  214. result, cli = _feed_cli_with_input('hello world /some/very/long/path\x1b2\x17X\n')
  215. assert result.text == 'hello X'
  216. # backward-kill-word: delete word before the cursor.
  217. # (Esc-ControlH).
  218. result, cli = _feed_cli_with_input('hello world /some/very/long/path\x1b\x08X\n')
  219. assert result.text == 'hello world /some/very/long/X'
  220. # (with arguments.)
  221. result, cli = _feed_cli_with_input('hello world /some/very/long/path\x1b3\x1b\x08X\n')
  222. assert result.text == 'hello world /some/very/X'
  223. def test_controlx_controlx():
  224. # At the end: go to the start of the line.
  225. result, cli = _feed_cli_with_input('hello world\x18\x18X\n')
  226. assert result.text == 'Xhello world'
  227. assert result.cursor_position == 1
  228. # At the start: go to the end of the line.
  229. result, cli = _feed_cli_with_input('hello world\x01\x18\x18X\n')
  230. assert result.text == 'hello worldX'
  231. # Left, Left Control-X Control-X: go to the end of the line.
  232. result, cli = _feed_cli_with_input('hello world\x1b[D\x1b[D\x18\x18X\n')
  233. assert result.text == 'hello worldX'
  234. def test_emacs_history_bindings():
  235. # Adding a new item to the history.
  236. history = _history()
  237. result, cli = _feed_cli_with_input('new input\n', history=history)
  238. assert result.text == 'new input'
  239. history.strings[-1] == 'new input'
  240. # Go up in history, and accept the last item.
  241. result, cli = _feed_cli_with_input('hello\x1b[A\n', history=history)
  242. assert result.text == 'new input'
  243. # Esc< (beginning-of-history)
  244. result, cli = _feed_cli_with_input('hello\x1b<\n', history=history)
  245. assert result.text == 'line1 first input'
  246. # Esc> (end-of-history)
  247. result, cli = _feed_cli_with_input('another item\x1b[A\x1b[a\x1b>\n', history=history)
  248. assert result.text == 'another item'
  249. # ControlUp (previous-history)
  250. result, cli = _feed_cli_with_input('\x1b[1;5A\n', history=history)
  251. assert result.text == 'another item'
  252. # Esc< ControlDown (beginning-of-history, next-history)
  253. result, cli = _feed_cli_with_input('\x1b<\x1b[1;5B\n', history=history)
  254. assert result.text == 'line2 second input'
  255. def test_emacs_reverse_search():
  256. history = _history()
  257. # ControlR (reverse-search-history)
  258. result, cli = _feed_cli_with_input('\x12input\n\n', history=history)
  259. assert result.text == 'line3 third input'
  260. # Hitting ControlR twice.
  261. result, cli = _feed_cli_with_input('\x12input\x12\n\n', history=history)
  262. assert result.text == 'line2 second input'
  263. def test_emacs_arguments():
  264. """
  265. Test various combinations of arguments in Emacs mode.
  266. """
  267. # esc 4
  268. result, cli = _feed_cli_with_input('\x1b4x\n')
  269. assert result.text == 'xxxx'
  270. # esc 4 4
  271. result, cli = _feed_cli_with_input('\x1b44x\n')
  272. assert result.text == 'x' * 44
  273. # esc 4 esc 4
  274. result, cli = _feed_cli_with_input('\x1b4\x1b4x\n')
  275. assert result.text == 'x' * 44
  276. # esc - right (-1 position to the right, equals 1 to the left.)
  277. result, cli = _feed_cli_with_input('aaaa\x1b-\x1b[Cbbbb\n')
  278. assert result.text == 'aaabbbba'
  279. # esc - 3 right
  280. result, cli = _feed_cli_with_input('aaaa\x1b-3\x1b[Cbbbb\n')
  281. assert result.text == 'abbbbaaa'
  282. # esc - - - 3 right
  283. result, cli = _feed_cli_with_input('aaaa\x1b---3\x1b[Cbbbb\n')
  284. assert result.text == 'abbbbaaa'
  285. def test_emacs_arguments_for_all_commands():
  286. """
  287. Test all Emacs commands with Meta-[0-9] arguments (both positive and
  288. negative). No one should crash.
  289. """
  290. for key in ANSI_SEQUENCES:
  291. # Ignore BracketedPaste. This would hang forever, because it waits for
  292. # the end sequence.
  293. if key != '\x1b[200~':
  294. try:
  295. # Note: we add an 'X' after the key, because Ctrl-Q (quoted-insert)
  296. # expects something to follow. We add an additional \n, because
  297. # Ctrl-R and Ctrl-S (reverse-search) expect that.
  298. result, cli = _feed_cli_with_input(
  299. 'hello\x1b4' + key + 'X\n\n')
  300. result, cli = _feed_cli_with_input(
  301. 'hello\x1b-' + key + 'X\n\n')
  302. except KeyboardInterrupt:
  303. # This exception should only be raised for Ctrl-C
  304. assert key == '\x03'
  305. def test_emacs_kill_ring():
  306. operations = (
  307. # abc ControlA ControlK
  308. 'abc\x01\x0b'
  309. # def ControlA ControlK
  310. 'def\x01\x0b'
  311. # ghi ControlA ControlK
  312. 'ghi\x01\x0b'
  313. # ControlY (yank)
  314. '\x19'
  315. )
  316. result, cli = _feed_cli_with_input(operations + '\n')
  317. assert result.text == 'ghi'
  318. result, cli = _feed_cli_with_input(operations + '\x1by\n')
  319. assert result.text == 'def'
  320. result, cli = _feed_cli_with_input(operations + '\x1by\x1by\n')
  321. assert result.text == 'abc'
  322. result, cli = _feed_cli_with_input(operations + '\x1by\x1by\x1by\n')
  323. assert result.text == 'ghi'
  324. def test_emacs_insert_comment():
  325. # Test insert-comment (M-#) binding.
  326. result, cli = _feed_cli_with_input('hello\x1b#', check_line_ending=False)
  327. assert result.text == '#hello'
  328. result, cli = _feed_cli_with_input(
  329. 'hello\nworld\x1b#', check_line_ending=False, multiline=True)
  330. assert result.text == '#hello\n#world'
  331. def test_emacs_record_macro():
  332. operations = (
  333. ' '
  334. '\x18(' # Start recording macro. C-X(
  335. 'hello'
  336. '\x18)' # Stop recording macro.
  337. ' '
  338. '\x18e' # Execute macro.
  339. '\x18e' # Execute macro.
  340. '\n'
  341. )
  342. result, cli = _feed_cli_with_input(operations)
  343. assert result.text == ' hello hellohello'
  344. def test_prefix_meta():
  345. # Test the prefix-meta command.
  346. def setup_keybindings(cli):
  347. from prompt_toolkit.key_binding.bindings.named_commands import prefix_meta
  348. from prompt_toolkit.filters import ViInsertMode
  349. cli.application.key_bindings_registry.add_binding('j', 'j', filter=ViInsertMode())(prefix_meta)
  350. result, cli = _feed_cli_with_input(
  351. 'hellojjIX\n', pre_run_callback=setup_keybindings, editing_mode=EditingMode.VI)
  352. assert result.text == 'Xhello'
  353. def test_bracketed_paste():
  354. result, cli = _feed_cli_with_input('\x1b[200~hello world\x1b[201~\n')
  355. assert result.text == 'hello world'
  356. result, cli = _feed_cli_with_input('\x1b[200~hello\nworld\x1b[201~\x1b\n')
  357. assert result.text == 'hello\nworld'
  358. # With \r\n endings.
  359. result, cli = _feed_cli_with_input('\x1b[200~hello\r\nworld\x1b[201~\x1b\n')
  360. assert result.text == 'hello\nworld'
  361. # With \r endings.
  362. result, cli = _feed_cli_with_input('\x1b[200~hello\rworld\x1b[201~\x1b\n')
  363. assert result.text == 'hello\nworld'
  364. def test_vi_cursor_movements():
  365. """
  366. Test cursor movements with Vi key bindings.
  367. """
  368. feed = partial(_feed_cli_with_input, editing_mode=EditingMode.VI)
  369. result, cli = feed('\x1b\n')
  370. assert result.text == ''
  371. assert cli.editing_mode == EditingMode.VI
  372. # Esc h a X
  373. result, cli = feed('hello\x1bhaX\n')
  374. assert result.text == 'hellXo'
  375. # Esc I X
  376. result, cli = feed('hello\x1bIX\n')
  377. assert result.text == 'Xhello'
  378. # Esc I X
  379. result, cli = feed('hello\x1bIX\n')
  380. assert result.text == 'Xhello'
  381. # Esc 2hiX
  382. result, cli = feed('hello\x1b2hiX\n')
  383. assert result.text == 'heXllo'
  384. # Esc 2h2liX
  385. result, cli = feed('hello\x1b2h2liX\n')
  386. assert result.text == 'hellXo'
  387. # Esc \b\b
  388. result, cli = feed('hello\b\b\n')
  389. assert result.text == 'hel'
  390. # Esc \b\b
  391. result, cli = feed('hello\b\b\n')
  392. assert result.text == 'hel'
  393. # Esc 2h D
  394. result, cli = feed('hello\x1b2hD\n')
  395. assert result.text == 'he'
  396. # Esc 2h rX \n
  397. result, cli = feed('hello\x1b2hrX\n')
  398. assert result.text == 'heXlo'
  399. def test_vi_operators():
  400. feed = partial(_feed_cli_with_input, editing_mode=EditingMode.VI)
  401. # Esc g~0
  402. result, cli = feed('hello\x1bg~0\n')
  403. assert result.text == 'HELLo'
  404. # Esc gU0
  405. result, cli = feed('hello\x1bgU0\n')
  406. assert result.text == 'HELLo'
  407. # Esc d0
  408. result, cli = feed('hello\x1bd0\n')
  409. assert result.text == 'o'
  410. def test_vi_text_objects():
  411. feed = partial(_feed_cli_with_input, editing_mode=EditingMode.VI)
  412. # Esc gUgg
  413. result, cli = feed('hello\x1bgUgg\n')
  414. assert result.text == 'HELLO'
  415. # Esc gUU
  416. result, cli = feed('hello\x1bgUU\n')
  417. assert result.text == 'HELLO'
  418. # Esc di(
  419. result, cli = feed('before(inside)after\x1b8hdi(\n')
  420. assert result.text == 'before()after'
  421. # Esc di[
  422. result, cli = feed('before[inside]after\x1b8hdi[\n')
  423. assert result.text == 'before[]after'
  424. # Esc da(
  425. result, cli = feed('before(inside)after\x1b8hda(\n')
  426. assert result.text == 'beforeafter'
  427. def test_vi_digraphs():
  428. feed = partial(_feed_cli_with_input, editing_mode=EditingMode.VI)
  429. # C-K o/
  430. result, cli = feed('hello\x0bo/\n')
  431. assert result.text == 'helloø'
  432. # C-K /o (reversed input.)
  433. result, cli = feed('hello\x0b/o\n')
  434. assert result.text == 'helloø'
  435. # C-K e:
  436. result, cli = feed('hello\x0be:\n')
  437. assert result.text == 'helloë'
  438. # C-K xxy (Unknown digraph.)
  439. result, cli = feed('hello\x0bxxy\n')
  440. assert result.text == 'helloy'
  441. def test_vi_block_editing():
  442. " Test Vi Control-V style block insertion. "
  443. feed = partial(_feed_cli_with_input, editing_mode=EditingMode.VI,
  444. multiline=True)
  445. operations = (
  446. # Three lines of text.
  447. '-line1\n-line2\n-line3\n-line4\n-line5\n-line6'
  448. # Go to the second character of the second line.
  449. '\x1bkkkkkkkj0l'
  450. # Enter Visual block mode.
  451. '\x16'
  452. # Go down two more lines.
  453. 'jj'
  454. # Go 3 characters to the right.
  455. 'lll'
  456. # Go to insert mode.
  457. 'insert' # (Will be replaced.)
  458. # Insert stars.
  459. '***'
  460. # Escape again.
  461. '\x1b\n')
  462. # Control-I
  463. result, cli = feed(operations.replace('insert', 'I'))
  464. assert (result.text ==
  465. '-line1\n-***line2\n-***line3\n-***line4\n-line5\n-line6')
  466. # Control-A
  467. result, cli = feed(operations.replace('insert', 'A'))
  468. assert (result.text ==
  469. '-line1\n-line***2\n-line***3\n-line***4\n-line5\n-line6')
  470. def test_vi_character_paste():
  471. feed = partial(_feed_cli_with_input, editing_mode=EditingMode.VI)
  472. # Test 'p' character paste.
  473. result, cli = feed('abcde\x1bhhxp\n')
  474. assert result.text == 'abdce'
  475. assert result.cursor_position == 3
  476. # Test 'P' character paste.
  477. result, cli = feed('abcde\x1bhhxP\n')
  478. assert result.text == 'abcde'
  479. assert result.cursor_position == 2