cmdline_spec.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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. feed(':resize -3<CR>')
  150. screen:expect([[
  151. ^ |
  152. {1:~ }|*2
  153. {3:[No Name] }|
  154. |*4
  155. ]])
  156. -- :resize now also changes 'cmdheight' accordingly
  157. feed(':set cmdheight+=1<CR>')
  158. screen:expect([[
  159. ^ |
  160. {1:~ }|
  161. {3:[No Name] }|
  162. |*5
  163. ]])
  164. -- using more space moves the status line up
  165. feed(':set cmdheight+=1<CR>')
  166. screen:expect([[
  167. ^ |
  168. {3:[No Name] }|
  169. |*6
  170. ]])
  171. -- reducing cmdheight moves status line down
  172. feed(':set cmdheight-=3<CR>')
  173. screen:expect([[
  174. ^ |
  175. {1:~ }|*3
  176. {3:[No Name] }|
  177. |*3
  178. ]])
  179. -- reducing window size and then setting cmdheight
  180. feed(':resize -1<CR>')
  181. feed(':set cmdheight=1<CR>')
  182. screen:expect([[
  183. ^ |
  184. {1:~ }|*5
  185. {3:[No Name] }|
  186. |
  187. ]])
  188. -- setting 'cmdheight' works after outputting two messages
  189. feed(':call EchoTwo()')
  190. screen:expect([[
  191. |
  192. {1:~ }|*5
  193. {3:[No Name] }|
  194. :call EchoTwo()^ |
  195. ]])
  196. feed('<CR>')
  197. screen:expect([[
  198. ^ |
  199. {1:~ }|*5
  200. {3:[No Name] }|
  201. |
  202. ]])
  203. -- increasing 'cmdheight' doesn't clear the messages that need hit-enter
  204. feed(':call EchoOne()<CR>')
  205. screen:expect([[
  206. |
  207. {1:~ }|*3
  208. {3: }|
  209. foo |
  210. bar |
  211. {6:Press ENTER or type command to continue}^ |
  212. ]])
  213. -- window commands do not reduce 'cmdheight' to value lower than :set by user
  214. feed('<CR>:wincmd _<CR>')
  215. screen:expect([[
  216. ^ |
  217. {1:~ }|*4
  218. {3:[No Name] }|
  219. :wincmd _ |
  220. |
  221. ]])
  222. end)
  223. -- oldtest: Test_cmdheight_tabline()
  224. it("changing 'cmdheight' when there is a tabline", function()
  225. local screen = Screen.new(60, 8)
  226. api.nvim_set_option_value('laststatus', 2, {})
  227. api.nvim_set_option_value('showtabline', 2, {})
  228. api.nvim_set_option_value('cmdheight', 1, {})
  229. screen:expect([[
  230. {5: [No Name] }{2: }|
  231. ^ |
  232. {1:~ }|*4
  233. {3:[No Name] }|
  234. |
  235. ]])
  236. end)
  237. -- oldtest: Test_rulerformat_position()
  238. it("ruler has correct position with 'rulerformat' set", function()
  239. local screen = Screen.new(20, 3)
  240. api.nvim_set_option_value('ruler', true, {})
  241. api.nvim_set_option_value('rulerformat', 'longish', {})
  242. api.nvim_set_option_value('laststatus', 0, {})
  243. api.nvim_set_option_value('winwidth', 1, {})
  244. feed [[<C-W>v<C-W>|<C-W>p]]
  245. screen:expect [[
  246. │^ |
  247. {1:~ }│{1:~}|
  248. longish |
  249. ]]
  250. end)
  251. -- oldtest: Test_rulerformat_function()
  252. it("'rulerformat' can use %!", function()
  253. local screen = Screen.new(40, 2)
  254. exec([[
  255. func TestRulerFn()
  256. return '10,20%=30%%'
  257. endfunc
  258. ]])
  259. api.nvim_set_option_value('ruler', true, {})
  260. api.nvim_set_option_value('rulerformat', '%!TestRulerFn()', {})
  261. screen:expect([[
  262. ^ |
  263. 10,20 30% |
  264. ]])
  265. end)
  266. end)
  267. describe('cmdwin', function()
  268. before_each(clear)
  269. -- oldtest: Test_cmdwin_interrupted()
  270. it('still uses a new buffer when interrupting more prompt on open', function()
  271. local screen = Screen.new(30, 16)
  272. screen:set_default_attr_ids({
  273. [0] = { bold = true, foreground = Screen.colors.Blue }, -- NonText
  274. [1] = { bold = true, reverse = true }, -- StatusLine
  275. [2] = { reverse = true }, -- StatusLineNC
  276. [3] = { bold = true, foreground = Screen.colors.SeaGreen }, -- MoreMsg
  277. [4] = { bold = true }, -- ModeMsg
  278. })
  279. command('set more')
  280. command('autocmd WinNew * highlight')
  281. feed('q:')
  282. screen:expect({ any = pesc('{3:-- More --}^') })
  283. feed('q')
  284. screen:expect([[
  285. |
  286. {0:~ }|*5
  287. {2:[No Name] }|
  288. {0::}^ |
  289. {0:~ }|*6
  290. {1:[Command Line] }|
  291. |
  292. ]])
  293. feed([[aecho 'done']])
  294. screen:expect([[
  295. |
  296. {0:~ }|*5
  297. {2:[No Name] }|
  298. {0::}echo 'done'^ |
  299. {0:~ }|*6
  300. {1:[Command Line] }|
  301. {4:-- INSERT --} |
  302. ]])
  303. feed('<CR>')
  304. screen:expect([[
  305. ^ |
  306. {0:~ }|*14
  307. done |
  308. ]])
  309. end)
  310. end)