cmdline_spec.lua 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. local n = require('test.functional.testnvim')()
  2. local Screen = require('test.functional.ui.screen')
  3. local clear = n.clear
  4. local command = n.command
  5. local feed = n.feed
  6. local feed_command = n.feed_command
  7. local exec = n.exec
  8. local api = n.api
  9. local pesc = vim.pesc
  10. describe('cmdline', function()
  11. before_each(clear)
  12. -- oldtest: Test_cmdlineclear_tabenter()
  13. it('is cleared when switching tabs', function()
  14. local screen = Screen.new(30, 10)
  15. feed_command([[call setline(1, range(30))]])
  16. screen:expect([[
  17. ^0 |
  18. 1 |
  19. 2 |
  20. 3 |
  21. 4 |
  22. 5 |
  23. 6 |
  24. 7 |
  25. 8 |
  26. :call setline(1, range(30)) |
  27. ]])
  28. feed [[:tabnew<cr>]]
  29. screen:expect {
  30. grid = [[
  31. {24: + [No Name] }{5: [No Name] }{2: }{24:X}|
  32. ^ |
  33. {1:~ }|*7
  34. :tabnew |
  35. ]],
  36. }
  37. feed [[<C-w>-<C-w>-]]
  38. screen:expect {
  39. grid = [[
  40. {24: + [No Name] }{5: [No Name] }{2: }{24:X}|
  41. ^ |
  42. {1:~ }|*5
  43. |*3
  44. ]],
  45. }
  46. feed [[gt]]
  47. screen:expect {
  48. grid = [[
  49. {5: + [No Name] }{24: [No Name] }{2: }{24:X}|
  50. ^0 |
  51. 1 |
  52. 2 |
  53. 3 |
  54. 4 |
  55. 5 |
  56. 6 |
  57. 7 |
  58. |
  59. ]],
  60. }
  61. feed [[gt]]
  62. screen:expect([[
  63. {24: + [No Name] }{5: [No Name] }{2: }{24:X}|
  64. ^ |
  65. {1:~ }|*5
  66. |*3
  67. ]])
  68. end)
  69. -- oldtest: Test_verbose_option()
  70. it('prints every executed Ex command if verbose >= 16', function()
  71. local screen = Screen.new(60, 12)
  72. exec([[
  73. command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v
  74. call feedkeys("\r", 't') " for the hit-enter prompt
  75. set verbose=20
  76. ]])
  77. feed_command('DoSomething')
  78. screen:expect([[
  79. |
  80. {1:~ }|*2
  81. {3: }|
  82. Executing: DoSomething |
  83. Executing: echo 'hello' |set ts=4 |let v = '123' |echo v |
  84. hello |
  85. Executing: set ts=4 |let v = '123' |echo v |
  86. Executing: let v = '123' |echo v |
  87. Executing: echo v |
  88. 123 |
  89. {6:Press ENTER or type command to continue}^ |
  90. ]])
  91. end)
  92. -- oldtest: Test_cmdline_redraw_tabline()
  93. it('tabline is redrawn on entering cmdline', function()
  94. local screen = Screen.new(30, 6)
  95. exec([[
  96. set showtabline=2
  97. autocmd CmdlineEnter * set tabline=foo
  98. ]])
  99. feed(':')
  100. screen:expect([[
  101. {2:foo }|
  102. |
  103. {1:~ }|*3
  104. :^ |
  105. ]])
  106. end)
  107. -- oldtest: Test_redraw_in_autocmd()
  108. it('cmdline cursor position is correct after :redraw with cmdheight=2', function()
  109. local screen = Screen.new(30, 6)
  110. exec([[
  111. set cmdheight=2
  112. autocmd CmdlineChanged * redraw
  113. ]])
  114. feed(':for i in range(3)<CR>')
  115. screen:expect([[
  116. |
  117. {1:~ }|*3
  118. :for i in range(3) |
  119. : ^ |
  120. ]])
  121. feed(':let i =')
  122. -- Note: this may still be considered broken, ref #18140
  123. screen:expect([[
  124. |
  125. {1:~ }|*3
  126. : :let i =^ |
  127. |
  128. ]])
  129. end)
  130. -- oldtest: Test_changing_cmdheight()
  131. it("changing 'cmdheight'", function()
  132. local screen = Screen.new(60, 8)
  133. exec([[
  134. set cmdheight=1 laststatus=2
  135. func EchoOne()
  136. set laststatus=2 cmdheight=1
  137. echo 'foo'
  138. echo 'bar'
  139. set cmdheight=2
  140. endfunc
  141. func EchoTwo()
  142. set laststatus=2
  143. set cmdheight=5
  144. echo 'foo'
  145. echo 'bar'
  146. set cmdheight=1
  147. endfunc
  148. ]])
  149. -- setting 'cmdheight' works after outputting two messages
  150. feed(':call EchoTwo()')
  151. screen:expect([[
  152. |
  153. {1:~ }|*5
  154. {3:[No Name] }|
  155. :call EchoTwo()^ |
  156. ]])
  157. feed('<CR>')
  158. screen:expect([[
  159. ^ |
  160. {1:~ }|*5
  161. {3:[No Name] }|
  162. |
  163. ]])
  164. -- increasing 'cmdheight' doesn't clear the messages that need hit-enter
  165. feed(':call EchoOne()<CR>')
  166. screen:expect([[
  167. |
  168. {1:~ }|*3
  169. {3: }|
  170. foo |
  171. bar |
  172. {6:Press ENTER or type command to continue}^ |
  173. ]])
  174. end)
  175. -- oldtest: Test_cmdheight_tabline()
  176. it("changing 'cmdheight' when there is a tabline", function()
  177. local screen = Screen.new(60, 8)
  178. api.nvim_set_option_value('laststatus', 2, {})
  179. api.nvim_set_option_value('showtabline', 2, {})
  180. api.nvim_set_option_value('cmdheight', 1, {})
  181. screen:expect([[
  182. {5: [No Name] }{2: }|
  183. ^ |
  184. {1:~ }|*4
  185. {3:[No Name] }|
  186. |
  187. ]])
  188. end)
  189. -- oldtest: Test_rulerformat_position()
  190. it("ruler has correct position with 'rulerformat' set", function()
  191. local screen = Screen.new(20, 3)
  192. api.nvim_set_option_value('ruler', true, {})
  193. api.nvim_set_option_value('rulerformat', 'longish', {})
  194. api.nvim_set_option_value('laststatus', 0, {})
  195. api.nvim_set_option_value('winwidth', 1, {})
  196. feed [[<C-W>v<C-W>|<C-W>p]]
  197. screen:expect [[
  198. │^ |
  199. {1:~ }│{1:~}|
  200. longish |
  201. ]]
  202. end)
  203. end)
  204. describe('cmdwin', function()
  205. before_each(clear)
  206. -- oldtest: Test_cmdwin_interrupted()
  207. it('still uses a new buffer when interrupting more prompt on open', function()
  208. local screen = Screen.new(30, 16)
  209. screen:set_default_attr_ids({
  210. [0] = { bold = true, foreground = Screen.colors.Blue }, -- NonText
  211. [1] = { bold = true, reverse = true }, -- StatusLine
  212. [2] = { reverse = true }, -- StatusLineNC
  213. [3] = { bold = true, foreground = Screen.colors.SeaGreen }, -- MoreMsg
  214. [4] = { bold = true }, -- ModeMsg
  215. })
  216. command('set more')
  217. command('autocmd WinNew * highlight')
  218. feed('q:')
  219. screen:expect({ any = pesc('{3:-- More --}^') })
  220. feed('q')
  221. screen:expect([[
  222. |
  223. {0:~ }|*5
  224. {2:[No Name] }|
  225. {0::}^ |
  226. {0:~ }|*6
  227. {1:[Command Line] }|
  228. |
  229. ]])
  230. feed([[aecho 'done']])
  231. screen:expect([[
  232. |
  233. {0:~ }|*5
  234. {2:[No Name] }|
  235. {0::}echo 'done'^ |
  236. {0:~ }|*6
  237. {1:[Command Line] }|
  238. {4:-- INSERT --} |
  239. ]])
  240. feed('<CR>')
  241. screen:expect([[
  242. ^ |
  243. {0:~ }|*14
  244. done |
  245. ]])
  246. end)
  247. end)