test_cmdwin.vim 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. " Tests for editing the command line.
  2. source check.vim
  3. source screendump.vim
  4. func Test_cant_open_cmdwin_in_cmdwin()
  5. try
  6. call feedkeys("q:q::q\<CR>", "x!")
  7. catch
  8. let caught = v:exception
  9. endtry
  10. call assert_match('E1292:', caught)
  11. endfunc
  12. func Test_cmdwin_virtual_edit()
  13. enew!
  14. set ve=all cpo+=$
  15. silent normal q/s
  16. set ve= cpo-=$
  17. endfunc
  18. " Check that a :normal command can be used to stop Visual mode without side
  19. " effects.
  20. func Test_normal_escape()
  21. call feedkeys("q:i\" foo\<Esc>:normal! \<C-V>\<Esc>\<CR>:\" bar\<CR>", 'ntx')
  22. call assert_equal('" bar', @:)
  23. endfunc
  24. " This was using a pointer to a freed buffer
  25. func Test_cmdwin_freed_buffer_ptr()
  26. " this does not work on MS-Windows because renaming an open file fails
  27. CheckNotMSWindows
  28. au BufEnter * next 0| file
  29. edit 0
  30. silent! norm q/
  31. au! BufEnter
  32. bwipe!
  33. endfunc
  34. " This was resulting in a window with negative width.
  35. " The test doesn't reproduce the illegal memory access though...
  36. func Test_cmdwin_split_often()
  37. let lines = &lines
  38. let columns = &columns
  39. set t_WS=
  40. try
  41. " set encoding=iso8859
  42. set ruler
  43. winsize 0 0
  44. noremap 0 H
  45. sil norm 0000000q:
  46. catch /E36:/
  47. endtry
  48. bwipe!
  49. set encoding=utf8
  50. let &lines = lines
  51. let &columns = columns
  52. endfunc
  53. func Test_cmdwin_restore_heights()
  54. set showtabline=0 cmdheight=2 laststatus=0
  55. call feedkeys("q::set cmdheight=1\<CR>:q\<CR>", 'ntx')
  56. call assert_equal(&lines - 1, winheight(0))
  57. set showtabline=2 cmdheight=3
  58. call feedkeys("q::set showtabline=0\<CR>:q\<CR>", 'ntx')
  59. call assert_equal(&lines - 3, winheight(0))
  60. set cmdheight=1 laststatus=2
  61. call feedkeys("q::set laststatus=0\<CR>:q\<CR>", 'ntx')
  62. call assert_equal(&lines - 1, winheight(0))
  63. set laststatus=2
  64. call feedkeys("q::set laststatus=1\<CR>:q\<CR>", 'ntx')
  65. call assert_equal(&lines - 1, winheight(0))
  66. set laststatus=2
  67. belowright vsplit
  68. wincmd _
  69. let restcmds = winrestcmd()
  70. call feedkeys("q::set laststatus=1\<CR>:q\<CR>", 'ntx')
  71. " As we have 2 windows, &ls = 1 should still have a statusline on the last
  72. " window. As such, the number of available rows hasn't changed and the window
  73. " sizes should be restored.
  74. call assert_equal(restcmds, winrestcmd())
  75. set cmdheight& showtabline& laststatus&
  76. endfunc
  77. func Test_cmdwin_temp_curwin()
  78. func CheckWraps(expect_wrap)
  79. setlocal textwidth=0 wrapmargin=1
  80. call deletebufline('', 1, '$')
  81. let as = repeat('a', winwidth(0) - 2 - &wrapmargin)
  82. call setline(1, as .. ' b')
  83. normal! gww
  84. setlocal textwidth& wrapmargin&
  85. call assert_equal(a:expect_wrap ? [as, 'b'] : [as .. ' b'], getline(1, '$'))
  86. endfunc
  87. func CheckCmdWin()
  88. call assert_equal('command', win_gettype())
  89. " textoff and &wrapmargin formatting considers the cmdwin_type char.
  90. call assert_equal(1, getwininfo(win_getid())[0].textoff)
  91. call CheckWraps(1)
  92. endfunc
  93. func CheckOtherWin()
  94. call assert_equal('', win_gettype())
  95. call assert_equal(0, getwininfo(win_getid())[0].textoff)
  96. call CheckWraps(0)
  97. endfunc
  98. call feedkeys("q::call CheckCmdWin()\<CR>:call win_execute(win_getid(winnr('#')), 'call CheckOtherWin()')\<CR>:q<CR>", 'ntx')
  99. %bwipe!
  100. delfunc CheckWraps
  101. delfunc CheckCmdWin
  102. delfunc CheckOtherWin
  103. endfunc
  104. func Test_cmdwin_interrupted()
  105. func CheckInterrupted()
  106. call feedkeys("q::call assert_equal('', getcmdwintype())\<CR>:call assert_equal('', getcmdtype())\<CR>:q<CR>", 'ntx')
  107. endfunc
  108. augroup CmdWin
  109. " While opening the cmdwin's split:
  110. " Close the cmdwin's window.
  111. au WinEnter * ++once quit
  112. call CheckInterrupted()
  113. " Close the old window.
  114. au WinEnter * ++once execute winnr('#') 'quit'
  115. call CheckInterrupted()
  116. " Switch back to the old window.
  117. au WinEnter * ++once wincmd p
  118. call CheckInterrupted()
  119. " Change the old window's buffer.
  120. au WinEnter * ++once call win_execute(win_getid(winnr('#')), 'enew')
  121. call CheckInterrupted()
  122. " Using BufLeave autocmds as cmdwin restrictions do not apply to them when
  123. " fired from opening the cmdwin...
  124. " After opening the cmdwin's split, while creating the cmdwin's buffer:
  125. " Delete the cmdwin's buffer.
  126. au BufLeave * ++once bwipe
  127. call CheckInterrupted()
  128. " Close the cmdwin's window.
  129. au BufLeave * ++once quit
  130. call CheckInterrupted()
  131. " Close the old window.
  132. au BufLeave * ++once execute winnr('#') 'quit'
  133. call CheckInterrupted()
  134. " Switch to a different window.
  135. au BufLeave * ++once split
  136. call CheckInterrupted()
  137. " Change the old window's buffer.
  138. au BufLeave * ++once call win_execute(win_getid(winnr('#')), 'enew')
  139. call CheckInterrupted()
  140. " However, changing the current buffer is OK and does not interrupt.
  141. au BufLeave * ++once edit other
  142. call feedkeys("q::let t=getcmdwintype()\<CR>:let b=bufnr()\<CR>:clo<CR>", 'ntx')
  143. call assert_equal(':', t)
  144. call assert_equal(1, bufloaded('other'))
  145. call assert_notequal(b, bufnr('other'))
  146. augroup END
  147. " No autocmds should remain, but clear the augroup to be sure.
  148. augroup CmdWin
  149. au!
  150. augroup END
  151. %bwipe!
  152. delfunc CheckInterrupted
  153. endfunc
  154. func Test_cmdwin_existing_bufname()
  155. func CheckName()
  156. call assert_equal(1, getbufinfo('')[0].command)
  157. call assert_equal(0, getbufinfo('[Command Line]')[0].command)
  158. call assert_match('#a\s*"\[Command Line\]"', execute('ls'))
  159. call assert_match('%a\s*"\[Command Line\]"', execute('ls'))
  160. endfunc
  161. file [Command Line]
  162. call feedkeys("q::call CheckName()\<CR>:q\<CR>", 'ntx')
  163. 0file
  164. delfunc CheckName
  165. endfunc
  166. " vim: shiftwidth=2 sts=2 expandtab