1" Tests for :messages, :echomsg, :echoerr 2 3source check.vim 4source shared.vim 5source term_util.vim 6source view_util.vim 7 8func Test_messages() 9 let oldmore = &more 10 try 11 set nomore 12 13 let arr = map(range(10), '"hello" . v:val') 14 for s in arr 15 echomsg s | redraw 16 endfor 17 18 " get last two messages 19 redir => result 20 2messages | redraw 21 redir END 22 let msg_list = split(result, "\n") 23 call assert_equal(["hello8", "hello9"], msg_list) 24 25 " clear messages without last one 26 1messages clear 27 let msg_list = GetMessages() 28 call assert_equal(['hello9'], msg_list) 29 30 " clear all messages 31 messages clear 32 let msg_list = GetMessages() 33 call assert_equal([], msg_list) 34 finally 35 let &more = oldmore 36 endtry 37 38 call assert_fails('message 1', 'E474:') 39endfunc 40 41" Patch 7.4.1696 defined the "clearmode()" function for clearing the mode 42" indicator (e.g., "-- INSERT --") when ":stopinsert" is invoked. Message 43" output could then be disturbed when 'cmdheight' was greater than one. 44" This test ensures that the bugfix for this issue remains in place. 45func Test_stopinsert_does_not_break_message_output() 46 set cmdheight=2 47 redraw! 48 49 stopinsert | echo 'test echo' 50 call assert_equal(116, screenchar(&lines - 1, 1)) 51 call assert_equal(32, screenchar(&lines, 1)) 52 redraw! 53 54 stopinsert | echomsg 'test echomsg' 55 call assert_equal(116, screenchar(&lines - 1, 1)) 56 call assert_equal(32, screenchar(&lines, 1)) 57 redraw! 58 59 set cmdheight& 60endfunc 61 62func Test_message_completion() 63 call feedkeys(":message \<C-A>\<C-B>\"\<CR>", 'tx') 64 call assert_equal('"message clear', @:) 65endfunc 66 67func Test_echomsg() 68 call assert_equal("\nhello", execute(':echomsg "hello"')) 69 call assert_equal("\n", execute(':echomsg ""')) 70 call assert_equal("\n12345", execute(':echomsg 12345')) 71 call assert_equal("\n[]", execute(':echomsg []')) 72 call assert_equal("\n[1, 2, 3]", execute(':echomsg [1, 2, 3]')) 73 call assert_equal("\n[1, 2, []]", execute(':echomsg [1, 2, test_null_list()]')) 74 call assert_equal("\n{}", execute(':echomsg {}')) 75 call assert_equal("\n{'a': 1, 'b': 2}", execute(':echomsg {"a": 1, "b": 2}')) 76 if has('float') 77 call assert_equal("\n1.23", execute(':echomsg 1.23')) 78 endif 79 call assert_match("function('<lambda>\\d*')", execute(':echomsg {-> 1234}')) 80endfunc 81 82func Test_echoerr() 83 call test_ignore_error('IgNoRe') 84 call assert_equal("\nIgNoRe hello", execute(':echoerr "IgNoRe hello"')) 85 call assert_equal("\n12345 IgNoRe", execute(':echoerr 12345 "IgNoRe"')) 86 call assert_equal("\n[1, 2, 'IgNoRe']", execute(':echoerr [1, 2, "IgNoRe"]')) 87 call assert_equal("\n{'IgNoRe': 2, 'a': 1}", execute(':echoerr {"a": 1, "IgNoRe": 2}')) 88 if has('float') 89 call assert_equal("\n1.23 IgNoRe", execute(':echoerr 1.23 "IgNoRe"')) 90 endif 91 eval '<lambda>'->test_ignore_error() 92 call assert_match("function('<lambda>\\d*')", execute(':echoerr {-> 1234}')) 93 call test_ignore_error('RESET') 94endfunc 95 96func Test_mode_message_at_leaving_insert_by_ctrl_c() 97 if !has('terminal') || has('gui_running') 98 return 99 endif 100 101 " Set custom statusline built by user-defined function. 102 let testfile = 'Xtest.vim' 103 let lines =<< trim END 104 func StatusLine() abort 105 return "" 106 endfunc 107 set statusline=%!StatusLine() 108 set laststatus=2 109 END 110 call writefile(lines, testfile) 111 112 let rows = 10 113 let buf = term_start([GetVimProg(), '--clean', '-S', testfile], {'term_rows': rows}) 114 call TermWait(buf, 100) 115 call assert_equal('run', job_status(term_getjob(buf))) 116 117 call term_sendkeys(buf, "i") 118 call WaitForAssert({-> assert_match('^-- INSERT --\s*$', term_getline(buf, rows))}) 119 call term_sendkeys(buf, "\<C-C>") 120 call WaitForAssert({-> assert_match('^\s*$', term_getline(buf, rows))}) 121 122 call term_sendkeys(buf, ":qall!\<CR>") 123 call WaitForAssert({-> assert_equal('dead', job_status(term_getjob(buf)))}) 124 exe buf . 'bwipe!' 125 call delete(testfile) 126endfunc 127 128func Test_mode_message_at_leaving_insert_with_esc_mapped() 129 if !has('terminal') || has('gui_running') 130 return 131 endif 132 133 " Set custom statusline built by user-defined function. 134 let testfile = 'Xtest.vim' 135 let lines =<< trim END 136 set laststatus=2 137 inoremap <Esc> <Esc>00 138 END 139 call writefile(lines, testfile) 140 141 let rows = 10 142 let buf = term_start([GetVimProg(), '--clean', '-S', testfile], {'term_rows': rows}) 143 call WaitForAssert({-> assert_match('0,0-1\s*All$', term_getline(buf, rows - 1))}) 144 call assert_equal('run', job_status(term_getjob(buf))) 145 146 call term_sendkeys(buf, "i") 147 call WaitForAssert({-> assert_match('^-- INSERT --\s*$', term_getline(buf, rows))}) 148 call term_sendkeys(buf, "\<Esc>") 149 call WaitForAssert({-> assert_match('^\s*$', term_getline(buf, rows))}) 150 151 call term_sendkeys(buf, ":qall!\<CR>") 152 call WaitForAssert({-> assert_equal('dead', job_status(term_getjob(buf)))}) 153 exe buf . 'bwipe!' 154 call delete(testfile) 155endfunc 156 157func Test_echospace() 158 set noruler noshowcmd laststatus=1 159 call assert_equal(&columns - 1, v:echospace) 160 split 161 call assert_equal(&columns - 1, v:echospace) 162 set ruler 163 call assert_equal(&columns - 1, v:echospace) 164 close 165 call assert_equal(&columns - 19, v:echospace) 166 set showcmd noruler 167 call assert_equal(&columns - 12, v:echospace) 168 set showcmd ruler 169 call assert_equal(&columns - 29, v:echospace) 170 171 set ruler& showcmd& 172endfunc 173 174" Test more-prompt (see :help more-prompt). 175func Test_message_more() 176 CheckRunVimInTerminal 177 let buf = RunVimInTerminal('', {'rows': 6}) 178 call term_sendkeys(buf, ":call setline(1, range(1, 100))\n") 179 180 call term_sendkeys(buf, ":%p#\n") 181 call WaitForAssert({-> assert_equal(' 5 5', term_getline(buf, 5))}) 182 call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))}) 183 184 call term_sendkeys(buf, '?') 185 call WaitForAssert({-> assert_equal(' 5 5', term_getline(buf, 5))}) 186 call WaitForAssert({-> assert_equal('-- More -- SPACE/d/j: screen/page/line down, b/u/k: up, q: quit ', term_getline(buf, 6))}) 187 188 " Down a line with j, <CR>, <NL> or <Down>. 189 call term_sendkeys(buf, "j") 190 call WaitForAssert({-> assert_equal(' 6 6', term_getline(buf, 5))}) 191 call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))}) 192 call term_sendkeys(buf, "\<NL>") 193 call WaitForAssert({-> assert_equal(' 7 7', term_getline(buf, 5))}) 194 call term_sendkeys(buf, "\<CR>") 195 call WaitForAssert({-> assert_equal(' 8 8', term_getline(buf, 5))}) 196 call term_sendkeys(buf, "\<Down>") 197 call WaitForAssert({-> assert_equal(' 9 9', term_getline(buf, 5))}) 198 199 " Down a screen with <Space>, f, or <PageDown>. 200 call term_sendkeys(buf, 'f') 201 call WaitForAssert({-> assert_equal(' 14 14', term_getline(buf, 5))}) 202 call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))}) 203 call term_sendkeys(buf, ' ') 204 call WaitForAssert({-> assert_equal(' 19 19', term_getline(buf, 5))}) 205 call term_sendkeys(buf, "\<PageDown>") 206 call WaitForAssert({-> assert_equal(' 24 24', term_getline(buf, 5))}) 207 208 " Down a page (half a screen) with d. 209 call term_sendkeys(buf, 'd') 210 call WaitForAssert({-> assert_equal(' 27 27', term_getline(buf, 5))}) 211 212 " Down all the way with 'G'. 213 call term_sendkeys(buf, 'G') 214 call WaitForAssert({-> assert_equal('100 100', term_getline(buf, 5))}) 215 call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 6))}) 216 217 " Up a line k, <BS> or <Up>. 218 call term_sendkeys(buf, 'k') 219 call WaitForAssert({-> assert_equal(' 99 99', term_getline(buf, 5))}) 220 call term_sendkeys(buf, "\<BS>") 221 call WaitForAssert({-> assert_equal(' 98 98', term_getline(buf, 5))}) 222 call term_sendkeys(buf, "\<Up>") 223 call WaitForAssert({-> assert_equal(' 97 97', term_getline(buf, 5))}) 224 225 " Up a screen with b or <PageUp>. 226 call term_sendkeys(buf, 'b') 227 call WaitForAssert({-> assert_equal(' 92 92', term_getline(buf, 5))}) 228 call term_sendkeys(buf, "\<PageUp>") 229 call WaitForAssert({-> assert_equal(' 87 87', term_getline(buf, 5))}) 230 231 " Up a page (half a screen) with u. 232 call term_sendkeys(buf, 'u') 233 call WaitForAssert({-> assert_equal(' 84 84', term_getline(buf, 5))}) 234 235 " Up all the way with 'g'. 236 call term_sendkeys(buf, 'g') 237 call WaitForAssert({-> assert_equal(' 5 5', term_getline(buf, 5))}) 238 call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))}) 239 240 " All the way down. Pressing f should do nothing but pressing 241 " space should end the more prompt. 242 call term_sendkeys(buf, 'G') 243 call WaitForAssert({-> assert_equal('100 100', term_getline(buf, 5))}) 244 call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 6))}) 245 call term_sendkeys(buf, 'f') 246 call WaitForAssert({-> assert_equal('100 100', term_getline(buf, 5))}) 247 call term_sendkeys(buf, ' ') 248 call WaitForAssert({-> assert_equal('100', term_getline(buf, 5))}) 249 250 " Pressing g< shows the previous command output. 251 call term_sendkeys(buf, 'g<') 252 call WaitForAssert({-> assert_equal('100 100', term_getline(buf, 5))}) 253 call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 6))}) 254 255 call term_sendkeys(buf, ":%p#\n") 256 call WaitForAssert({-> assert_equal(' 5 5', term_getline(buf, 5))}) 257 call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))}) 258 259 " Stop command output with q, <Esc> or CTRL-C. 260 call term_sendkeys(buf, 'q') 261 call WaitForAssert({-> assert_equal('100', term_getline(buf, 5))}) 262 263 call StopVimInTerminal(buf) 264endfunc 265 266func Test_ask_yesno() 267 CheckRunVimInTerminal 268 let buf = RunVimInTerminal('', {'rows': 6}) 269 call term_sendkeys(buf, ":call setline(1, range(1, 2))\n") 270 271 call term_sendkeys(buf, ":2,1s/^/n/\n") 272 call WaitForAssert({-> assert_equal('Backwards range given, OK to swap (y/n)?', term_getline(buf, 6))}) 273 call term_sendkeys(buf, "n") 274 call WaitForAssert({-> assert_match('^Backwards range given, OK to swap (y/n)?n *1,1 *All$', term_getline(buf, 6))}) 275 call WaitForAssert({-> assert_equal('1', term_getline(buf, 1))}) 276 277 call term_sendkeys(buf, ":2,1s/^/Esc/\n") 278 call WaitForAssert({-> assert_equal('Backwards range given, OK to swap (y/n)?', term_getline(buf, 6))}) 279 call term_sendkeys(buf, "\<Esc>") 280 call WaitForAssert({-> assert_match('^Backwards range given, OK to swap (y/n)?n *1,1 *All$', term_getline(buf, 6))}) 281 call WaitForAssert({-> assert_equal('1', term_getline(buf, 1))}) 282 283 call term_sendkeys(buf, ":2,1s/^/y/\n") 284 call WaitForAssert({-> assert_equal('Backwards range given, OK to swap (y/n)?', term_getline(buf, 6))}) 285 call term_sendkeys(buf, "y") 286 call WaitForAssert({-> assert_match('^Backwards range given, OK to swap (y/n)?y *2,1 *All$', term_getline(buf, 6))}) 287 call WaitForAssert({-> assert_equal('y1', term_getline(buf, 1))}) 288 call WaitForAssert({-> assert_equal('y2', term_getline(buf, 2))}) 289 290 call StopVimInTerminal(buf) 291endfunc 292 293func Test_null() 294 echom test_null_list() 295 echom test_null_dict() 296 echom test_null_blob() 297 echom test_null_string() 298 echom test_null_function() 299 echom test_null_partial() 300 if has('job') 301 echom test_null_job() 302 echom test_null_channel() 303 endif 304endfunc 305 306func Test_mapping_at_hit_return_prompt() 307 nnoremap <C-B> :echo "hit ctrl-b"<CR> 308 call feedkeys(":ls\<CR>", "xt") 309 call feedkeys("\<*C-B>", "xt") 310 call assert_match('hit ctrl-b', Screenline(&lines - 1)) 311 nunmap <C-B> 312endfunc 313 314" vim: shiftwidth=2 sts=2 expandtab 315