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 | 494e906 | 2020-05-31 21:28:02 +0200 | [diff] [blame] | 3 | source check.vim |
Bram Moolenaar | abc7c7f | 2019-04-20 15:10:13 +0200 | [diff] [blame] | 4 | source shared.vim |
Bram Moolenaar | c6d539b | 2019-12-28 17:10:46 +0100 | [diff] [blame] | 5 | source term_util.vim |
Bram Moolenaar | b42c0d5 | 2020-05-29 22:41:41 +0200 | [diff] [blame] | 6 | source view_util.vim |
Bram Moolenaar | 3d30af8 | 2020-10-13 22:15:56 +0200 | [diff] [blame] | 7 | source screendump.vim |
Bram Moolenaar | abc7c7f | 2019-04-20 15:10:13 +0200 | [diff] [blame] | 8 | |
Bram Moolenaar | 49b2fb3 | 2020-04-25 17:13:56 +0200 | [diff] [blame] | 9 | func Test_messages() |
Bram Moolenaar | 451f849 | 2016-04-14 17:16:22 +0200 | [diff] [blame] | 10 | let oldmore = &more |
| 11 | try |
| 12 | set nomore |
| 13 | |
| 14 | let arr = map(range(10), '"hello" . v:val') |
| 15 | for s in arr |
| 16 | echomsg s | redraw |
| 17 | endfor |
Bram Moolenaar | 451f849 | 2016-04-14 17:16:22 +0200 | [diff] [blame] | 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 |
Bram Moolenaar | 49b2fb3 | 2020-04-25 17:13:56 +0200 | [diff] [blame] | 28 | let msg_list = GetMessages() |
Bram Moolenaar | bea1ede | 2016-04-14 19:44:36 +0200 | [diff] [blame] | 29 | call assert_equal(['hello9'], msg_list) |
Bram Moolenaar | 451f849 | 2016-04-14 17:16:22 +0200 | [diff] [blame] | 30 | |
| 31 | " clear all messages |
| 32 | messages clear |
Bram Moolenaar | 49b2fb3 | 2020-04-25 17:13:56 +0200 | [diff] [blame] | 33 | let msg_list = GetMessages() |
| 34 | call assert_equal([], msg_list) |
Bram Moolenaar | 451f849 | 2016-04-14 17:16:22 +0200 | [diff] [blame] | 35 | finally |
| 36 | let &more = oldmore |
| 37 | endtry |
Bram Moolenaar | 067297e | 2020-04-13 19:55:50 +0200 | [diff] [blame] | 38 | |
| 39 | call assert_fails('message 1', 'E474:') |
Bram Moolenaar | 49b2fb3 | 2020-04-25 17:13:56 +0200 | [diff] [blame] | 40 | endfunc |
Bram Moolenaar | 2abad54 | 2018-05-19 14:43:45 +0200 | [diff] [blame] | 41 | |
Bram Moolenaar | f52f9ea | 2018-06-27 20:49:44 +0200 | [diff] [blame] | 42 | " Patch 7.4.1696 defined the "clearmode()" function for clearing the mode |
Bram Moolenaar | 2abad54 | 2018-05-19 14:43:45 +0200 | [diff] [blame] | 43 | " indicator (e.g., "-- INSERT --") when ":stopinsert" is invoked. Message |
| 44 | " output could then be disturbed when 'cmdheight' was greater than one. |
| 45 | " This test ensures that the bugfix for this issue remains in place. |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 46 | func Test_stopinsert_does_not_break_message_output() |
Bram Moolenaar | 2abad54 | 2018-05-19 14:43:45 +0200 | [diff] [blame] | 47 | set cmdheight=2 |
| 48 | redraw! |
| 49 | |
| 50 | stopinsert | echo 'test echo' |
| 51 | call assert_equal(116, screenchar(&lines - 1, 1)) |
| 52 | call assert_equal(32, screenchar(&lines, 1)) |
| 53 | redraw! |
| 54 | |
| 55 | stopinsert | echomsg 'test echomsg' |
| 56 | call assert_equal(116, screenchar(&lines - 1, 1)) |
| 57 | call assert_equal(32, screenchar(&lines, 1)) |
| 58 | redraw! |
| 59 | |
| 60 | set cmdheight& |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 61 | endfunc |
Bram Moolenaar | b513d30 | 2018-12-02 14:55:08 +0100 | [diff] [blame] | 62 | |
| 63 | func Test_message_completion() |
| 64 | call feedkeys(":message \<C-A>\<C-B>\"\<CR>", 'tx') |
| 65 | call assert_equal('"message clear', @:) |
| 66 | endfunc |
Bram Moolenaar | 461a7fc | 2018-12-22 13:28:07 +0100 | [diff] [blame] | 67 | |
| 68 | func Test_echomsg() |
| 69 | call assert_equal("\nhello", execute(':echomsg "hello"')) |
| 70 | call assert_equal("\n", execute(':echomsg ""')) |
| 71 | call assert_equal("\n12345", execute(':echomsg 12345')) |
| 72 | call assert_equal("\n[]", execute(':echomsg []')) |
| 73 | call assert_equal("\n[1, 2, 3]", execute(':echomsg [1, 2, 3]')) |
Bram Moolenaar | db950e4 | 2020-04-22 19:13:19 +0200 | [diff] [blame] | 74 | 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] | 75 | call assert_equal("\n{}", execute(':echomsg {}')) |
| 76 | call assert_equal("\n{'a': 1, 'b': 2}", execute(':echomsg {"a": 1, "b": 2}')) |
| 77 | if has('float') |
| 78 | call assert_equal("\n1.23", execute(':echomsg 1.23')) |
| 79 | endif |
| 80 | call assert_match("function('<lambda>\\d*')", execute(':echomsg {-> 1234}')) |
| 81 | endfunc |
| 82 | |
| 83 | func Test_echoerr() |
| 84 | call test_ignore_error('IgNoRe') |
| 85 | call assert_equal("\nIgNoRe hello", execute(':echoerr "IgNoRe hello"')) |
| 86 | call assert_equal("\n12345 IgNoRe", execute(':echoerr 12345 "IgNoRe"')) |
| 87 | call assert_equal("\n[1, 2, 'IgNoRe']", execute(':echoerr [1, 2, "IgNoRe"]')) |
| 88 | call assert_equal("\n{'IgNoRe': 2, 'a': 1}", execute(':echoerr {"a": 1, "IgNoRe": 2}')) |
| 89 | if has('float') |
| 90 | call assert_equal("\n1.23 IgNoRe", execute(':echoerr 1.23 "IgNoRe"')) |
| 91 | endif |
Bram Moolenaar | ce90e36 | 2019-09-08 18:58:44 +0200 | [diff] [blame] | 92 | eval '<lambda>'->test_ignore_error() |
Bram Moolenaar | 461a7fc | 2018-12-22 13:28:07 +0100 | [diff] [blame] | 93 | call assert_match("function('<lambda>\\d*')", execute(':echoerr {-> 1234}')) |
| 94 | call test_ignore_error('RESET') |
| 95 | endfunc |
Bram Moolenaar | abc7c7f | 2019-04-20 15:10:13 +0200 | [diff] [blame] | 96 | |
| 97 | func Test_mode_message_at_leaving_insert_by_ctrl_c() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 98 | CheckFeature terminal |
| 99 | CheckNotGui |
Bram Moolenaar | abc7c7f | 2019-04-20 15:10:13 +0200 | [diff] [blame] | 100 | |
| 101 | " Set custom statusline built by user-defined function. |
| 102 | let testfile = 'Xtest.vim' |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 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) |
Bram Moolenaar | abc7c7f | 2019-04-20 15:10:13 +0200 | [diff] [blame] | 111 | |
| 112 | let rows = 10 |
| 113 | let buf = term_start([GetVimProg(), '--clean', '-S', testfile], {'term_rows': rows}) |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 114 | call TermWait(buf, 100) |
Bram Moolenaar | abc7c7f | 2019-04-20 15:10:13 +0200 | [diff] [blame] | 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) |
| 126 | endfunc |
Bram Moolenaar | 4c25bd7 | 2019-04-20 23:38:07 +0200 | [diff] [blame] | 127 | |
| 128 | func Test_mode_message_at_leaving_insert_with_esc_mapped() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 129 | CheckFeature terminal |
| 130 | CheckNotGui |
Bram Moolenaar | 4c25bd7 | 2019-04-20 23:38:07 +0200 | [diff] [blame] | 131 | |
| 132 | " Set custom statusline built by user-defined function. |
| 133 | let testfile = 'Xtest.vim' |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 134 | let lines =<< trim END |
| 135 | set laststatus=2 |
| 136 | inoremap <Esc> <Esc>00 |
| 137 | END |
| 138 | call writefile(lines, testfile) |
Bram Moolenaar | 4c25bd7 | 2019-04-20 23:38:07 +0200 | [diff] [blame] | 139 | |
| 140 | let rows = 10 |
| 141 | let buf = term_start([GetVimProg(), '--clean', '-S', testfile], {'term_rows': rows}) |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 142 | 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] | 143 | call assert_equal('run', job_status(term_getjob(buf))) |
| 144 | |
| 145 | call term_sendkeys(buf, "i") |
| 146 | call WaitForAssert({-> assert_match('^-- INSERT --\s*$', term_getline(buf, rows))}) |
| 147 | call term_sendkeys(buf, "\<Esc>") |
| 148 | call WaitForAssert({-> assert_match('^\s*$', term_getline(buf, rows))}) |
| 149 | |
| 150 | call term_sendkeys(buf, ":qall!\<CR>") |
| 151 | call WaitForAssert({-> assert_equal('dead', job_status(term_getjob(buf)))}) |
| 152 | exe buf . 'bwipe!' |
| 153 | call delete(testfile) |
| 154 | endfunc |
Bram Moolenaar | 37f4cbd | 2019-08-23 20:58:45 +0200 | [diff] [blame] | 155 | |
| 156 | func Test_echospace() |
| 157 | set noruler noshowcmd laststatus=1 |
| 158 | call assert_equal(&columns - 1, v:echospace) |
| 159 | split |
| 160 | call assert_equal(&columns - 1, v:echospace) |
| 161 | set ruler |
| 162 | call assert_equal(&columns - 1, v:echospace) |
| 163 | close |
| 164 | call assert_equal(&columns - 19, v:echospace) |
| 165 | set showcmd noruler |
| 166 | call assert_equal(&columns - 12, v:echospace) |
| 167 | set showcmd ruler |
| 168 | call assert_equal(&columns - 29, v:echospace) |
| 169 | |
| 170 | set ruler& showcmd& |
| 171 | endfunc |
Bram Moolenaar | c6d539b | 2019-12-28 17:10:46 +0100 | [diff] [blame] | 172 | |
| 173 | " Test more-prompt (see :help more-prompt). |
| 174 | func Test_message_more() |
Bram Moolenaar | 494e906 | 2020-05-31 21:28:02 +0200 | [diff] [blame] | 175 | CheckRunVimInTerminal |
Bram Moolenaar | c6d539b | 2019-12-28 17:10:46 +0100 | [diff] [blame] | 176 | let buf = RunVimInTerminal('', {'rows': 6}) |
| 177 | call term_sendkeys(buf, ":call setline(1, range(1, 100))\n") |
| 178 | |
zeertzjq | 46af7bc | 2022-07-28 12:34:09 +0100 | [diff] [blame] | 179 | call term_sendkeys(buf, ":%pfoo\<C-H>\<C-H>\<C-H>#") |
| 180 | call WaitForAssert({-> assert_equal(':%p#', term_getline(buf, 6))}) |
| 181 | call term_sendkeys(buf, "\n") |
Bram Moolenaar | c6d539b | 2019-12-28 17:10:46 +0100 | [diff] [blame] | 182 | call WaitForAssert({-> assert_equal(' 5 5', term_getline(buf, 5))}) |
| 183 | call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))}) |
| 184 | |
| 185 | call term_sendkeys(buf, '?') |
| 186 | call WaitForAssert({-> assert_equal(' 5 5', term_getline(buf, 5))}) |
| 187 | call WaitForAssert({-> assert_equal('-- More -- SPACE/d/j: screen/page/line down, b/u/k: up, q: quit ', term_getline(buf, 6))}) |
| 188 | |
| 189 | " Down a line with j, <CR>, <NL> or <Down>. |
| 190 | call term_sendkeys(buf, "j") |
| 191 | call WaitForAssert({-> assert_equal(' 6 6', term_getline(buf, 5))}) |
| 192 | call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))}) |
| 193 | call term_sendkeys(buf, "\<NL>") |
| 194 | call WaitForAssert({-> assert_equal(' 7 7', term_getline(buf, 5))}) |
| 195 | call term_sendkeys(buf, "\<CR>") |
| 196 | call WaitForAssert({-> assert_equal(' 8 8', term_getline(buf, 5))}) |
| 197 | call term_sendkeys(buf, "\<Down>") |
| 198 | call WaitForAssert({-> assert_equal(' 9 9', term_getline(buf, 5))}) |
| 199 | |
| 200 | " Down a screen with <Space>, f, or <PageDown>. |
| 201 | call term_sendkeys(buf, 'f') |
| 202 | call WaitForAssert({-> assert_equal(' 14 14', term_getline(buf, 5))}) |
| 203 | call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))}) |
| 204 | call term_sendkeys(buf, ' ') |
| 205 | call WaitForAssert({-> assert_equal(' 19 19', term_getline(buf, 5))}) |
| 206 | call term_sendkeys(buf, "\<PageDown>") |
| 207 | call WaitForAssert({-> assert_equal(' 24 24', term_getline(buf, 5))}) |
| 208 | |
| 209 | " Down a page (half a screen) with d. |
| 210 | call term_sendkeys(buf, 'd') |
| 211 | call WaitForAssert({-> assert_equal(' 27 27', term_getline(buf, 5))}) |
| 212 | |
| 213 | " Down all the way with 'G'. |
| 214 | call term_sendkeys(buf, 'G') |
| 215 | call WaitForAssert({-> assert_equal('100 100', term_getline(buf, 5))}) |
| 216 | call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 6))}) |
| 217 | |
| 218 | " Up a line k, <BS> or <Up>. |
| 219 | call term_sendkeys(buf, 'k') |
| 220 | call WaitForAssert({-> assert_equal(' 99 99', term_getline(buf, 5))}) |
| 221 | call term_sendkeys(buf, "\<BS>") |
| 222 | call WaitForAssert({-> assert_equal(' 98 98', term_getline(buf, 5))}) |
| 223 | call term_sendkeys(buf, "\<Up>") |
| 224 | call WaitForAssert({-> assert_equal(' 97 97', term_getline(buf, 5))}) |
| 225 | |
| 226 | " Up a screen with b or <PageUp>. |
| 227 | call term_sendkeys(buf, 'b') |
| 228 | call WaitForAssert({-> assert_equal(' 92 92', term_getline(buf, 5))}) |
| 229 | call term_sendkeys(buf, "\<PageUp>") |
| 230 | call WaitForAssert({-> assert_equal(' 87 87', term_getline(buf, 5))}) |
| 231 | |
| 232 | " Up a page (half a screen) with u. |
| 233 | call term_sendkeys(buf, 'u') |
| 234 | call WaitForAssert({-> assert_equal(' 84 84', term_getline(buf, 5))}) |
| 235 | |
| 236 | " Up all the way with 'g'. |
| 237 | call term_sendkeys(buf, 'g') |
zeertzjq | ecdc82e | 2022-07-25 19:50:57 +0100 | [diff] [blame] | 238 | call WaitForAssert({-> assert_equal(' 4 4', term_getline(buf, 5))}) |
| 239 | call WaitForAssert({-> assert_equal(':%p#', term_getline(buf, 1))}) |
Bram Moolenaar | c6d539b | 2019-12-28 17:10:46 +0100 | [diff] [blame] | 240 | call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))}) |
| 241 | |
| 242 | " All the way down. Pressing f should do nothing but pressing |
| 243 | " space should end the more prompt. |
| 244 | call term_sendkeys(buf, 'G') |
| 245 | call WaitForAssert({-> assert_equal('100 100', term_getline(buf, 5))}) |
| 246 | call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 6))}) |
| 247 | call term_sendkeys(buf, 'f') |
| 248 | call WaitForAssert({-> assert_equal('100 100', term_getline(buf, 5))}) |
| 249 | call term_sendkeys(buf, ' ') |
| 250 | call WaitForAssert({-> assert_equal('100', term_getline(buf, 5))}) |
| 251 | |
| 252 | " Pressing g< shows the previous command output. |
| 253 | call term_sendkeys(buf, 'g<') |
| 254 | call WaitForAssert({-> assert_equal('100 100', term_getline(buf, 5))}) |
| 255 | call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 6))}) |
| 256 | |
zeertzjq | 46af7bc | 2022-07-28 12:34:09 +0100 | [diff] [blame] | 257 | " A command line that doesn't print text is appended to scrollback, |
| 258 | " even if it invokes a nested command line. |
| 259 | call term_sendkeys(buf, ":\<C-R>=':'\<CR>:\<CR>g<") |
| 260 | call WaitForAssert({-> assert_equal('100 100', term_getline(buf, 4))}) |
| 261 | call WaitForAssert({-> assert_equal(':::', term_getline(buf, 5))}) |
| 262 | call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 6))}) |
| 263 | |
Bram Moolenaar | c6d539b | 2019-12-28 17:10:46 +0100 | [diff] [blame] | 264 | call term_sendkeys(buf, ":%p#\n") |
| 265 | call WaitForAssert({-> assert_equal(' 5 5', term_getline(buf, 5))}) |
| 266 | call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))}) |
| 267 | |
| 268 | " Stop command output with q, <Esc> or CTRL-C. |
| 269 | call term_sendkeys(buf, 'q') |
| 270 | call WaitForAssert({-> assert_equal('100', term_getline(buf, 5))}) |
| 271 | |
Bram Moolenaar | f4fcedc | 2021-03-15 18:36:20 +0100 | [diff] [blame] | 272 | " Execute a : command from the more prompt |
| 273 | call term_sendkeys(buf, ":%p#\n") |
| 274 | call term_wait(buf) |
| 275 | call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))}) |
| 276 | call term_sendkeys(buf, ":") |
| 277 | call term_wait(buf) |
| 278 | call WaitForAssert({-> assert_equal(':', term_getline(buf, 6))}) |
| 279 | call term_sendkeys(buf, "echo 'Hello'\n") |
| 280 | call term_wait(buf) |
| 281 | call WaitForAssert({-> assert_equal('Hello ', term_getline(buf, 5))}) |
| 282 | |
Bram Moolenaar | 43c60ed | 2020-02-02 15:55:19 +0100 | [diff] [blame] | 283 | call StopVimInTerminal(buf) |
| 284 | endfunc |
| 285 | |
| 286 | func Test_ask_yesno() |
Bram Moolenaar | 494e906 | 2020-05-31 21:28:02 +0200 | [diff] [blame] | 287 | CheckRunVimInTerminal |
Bram Moolenaar | 43c60ed | 2020-02-02 15:55:19 +0100 | [diff] [blame] | 288 | let buf = RunVimInTerminal('', {'rows': 6}) |
| 289 | call term_sendkeys(buf, ":call setline(1, range(1, 2))\n") |
| 290 | |
| 291 | call term_sendkeys(buf, ":2,1s/^/n/\n") |
| 292 | call WaitForAssert({-> assert_equal('Backwards range given, OK to swap (y/n)?', term_getline(buf, 6))}) |
| 293 | call term_sendkeys(buf, "n") |
| 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/^/Esc/\n") |
| 298 | call WaitForAssert({-> assert_equal('Backwards range given, OK to swap (y/n)?', term_getline(buf, 6))}) |
| 299 | call term_sendkeys(buf, "\<Esc>") |
| 300 | call WaitForAssert({-> assert_match('^Backwards range given, OK to swap (y/n)?n *1,1 *All$', term_getline(buf, 6))}) |
| 301 | call WaitForAssert({-> assert_equal('1', term_getline(buf, 1))}) |
| 302 | |
| 303 | call term_sendkeys(buf, ":2,1s/^/y/\n") |
| 304 | call WaitForAssert({-> assert_equal('Backwards range given, OK to swap (y/n)?', term_getline(buf, 6))}) |
| 305 | call term_sendkeys(buf, "y") |
| 306 | call WaitForAssert({-> assert_match('^Backwards range given, OK to swap (y/n)?y *2,1 *All$', term_getline(buf, 6))}) |
| 307 | call WaitForAssert({-> assert_equal('y1', term_getline(buf, 1))}) |
| 308 | call WaitForAssert({-> assert_equal('y2', term_getline(buf, 2))}) |
| 309 | |
Bram Moolenaar | c6d539b | 2019-12-28 17:10:46 +0100 | [diff] [blame] | 310 | call StopVimInTerminal(buf) |
| 311 | endfunc |
Bram Moolenaar | 9db2afe | 2020-01-08 18:56:20 +0100 | [diff] [blame] | 312 | |
| 313 | func Test_null() |
| 314 | echom test_null_list() |
| 315 | echom test_null_dict() |
| 316 | echom test_null_blob() |
Bram Moolenaar | 9db2afe | 2020-01-08 18:56:20 +0100 | [diff] [blame] | 317 | echom test_null_string() |
Bram Moolenaar | 92b83cc | 2020-04-25 15:24:44 +0200 | [diff] [blame] | 318 | echom test_null_function() |
Bram Moolenaar | 9db2afe | 2020-01-08 18:56:20 +0100 | [diff] [blame] | 319 | echom test_null_partial() |
Bram Moolenaar | da292b0 | 2020-01-08 19:27:40 +0100 | [diff] [blame] | 320 | if has('job') |
| 321 | echom test_null_job() |
| 322 | echom test_null_channel() |
| 323 | endif |
Bram Moolenaar | 9db2afe | 2020-01-08 18:56:20 +0100 | [diff] [blame] | 324 | endfunc |
Bram Moolenaar | 92b83cc | 2020-04-25 15:24:44 +0200 | [diff] [blame] | 325 | |
Bram Moolenaar | b42c0d5 | 2020-05-29 22:41:41 +0200 | [diff] [blame] | 326 | func Test_mapping_at_hit_return_prompt() |
| 327 | nnoremap <C-B> :echo "hit ctrl-b"<CR> |
| 328 | call feedkeys(":ls\<CR>", "xt") |
Bram Moolenaar | fccd93f | 2020-05-31 22:06:51 +0200 | [diff] [blame] | 329 | call feedkeys("\<*C-B>", "xt") |
Bram Moolenaar | b42c0d5 | 2020-05-29 22:41:41 +0200 | [diff] [blame] | 330 | call assert_match('hit ctrl-b', Screenline(&lines - 1)) |
| 331 | nunmap <C-B> |
| 332 | endfunc |
| 333 | |
Bram Moolenaar | 3d30af8 | 2020-10-13 22:15:56 +0200 | [diff] [blame] | 334 | func Test_quit_long_message() |
| 335 | CheckScreendump |
| 336 | |
| 337 | let content =<< trim END |
| 338 | echom range(9999)->join("\x01") |
| 339 | END |
| 340 | call writefile(content, 'Xtest_quit_message') |
| 341 | let buf = RunVimInTerminal('-S Xtest_quit_message', #{rows: 6}) |
| 342 | call term_sendkeys(buf, "q") |
| 343 | call VerifyScreenDump(buf, 'Test_quit_long_message', {}) |
| 344 | |
| 345 | " clean up |
| 346 | call StopVimInTerminal(buf) |
Bram Moolenaar | ac665c2 | 2020-12-08 20:39:15 +0100 | [diff] [blame] | 347 | call delete('Xtest_quit_message') |
Bram Moolenaar | 3d30af8 | 2020-10-13 22:15:56 +0200 | [diff] [blame] | 348 | endfunc |
| 349 | |
Bram Moolenaar | 2de5371 | 2021-12-19 11:06:35 +0000 | [diff] [blame] | 350 | " this was missing a terminating NUL |
| 351 | func Test_echo_string_partial() |
| 352 | function CountSpaces() |
| 353 | endfunction |
Yegappan Lakshmanan | bc404bf | 2021-12-19 19:19:31 +0000 | [diff] [blame] | 354 | call assert_equal("function('CountSpaces', [{'ccccccccccc': ['ab', 'cd'], 'aaaaaaaaaaa': v:false, 'bbbbbbbbbbbb': ''}])", string(function('CountSpaces', [#{aaaaaaaaaaa: v:false, bbbbbbbbbbbb: '', ccccccccccc: ['ab', 'cd']}]))) |
Bram Moolenaar | 2de5371 | 2021-12-19 11:06:35 +0000 | [diff] [blame] | 355 | endfunc |
| 356 | |
Rob Pilling | 726f7f9 | 2022-01-20 14:44:38 +0000 | [diff] [blame] | 357 | " Message output was previously overwritten by the fileinfo display, shown |
| 358 | " when switching buffers. If a buffer is switched to, then a message if |
| 359 | " echoed, we should show the message, rather than overwriting it with |
| 360 | " fileinfo. |
| 361 | func Test_fileinfo_after_echo() |
| 362 | CheckScreendump |
| 363 | |
| 364 | let content =<< trim END |
| 365 | file a.txt |
| 366 | |
| 367 | hide edit b.txt |
| 368 | call setline(1, "hi") |
| 369 | setlocal modified |
| 370 | |
| 371 | hide buffer a.txt |
| 372 | |
Bram Moolenaar | 9323ca5 | 2022-03-16 11:14:57 +0000 | [diff] [blame] | 373 | autocmd CursorHold * buf b.txt | w | echo "'b' written" |
Rob Pilling | 726f7f9 | 2022-01-20 14:44:38 +0000 | [diff] [blame] | 374 | END |
| 375 | |
| 376 | call writefile(content, 'Xtest_fileinfo_after_echo') |
| 377 | let buf = RunVimInTerminal('-S Xtest_fileinfo_after_echo', #{rows: 6}) |
Bram Moolenaar | 9323ca5 | 2022-03-16 11:14:57 +0000 | [diff] [blame] | 378 | call term_sendkeys(buf, ":set updatetime=50\<CR>") |
| 379 | call term_sendkeys(buf, "0$") |
Rob Pilling | 726f7f9 | 2022-01-20 14:44:38 +0000 | [diff] [blame] | 380 | call VerifyScreenDump(buf, 'Test_fileinfo_after_echo', {}) |
| 381 | |
| 382 | call term_sendkeys(buf, ":q\<CR>") |
| 383 | |
| 384 | " clean up |
| 385 | call StopVimInTerminal(buf) |
| 386 | call delete('Xtest_fileinfo_after_echo') |
Yegappan Lakshmanan | 7e765a3 | 2022-01-24 11:40:37 +0000 | [diff] [blame] | 387 | call delete('b.txt') |
Rob Pilling | 726f7f9 | 2022-01-20 14:44:38 +0000 | [diff] [blame] | 388 | endfunc |
| 389 | |
Bram Moolenaar | d1f8fd5 | 2022-08-27 22:51:25 +0100 | [diff] [blame] | 390 | func Test_cmdheight_zero() |
Bram Moolenaar | d4cf9fc | 2022-08-11 14:13:37 +0100 | [diff] [blame] | 391 | enew |
Shougo Matsushita | f39cfb7 | 2022-07-30 16:54:05 +0100 | [diff] [blame] | 392 | set cmdheight=0 |
| 393 | set showcmd |
| 394 | redraw! |
Bram Moolenaar | 9198de3 | 2022-08-27 21:30:03 +0100 | [diff] [blame] | 395 | let using_popupwin = has('timers') && has('popupwin') |
Shougo Matsushita | f39cfb7 | 2022-07-30 16:54:05 +0100 | [diff] [blame] | 396 | |
| 397 | echo 'test echo' |
Bram Moolenaar | 9198de3 | 2022-08-27 21:30:03 +0100 | [diff] [blame] | 398 | if using_popupwin |
| 399 | redraw |
| 400 | call assert_equal('test echo', Screenline(&lines)) |
Bram Moolenaar | b0509c5 | 2022-08-28 12:06:21 +0100 | [diff] [blame] | 401 | |
| 402 | " check that the popup is cleared when entering a command line |
| 403 | call feedkeys(':', 'xt') |
| 404 | redraw |
| 405 | call assert_equal('~', Screenline(&lines)) |
Bram Moolenaar | 9198de3 | 2022-08-27 21:30:03 +0100 | [diff] [blame] | 406 | else |
| 407 | call assert_equal(116, screenchar(&lines, 1)) |
| 408 | endif |
Shougo Matsushita | f39cfb7 | 2022-07-30 16:54:05 +0100 | [diff] [blame] | 409 | redraw! |
| 410 | |
| 411 | echomsg 'test echomsg' |
Bram Moolenaar | 9198de3 | 2022-08-27 21:30:03 +0100 | [diff] [blame] | 412 | if using_popupwin |
| 413 | redraw |
| 414 | call assert_equal('test echomsg', Screenline(&lines)) |
| 415 | else |
| 416 | call assert_equal(116, screenchar(&lines, 1)) |
| 417 | endif |
Shougo Matsushita | f39cfb7 | 2022-07-30 16:54:05 +0100 | [diff] [blame] | 418 | redraw! |
| 419 | |
Bram Moolenaar | 9198de3 | 2022-08-27 21:30:03 +0100 | [diff] [blame] | 420 | if !using_popupwin |
| 421 | call feedkeys(":ls\<CR>", "xt") |
| 422 | call assert_equal(':ls', Screenline(&lines)) |
| 423 | redraw! |
| 424 | endif |
Shougo Matsushita | f39cfb7 | 2022-07-30 16:54:05 +0100 | [diff] [blame] | 425 | |
| 426 | let char = getchar(0) |
| 427 | call assert_match(char, 0) |
| 428 | |
| 429 | " Check change/restore cmdheight when macro |
| 430 | call feedkeys("qa", "xt") |
zeertzjq | 7502094 | 2022-07-31 11:37:20 +0100 | [diff] [blame] | 431 | call assert_equal(1, &cmdheight) |
Shougo Matsushita | f39cfb7 | 2022-07-30 16:54:05 +0100 | [diff] [blame] | 432 | call feedkeys("q", "xt") |
zeertzjq | 7502094 | 2022-07-31 11:37:20 +0100 | [diff] [blame] | 433 | call assert_equal(0, &cmdheight) |
Shougo Matsushita | f39cfb7 | 2022-07-30 16:54:05 +0100 | [diff] [blame] | 434 | |
| 435 | call setline(1, 'somestring') |
| 436 | call feedkeys("y", "n") |
| 437 | %s/somestring/otherstring/gc |
zeertzjq | 7502094 | 2022-07-31 11:37:20 +0100 | [diff] [blame] | 438 | call assert_equal('otherstring', getline(1)) |
Shougo Matsushita | f39cfb7 | 2022-07-30 16:54:05 +0100 | [diff] [blame] | 439 | |
| 440 | call feedkeys("g\<C-g>", "xt") |
Bram Moolenaar | 9198de3 | 2022-08-27 21:30:03 +0100 | [diff] [blame] | 441 | if using_popupwin |
| 442 | redraw |
| 443 | endif |
Shougo Matsushita | f39cfb7 | 2022-07-30 16:54:05 +0100 | [diff] [blame] | 444 | call assert_match( |
| 445 | \ 'Col 1 of 11; Line 1 of 1; Word 1 of 1', |
| 446 | \ Screenline(&lines)) |
| 447 | |
| 448 | " Check split behavior |
| 449 | for i in range(1, 10) |
| 450 | split |
| 451 | endfor |
| 452 | only |
zeertzjq | 7502094 | 2022-07-31 11:37:20 +0100 | [diff] [blame] | 453 | call assert_equal(0, &cmdheight) |
| 454 | |
| 455 | " Check that pressing ":" should not scroll a window |
| 456 | " Check for what patch 9.0.0115 fixes |
| 457 | botright 10new |
| 458 | call setline(1, range(12)) |
| 459 | 7 |
| 460 | call feedkeys(":\"\<C-R>=line('w0')\<CR>\<CR>", "xt") |
| 461 | call assert_equal('"1', @:) |
Shougo Matsushita | f39cfb7 | 2022-07-30 16:54:05 +0100 | [diff] [blame] | 462 | |
Bram Moolenaar | d4cf9fc | 2022-08-11 14:13:37 +0100 | [diff] [blame] | 463 | bwipe! |
| 464 | bwipe! |
Shougo Matsushita | f39cfb7 | 2022-07-30 16:54:05 +0100 | [diff] [blame] | 465 | set cmdheight& |
| 466 | set showcmd& |
Bram Moolenaar | d4cf9fc | 2022-08-11 14:13:37 +0100 | [diff] [blame] | 467 | tabnew |
| 468 | tabonly |
Bram Moolenaar | d1f8fd5 | 2022-08-27 22:51:25 +0100 | [diff] [blame] | 469 | |
| 470 | "redraw to hide the popup window |
| 471 | redraw |
Shougo Matsushita | f39cfb7 | 2022-07-30 16:54:05 +0100 | [diff] [blame] | 472 | endfunc |
| 473 | |
Bram Moolenaar | 4356864 | 2022-08-28 13:02:45 +0100 | [diff] [blame] | 474 | func Test_cmdheight_zero_dump() |
| 475 | CheckScreendump |
| 476 | |
| 477 | let lines =<< trim END |
| 478 | set cmdheight=0 |
| 479 | set showmode |
| 480 | call setline(1, 'some text') |
Bram Moolenaar | 134b865 | 2022-08-28 21:36:43 +0100 | [diff] [blame] | 481 | func ShowMessages() |
| 482 | echomsg 'some text' |
| 483 | sleep 100m |
| 484 | echomsg 'some more text' |
| 485 | sleep 2500m |
| 486 | echomsg 'even more text' |
| 487 | endfunc |
Bram Moolenaar | 4356864 | 2022-08-28 13:02:45 +0100 | [diff] [blame] | 488 | END |
| 489 | call writefile(lines, 'XtestCmdheight') |
| 490 | let buf = RunVimInTerminal('-S XtestCmdheight', #{rows: 6}) |
| 491 | " The "-- INSERT --" indicator should not be visible. |
| 492 | call term_sendkeys(buf, "i") |
| 493 | call VerifyScreenDump(buf, 'Test_cmdheight_zero_1', {}) |
| 494 | |
| 495 | " The "-- VISUAL --" indicator should not be visible. |
| 496 | call term_sendkeys(buf, "\<Esc>vw") |
| 497 | call VerifyScreenDump(buf, 'Test_cmdheight_zero_2', {}) |
| 498 | |
| 499 | " Echo'd text is in a popup window |
| 500 | call term_sendkeys(buf, "\<Esc>:echo 'message window'\<CR>") |
| 501 | call VerifyScreenDump(buf, 'Test_cmdheight_zero_3', {}) |
| 502 | |
Bram Moolenaar | 35a4fbc | 2022-08-28 14:39:53 +0100 | [diff] [blame] | 503 | " Message for CTRL-C is in the popup window |
Bram Moolenaar | 35a4fbc | 2022-08-28 14:39:53 +0100 | [diff] [blame] | 504 | call term_sendkeys(buf, "\<C-C>") |
| 505 | call VerifyScreenDump(buf, 'Test_cmdheight_zero_4', {}) |
| 506 | |
Bram Moolenaar | f2fb54f | 2022-08-28 20:58:51 +0100 | [diff] [blame] | 507 | " file write message is one line |
| 508 | call term_sendkeys(buf, ":w XsomeText\<CR>") |
| 509 | call VerifyScreenDump(buf, 'Test_cmdheight_zero_5', {}) |
| 510 | |
Bram Moolenaar | 134b865 | 2022-08-28 21:36:43 +0100 | [diff] [blame] | 511 | call term_sendkeys(buf, ":call popup_clear()\<CR>") |
| 512 | call VerifyScreenDump(buf, 'Test_cmdheight_zero_6', {}) |
| 513 | |
| 514 | call term_sendkeys(buf, ":call ShowMessages()\<CR>") |
| 515 | call VerifyScreenDump(buf, 'Test_cmdheight_zero_7', {}) |
| 516 | sleep 2 |
| 517 | call VerifyScreenDump(buf, 'Test_cmdheight_zero_8', {}) |
| 518 | |
Bram Moolenaar | 4356864 | 2022-08-28 13:02:45 +0100 | [diff] [blame] | 519 | " clean up |
| 520 | call StopVimInTerminal(buf) |
| 521 | call delete('XtestCmdheight') |
Bram Moolenaar | f2fb54f | 2022-08-28 20:58:51 +0100 | [diff] [blame] | 522 | call delete('XsomeText') |
Bram Moolenaar | 4356864 | 2022-08-28 13:02:45 +0100 | [diff] [blame] | 523 | endfunc |
| 524 | |
Bram Moolenaar | 35a4fbc | 2022-08-28 14:39:53 +0100 | [diff] [blame] | 525 | func Test_cmdheight_zero_shell() |
| 526 | CheckUnix |
| 527 | |
| 528 | set cmdheight=0 |
| 529 | set nomore |
| 530 | call setline(1, 'foo!') |
| 531 | silent !echo <cWORD> > Xfile.out |
| 532 | call assert_equal(['foo!'], readfile('Xfile.out')) |
| 533 | call delete('Xfile.out') |
| 534 | redraw! |
| 535 | |
| 536 | set more& |
| 537 | set cmdheight& |
| 538 | endfunc |
| 539 | |
Bram Moolenaar | 4356864 | 2022-08-28 13:02:45 +0100 | [diff] [blame] | 540 | |
Bram Moolenaar | 92b83cc | 2020-04-25 15:24:44 +0200 | [diff] [blame] | 541 | " vim: shiftwidth=2 sts=2 expandtab |