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