1" Tests for :messages, :echomsg, :echoerr 2 3source shared.vim 4 5function Test_messages() 6 let oldmore = &more 7 try 8 set nomore 9 " Avoid the "message maintainer" line. 10 let $LANG = '' 11 12 let arr = map(range(10), '"hello" . v:val') 13 for s in arr 14 echomsg s | redraw 15 endfor 16 let result = '' 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 redir => result 28 redraw | messages 29 redir END 30 let msg_list = split(result, "\n") 31 call assert_equal(['hello9'], msg_list) 32 33 " clear all messages 34 messages clear 35 redir => result 36 redraw | messages 37 redir END 38 call assert_equal('', result) 39 finally 40 let &more = oldmore 41 endtry 42endfunction 43 44" Patch 7.4.1696 defined the "clearmode()" function for clearing the mode 45" indicator (e.g., "-- INSERT --") when ":stopinsert" is invoked. Message 46" output could then be disturbed when 'cmdheight' was greater than one. 47" This test ensures that the bugfix for this issue remains in place. 48func Test_stopinsert_does_not_break_message_output() 49 set cmdheight=2 50 redraw! 51 52 stopinsert | echo 'test echo' 53 call assert_equal(116, screenchar(&lines - 1, 1)) 54 call assert_equal(32, screenchar(&lines, 1)) 55 redraw! 56 57 stopinsert | echomsg 'test echomsg' 58 call assert_equal(116, screenchar(&lines - 1, 1)) 59 call assert_equal(32, screenchar(&lines, 1)) 60 redraw! 61 62 set cmdheight& 63endfunc 64 65func Test_message_completion() 66 call feedkeys(":message \<C-A>\<C-B>\"\<CR>", 'tx') 67 call assert_equal('"message clear', @:) 68endfunc 69 70func Test_echomsg() 71 call assert_equal("\nhello", execute(':echomsg "hello"')) 72 call assert_equal("\n", execute(':echomsg ""')) 73 call assert_equal("\n12345", execute(':echomsg 12345')) 74 call assert_equal("\n[]", execute(':echomsg []')) 75 call assert_equal("\n[1, 2, 3]", execute(':echomsg [1, 2, 3]')) 76 call assert_equal("\n{}", execute(':echomsg {}')) 77 call assert_equal("\n{'a': 1, 'b': 2}", execute(':echomsg {"a": 1, "b": 2}')) 78 if has('float') 79 call assert_equal("\n1.23", execute(':echomsg 1.23')) 80 endif 81 call assert_match("function('<lambda>\\d*')", execute(':echomsg {-> 1234}')) 82endfunc 83 84func Test_echoerr() 85 call test_ignore_error('IgNoRe') 86 call assert_equal("\nIgNoRe hello", execute(':echoerr "IgNoRe hello"')) 87 call assert_equal("\n12345 IgNoRe", execute(':echoerr 12345 "IgNoRe"')) 88 call assert_equal("\n[1, 2, 'IgNoRe']", execute(':echoerr [1, 2, "IgNoRe"]')) 89 call assert_equal("\n{'IgNoRe': 2, 'a': 1}", execute(':echoerr {"a": 1, "IgNoRe": 2}')) 90 if has('float') 91 call assert_equal("\n1.23 IgNoRe", execute(':echoerr 1.23 "IgNoRe"')) 92 endif 93 call test_ignore_error('<lambda>') 94 call assert_match("function('<lambda>\\d*')", execute(':echoerr {-> 1234}')) 95 call test_ignore_error('RESET') 96endfunc 97 98func Test_mode_message_at_leaving_insert_by_ctrl_c() 99 if !has('terminal') || has('gui_running') 100 return 101 endif 102 103 " Set custom statusline built by user-defined function. 104 let testfile = 'Xtest.vim' 105 let lines =<< trim END 106 func StatusLine() abort 107 return "" 108 endfunc 109 set statusline=%!StatusLine() 110 set laststatus=2 111 END 112 call writefile(lines, testfile) 113 114 let rows = 10 115 let buf = term_start([GetVimProg(), '--clean', '-S', testfile], {'term_rows': rows}) 116 call term_wait(buf, 200) 117 call assert_equal('run', job_status(term_getjob(buf))) 118 119 call term_sendkeys(buf, "i") 120 call WaitForAssert({-> assert_match('^-- INSERT --\s*$', term_getline(buf, rows))}) 121 call term_sendkeys(buf, "\<C-C>") 122 call WaitForAssert({-> assert_match('^\s*$', term_getline(buf, rows))}) 123 124 call term_sendkeys(buf, ":qall!\<CR>") 125 call WaitForAssert({-> assert_equal('dead', job_status(term_getjob(buf)))}) 126 exe buf . 'bwipe!' 127 call delete(testfile) 128endfunc 129 130func Test_mode_message_at_leaving_insert_with_esc_mapped() 131 if !has('terminal') || has('gui_running') 132 return 133 endif 134 135 " Set custom statusline built by user-defined function. 136 let testfile = 'Xtest.vim' 137 let lines =<< trim END 138 set laststatus=2 139 inoremap <Esc> <Esc>00 140 END 141 call writefile(lines, testfile) 142 143 let rows = 10 144 let buf = term_start([GetVimProg(), '--clean', '-S', testfile], {'term_rows': rows}) 145 call term_wait(buf, 200) 146 call assert_equal('run', job_status(term_getjob(buf))) 147 148 call term_sendkeys(buf, "i") 149 call WaitForAssert({-> assert_match('^-- INSERT --\s*$', term_getline(buf, rows))}) 150 call term_sendkeys(buf, "\<Esc>") 151 call WaitForAssert({-> assert_match('^\s*$', term_getline(buf, rows))}) 152 153 call term_sendkeys(buf, ":qall!\<CR>") 154 call WaitForAssert({-> assert_equal('dead', job_status(term_getjob(buf)))}) 155 exe buf . 'bwipe!' 156 call delete(testfile) 157endfunc 158