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