blob: f122917ba7e33ef510e0ad9b792282a7b63641f0 [file] [log] [blame]
Bram Moolenaar461a7fc2018-12-22 13:28:07 +01001" Tests for :messages, :echomsg, :echoerr
Bram Moolenaar451f8492016-04-14 17:16:22 +02002
Bram Moolenaarabc7c7f2019-04-20 15:10:13 +02003source shared.vim
4
Bram Moolenaar451f8492016-04-14 17:16:22 +02005function Test_messages()
6 let oldmore = &more
7 try
8 set nomore
Bram Moolenaarbea1ede2016-04-14 19:44:36 +02009 " Avoid the "message maintainer" line.
10 let $LANG = ''
Bram Moolenaar451f8492016-04-14 17:16:22 +020011
12 let arr = map(range(10), '"hello" . v:val')
13 for s in arr
14 echomsg s | redraw
15 endfor
16 let result = ''
17
Bram Moolenaarbea1ede2016-04-14 19:44:36 +020018 " get last two messages
Bram Moolenaar451f8492016-04-14 17:16:22 +020019 redir => result
20 2messages | redraw
21 redir END
Bram Moolenaarbea1ede2016-04-14 19:44:36 +020022 let msg_list = split(result, "\n")
23 call assert_equal(["hello8", "hello9"], msg_list)
Bram Moolenaar451f8492016-04-14 17:16:22 +020024
25 " clear messages without last one
26 1messages clear
27 redir => result
Bram Moolenaarbea1ede2016-04-14 19:44:36 +020028 redraw | messages
Bram Moolenaar451f8492016-04-14 17:16:22 +020029 redir END
Bram Moolenaarbea1ede2016-04-14 19:44:36 +020030 let msg_list = split(result, "\n")
31 call assert_equal(['hello9'], msg_list)
Bram Moolenaar451f8492016-04-14 17:16:22 +020032
33 " clear all messages
34 messages clear
35 redir => result
Bram Moolenaarbea1ede2016-04-14 19:44:36 +020036 redraw | messages
Bram Moolenaar451f8492016-04-14 17:16:22 +020037 redir END
Bram Moolenaarbea1ede2016-04-14 19:44:36 +020038 call assert_equal('', result)
Bram Moolenaar451f8492016-04-14 17:16:22 +020039 finally
40 let &more = oldmore
41 endtry
42endfunction
Bram Moolenaar2abad542018-05-19 14:43:45 +020043
Bram Moolenaarf52f9ea2018-06-27 20:49:44 +020044" Patch 7.4.1696 defined the "clearmode()" function for clearing the mode
Bram Moolenaar2abad542018-05-19 14:43:45 +020045" 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.
Bram Moolenaar1e115362019-01-09 23:01:02 +010048func Test_stopinsert_does_not_break_message_output()
Bram Moolenaar2abad542018-05-19 14:43:45 +020049 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&
Bram Moolenaar1e115362019-01-09 23:01:02 +010063endfunc
Bram Moolenaarb513d302018-12-02 14:55:08 +010064
65func Test_message_completion()
66 call feedkeys(":message \<C-A>\<C-B>\"\<CR>", 'tx')
67 call assert_equal('"message clear', @:)
68endfunc
Bram Moolenaar461a7fc2018-12-22 13:28:07 +010069
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
Bram Moolenaarabc7c7f2019-04-20 15:10:13 +020097
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'
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200105 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)
Bram Moolenaarabc7c7f2019-04-20 15:10:13 +0200113
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
Bram Moolenaar4c25bd72019-04-20 23:38:07 +0200129
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'
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200137 let lines =<< trim END
138 set laststatus=2
139 inoremap <Esc> <Esc>00
140 END
141 call writefile(lines, testfile)
Bram Moolenaar4c25bd72019-04-20 23:38:07 +0200142
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
Bram Moolenaar37f4cbd2019-08-23 20:58:45 +0200158
159func Test_echospace()
160 set noruler noshowcmd laststatus=1
161 call assert_equal(&columns - 1, v:echospace)
162 split
163 call assert_equal(&columns - 1, v:echospace)
164 set ruler
165 call assert_equal(&columns - 1, v:echospace)
166 close
167 call assert_equal(&columns - 19, v:echospace)
168 set showcmd noruler
169 call assert_equal(&columns - 12, v:echospace)
170 set showcmd ruler
171 call assert_equal(&columns - 29, v:echospace)
172
173 set ruler& showcmd&
174endfunc