prompt_buffer_spec.lua 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. local helpers = require('test.functional.helpers')(after_each)
  2. local Screen = require('test.functional.ui.screen')
  3. local feed= helpers.feed
  4. local source = helpers.source
  5. local clear = helpers.clear
  6. local feed_command = helpers.feed_command
  7. describe('prompt buffer', function()
  8. local screen
  9. before_each(function()
  10. clear()
  11. screen = Screen.new(25, 10)
  12. screen:attach()
  13. source([[
  14. func TextEntered(text)
  15. if a:text == "exit"
  16. set nomodified
  17. stopinsert
  18. close
  19. else
  20. call append(line("$") - 1, 'Command: "' . a:text . '"')
  21. set nomodfied
  22. call timer_start(20, {id -> TimerFunc(a:text)})
  23. endif
  24. endfunc
  25. func TimerFunc(text)
  26. call append(line("$") - 1, 'Result: "' . a:text .'"')
  27. endfunc
  28. ]])
  29. feed_command("set noshowmode | set laststatus=0")
  30. feed_command("call setline(1, 'other buffer')")
  31. feed_command("new")
  32. feed_command("set buftype=prompt")
  33. feed_command("call prompt_setcallback(bufnr(''), function('TextEntered'))")
  34. end)
  35. after_each(function()
  36. screen:detach()
  37. end)
  38. it('works', function()
  39. screen:expect([[
  40. ^ |
  41. ~ |
  42. ~ |
  43. ~ |
  44. [Prompt] |
  45. other buffer |
  46. ~ |
  47. ~ |
  48. ~ |
  49. |
  50. ]])
  51. feed("i")
  52. feed("hello\n")
  53. screen:expect([[
  54. % hello |
  55. Command: "hello" |
  56. Result: "hello" |
  57. % ^ |
  58. [Prompt] [+] |
  59. other buffer |
  60. ~ |
  61. ~ |
  62. ~ |
  63. |
  64. ]])
  65. feed("exit\n")
  66. screen:expect([[
  67. ^other buffer |
  68. ~ |
  69. ~ |
  70. ~ |
  71. ~ |
  72. ~ |
  73. ~ |
  74. ~ |
  75. ~ |
  76. |
  77. ]])
  78. end)
  79. it('editing', function()
  80. screen:expect([[
  81. ^ |
  82. ~ |
  83. ~ |
  84. ~ |
  85. [Prompt] |
  86. other buffer |
  87. ~ |
  88. ~ |
  89. ~ |
  90. |
  91. ]])
  92. feed("i")
  93. feed("hello<BS><BS>")
  94. screen:expect([[
  95. % hel^ |
  96. ~ |
  97. ~ |
  98. ~ |
  99. [Prompt] [+] |
  100. other buffer |
  101. ~ |
  102. ~ |
  103. ~ |
  104. |
  105. ]])
  106. feed("<Left><Left><Left><BS>-")
  107. screen:expect([[
  108. % -^hel |
  109. ~ |
  110. ~ |
  111. ~ |
  112. [Prompt] [+] |
  113. other buffer |
  114. ~ |
  115. ~ |
  116. ~ |
  117. |
  118. ]])
  119. feed("<End>x")
  120. screen:expect([[
  121. % -helx^ |
  122. ~ |
  123. ~ |
  124. ~ |
  125. [Prompt] [+] |
  126. other buffer |
  127. ~ |
  128. ~ |
  129. ~ |
  130. |
  131. ]])
  132. feed("<C-U>exit\n")
  133. screen:expect([[
  134. ^other buffer |
  135. ~ |
  136. ~ |
  137. ~ |
  138. ~ |
  139. ~ |
  140. ~ |
  141. ~ |
  142. ~ |
  143. |
  144. ]])
  145. end)
  146. end)