wildmode_spec.lua 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. local global_helpers = require('test.helpers')
  2. local shallowcopy = global_helpers.shallowcopy
  3. local helpers = require('test.functional.helpers')(after_each)
  4. local Screen = require('test.functional.ui.screen')
  5. local clear, feed, command = helpers.clear, helpers.feed, helpers.command
  6. local iswin = helpers.iswin
  7. local funcs = helpers.funcs
  8. local eq = helpers.eq
  9. local eval = helpers.eval
  10. local retry = helpers.retry
  11. describe("'wildmenu'", function()
  12. local screen
  13. before_each(function()
  14. clear()
  15. screen = Screen.new(25, 5)
  16. screen:attach()
  17. end)
  18. after_each(function()
  19. screen:detach()
  20. end)
  21. -- expect the screen stayed unchanged some time after first seen success
  22. local function expect_stay_unchanged(args)
  23. screen:expect(args)
  24. args = shallowcopy(args)
  25. args.unchanged = true
  26. screen:expect(args)
  27. end
  28. it(':sign <tab> shows wildmenu completions', function()
  29. command('set wildmode=full')
  30. command('set wildmenu')
  31. feed(':sign <tab>')
  32. screen:expect([[
  33. |
  34. ~ |
  35. ~ |
  36. define jump list > |
  37. :sign define^ |
  38. ]])
  39. end)
  40. it(':sign <tab> <space> hides wildmenu #8453', function()
  41. command('set wildmode=full')
  42. -- only a regression if status-line open
  43. command('set laststatus=2')
  44. command('set wildmenu')
  45. feed(':sign <tab>')
  46. screen:expect([[
  47. |
  48. ~ |
  49. ~ |
  50. define jump list > |
  51. :sign define^ |
  52. ]])
  53. feed('<space>')
  54. screen:expect([[
  55. |
  56. ~ |
  57. ~ |
  58. [No Name] |
  59. :sign define ^ |
  60. ]])
  61. end)
  62. it('does not crash after cycling back to original text', function()
  63. command('set wildmode=full')
  64. feed(':j<Tab><Tab><Tab>')
  65. screen:expect([[
  66. |
  67. ~ |
  68. ~ |
  69. join jumps |
  70. :j^ |
  71. ]])
  72. -- This would cause nvim to crash before #6650
  73. feed('<BS><Tab>')
  74. screen:expect([[
  75. |
  76. ~ |
  77. ~ |
  78. ! # & < = > @ > |
  79. :!^ |
  80. ]])
  81. end)
  82. it('is preserved during :terminal activity', function()
  83. command('set wildmenu wildmode=full')
  84. command('set scrollback=4')
  85. if iswin() then
  86. feed([[:terminal for /L \%I in (1,1,5000) do @(echo foo & echo foo & echo foo)<cr>]])
  87. else
  88. feed([[:terminal for i in $(seq 1 5000); do printf 'foo\nfoo\nfoo\n'; sleep 0.1; done<cr>]])
  89. end
  90. feed([[<C-\><C-N>gg]])
  91. feed([[:sign <Tab>]]) -- Invoke wildmenu.
  92. expect_stay_unchanged{grid=[[
  93. foo |
  94. foo |
  95. foo |
  96. define jump list > |
  97. :sign define^ |
  98. ]]}
  99. -- cmdline CTRL-D display should also be preserved.
  100. feed([[<C-\><C-N>]])
  101. feed([[:sign <C-D>]]) -- Invoke cmdline CTRL-D.
  102. expect_stay_unchanged{grid=[[
  103. :sign |
  104. define place |
  105. jump undefine |
  106. list unplace |
  107. :sign ^ |
  108. ]]}
  109. -- Exiting cmdline should show the buffer.
  110. feed([[<C-\><C-N>]])
  111. screen:expect([[
  112. ^foo |
  113. foo |
  114. foo |
  115. foo |
  116. |
  117. ]])
  118. end)
  119. it('ignores :redrawstatus called from a timer #7108', function()
  120. command('set wildmenu wildmode=full')
  121. command([[call timer_start(10, {->execute('redrawstatus')}, {'repeat':-1})]])
  122. feed([[<C-\><C-N>]])
  123. feed([[:sign <Tab>]]) -- Invoke wildmenu.
  124. expect_stay_unchanged{grid=[[
  125. |
  126. ~ |
  127. ~ |
  128. define jump list > |
  129. :sign define^ |
  130. ]]}
  131. end)
  132. it('with laststatus=0, :vsplit, :term #2255', function()
  133. -- Because this test verifies a _lack_ of activity after screen:sleep(), we
  134. -- must wait the full timeout. So make it reasonable.
  135. screen.timeout = 1000
  136. if not iswin() then
  137. command('set shell=sh') -- Need a predictable "$" prompt.
  138. end
  139. command('set laststatus=0')
  140. command('vsplit')
  141. command('term')
  142. -- Check for a shell prompt to verify that the terminal loaded.
  143. retry(nil, nil, function()
  144. if iswin() then
  145. eq('Microsoft', eval("matchstr(join(getline(1, '$')), 'Microsoft')"))
  146. else
  147. eq('$', eval([[matchstr(getline(1), '\$')]]))
  148. end
  149. end)
  150. feed([[<C-\><C-N>]])
  151. feed([[:<Tab>]]) -- Invoke wildmenu.
  152. -- Check only the last 2 lines, because the shell output is
  153. -- system-dependent.
  154. expect_stay_unchanged{any='! # & < = > @ > \n:!^'}
  155. end)
  156. end)
  157. describe('command line completion', function()
  158. local screen
  159. before_each(function()
  160. clear()
  161. screen = Screen.new(40, 5)
  162. screen:attach()
  163. screen:set_default_attr_ids({[1]={bold=true, foreground=Screen.colors.Blue}})
  164. end)
  165. after_each(function()
  166. os.remove('Xtest-functional-viml-compl-dir')
  167. end)
  168. it('lists directories with empty PATH', function()
  169. local tmp = funcs.tempname()
  170. command('e '.. tmp)
  171. command('cd %:h')
  172. command("call mkdir('Xtest-functional-viml-compl-dir')")
  173. command('let $PATH=""')
  174. feed(':!<tab><bs>')
  175. screen:expect([[
  176. |
  177. {1:~ }|
  178. {1:~ }|
  179. {1:~ }|
  180. :!Xtest-functional-viml-compl-dir^ |
  181. ]])
  182. end)
  183. end)
  184. describe('ui/ext_wildmenu', function()
  185. local screen
  186. before_each(function()
  187. clear()
  188. screen = Screen.new(25, 5)
  189. screen:attach({rgb=true, ext_wildmenu=true})
  190. end)
  191. after_each(function()
  192. screen:detach()
  193. end)
  194. it('works with :sign <tab>', function()
  195. local expected = {
  196. 'define',
  197. 'jump',
  198. 'list',
  199. 'place',
  200. 'undefine',
  201. 'unplace',
  202. }
  203. command('set wildmode=full')
  204. command('set wildmenu')
  205. feed(':sign <tab>')
  206. screen:expect{grid=[[
  207. |
  208. ~ |
  209. ~ |
  210. ~ |
  211. :sign define^ |
  212. ]], wildmenu_items=expected, wildmenu_pos=0}
  213. feed('<tab>')
  214. screen:expect{grid=[[
  215. |
  216. ~ |
  217. ~ |
  218. ~ |
  219. :sign jump^ |
  220. ]], wildmenu_items=expected, wildmenu_pos=1}
  221. feed('<left><left>')
  222. screen:expect{grid=[[
  223. |
  224. ~ |
  225. ~ |
  226. ~ |
  227. :sign ^ |
  228. ]], wildmenu_items=expected, wildmenu_pos=-1}
  229. feed('<right>')
  230. screen:expect{grid=[[
  231. |
  232. ~ |
  233. ~ |
  234. ~ |
  235. :sign define^ |
  236. ]], wildmenu_items=expected, wildmenu_pos=0}
  237. feed('a')
  238. screen:expect{grid=[[
  239. |
  240. ~ |
  241. ~ |
  242. ~ |
  243. :sign definea^ |
  244. ]]}
  245. end)
  246. end)