test_yank_nth_arg.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. from __future__ import unicode_literals
  2. from prompt_toolkit.buffer import Buffer
  3. from prompt_toolkit.history import InMemoryHistory
  4. import pytest
  5. @pytest.fixture
  6. def _history():
  7. " Prefilled history. "
  8. history = InMemoryHistory()
  9. history.append('alpha beta gamma delta')
  10. history.append('one two three four')
  11. return history
  12. # Test yank_last_arg.
  13. def test_empty_history():
  14. buf = Buffer()
  15. buf.yank_last_arg()
  16. assert buf.document.current_line == ''
  17. def test_simple_search(_history):
  18. buff = Buffer(history=_history)
  19. buff.yank_last_arg()
  20. assert buff.document.current_line == 'four'
  21. def test_simple_search_with_quotes(_history):
  22. _history.append("""one two "three 'x' four"\n""")
  23. buff = Buffer(history=_history)
  24. buff.yank_last_arg()
  25. assert buff.document.current_line == '''"three 'x' four"'''
  26. def test_simple_search_with_arg(_history):
  27. buff = Buffer(history=_history)
  28. buff.yank_last_arg(n=2)
  29. assert buff.document.current_line == 'three'
  30. def test_simple_search_with_arg_out_of_bounds(_history):
  31. buff = Buffer(history=_history)
  32. buff.yank_last_arg(n=8)
  33. assert buff.document.current_line == ''
  34. def test_repeated_search(_history):
  35. buff = Buffer(history=_history)
  36. buff.yank_last_arg()
  37. buff.yank_last_arg()
  38. assert buff.document.current_line == 'delta'
  39. def test_repeated_search_with_wraparound(_history):
  40. buff = Buffer(history=_history)
  41. buff.yank_last_arg()
  42. buff.yank_last_arg()
  43. buff.yank_last_arg()
  44. assert buff.document.current_line == 'four'
  45. # Test yank_last_arg.
  46. def test_yank_nth_arg(_history):
  47. buff = Buffer(history=_history)
  48. buff.yank_nth_arg()
  49. assert buff.document.current_line == 'two'
  50. def test_repeated_yank_nth_arg(_history):
  51. buff = Buffer(history=_history)
  52. buff.yank_nth_arg()
  53. buff.yank_nth_arg()
  54. assert buff.document.current_line == 'beta'
  55. def test_yank_nth_arg_with_arg(_history):
  56. buff = Buffer(history=_history)
  57. buff.yank_nth_arg(n=2)
  58. assert buff.document.current_line == 'three'