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}')) |
Bram Moolenaar | 73e28dc | 2022-09-17 21:08:33 +0100 | [diff] [blame] | 77 | call assert_equal("\n1.23", execute(':echomsg 1.23')) |
Bram Moolenaar | 461a7fc | 2018-12-22 13:28:07 +0100 | [diff] [blame] | 78 | call assert_match("function('<lambda>\\d*')", execute(':echomsg {-> 1234}')) |
| 79 | endfunc |
| 80 | |
| 81 | func Test_echoerr() |
| 82 | call test_ignore_error('IgNoRe') |
| 83 | call assert_equal("\nIgNoRe hello", execute(':echoerr "IgNoRe hello"')) |
| 84 | call assert_equal("\n12345 IgNoRe", execute(':echoerr 12345 "IgNoRe"')) |
| 85 | call assert_equal("\n[1, 2, 'IgNoRe']", execute(':echoerr [1, 2, "IgNoRe"]')) |
| 86 | call assert_equal("\n{'IgNoRe': 2, 'a': 1}", execute(':echoerr {"a": 1, "IgNoRe": 2}')) |
Bram Moolenaar | 73e28dc | 2022-09-17 21:08:33 +0100 | [diff] [blame] | 87 | call assert_equal("\n1.23 IgNoRe", execute(':echoerr 1.23 "IgNoRe"')) |
Bram Moolenaar | ce90e36 | 2019-09-08 18:58:44 +0200 | [diff] [blame] | 88 | eval '<lambda>'->test_ignore_error() |
Bram Moolenaar | 461a7fc | 2018-12-22 13:28:07 +0100 | [diff] [blame] | 89 | call assert_match("function('<lambda>\\d*')", execute(':echoerr {-> 1234}')) |
| 90 | call test_ignore_error('RESET') |
| 91 | endfunc |
Bram Moolenaar | abc7c7f | 2019-04-20 15:10:13 +0200 | [diff] [blame] | 92 | |
| 93 | func Test_mode_message_at_leaving_insert_by_ctrl_c() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 94 | CheckFeature terminal |
| 95 | CheckNotGui |
Bram Moolenaar | abc7c7f | 2019-04-20 15:10:13 +0200 | [diff] [blame] | 96 | |
| 97 | " Set custom statusline built by user-defined function. |
| 98 | let testfile = 'Xtest.vim' |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 99 | let lines =<< trim END |
| 100 | func StatusLine() abort |
| 101 | return "" |
| 102 | endfunc |
| 103 | set statusline=%!StatusLine() |
| 104 | set laststatus=2 |
| 105 | END |
| 106 | call writefile(lines, testfile) |
Bram Moolenaar | abc7c7f | 2019-04-20 15:10:13 +0200 | [diff] [blame] | 107 | |
| 108 | let rows = 10 |
| 109 | let buf = term_start([GetVimProg(), '--clean', '-S', testfile], {'term_rows': rows}) |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 110 | call TermWait(buf, 100) |
Bram Moolenaar | abc7c7f | 2019-04-20 15:10:13 +0200 | [diff] [blame] | 111 | call assert_equal('run', job_status(term_getjob(buf))) |
| 112 | |
| 113 | call term_sendkeys(buf, "i") |
| 114 | call WaitForAssert({-> assert_match('^-- INSERT --\s*$', term_getline(buf, rows))}) |
| 115 | call term_sendkeys(buf, "\<C-C>") |
| 116 | call WaitForAssert({-> assert_match('^\s*$', term_getline(buf, rows))}) |
| 117 | |
| 118 | call term_sendkeys(buf, ":qall!\<CR>") |
| 119 | call WaitForAssert({-> assert_equal('dead', job_status(term_getjob(buf)))}) |
| 120 | exe buf . 'bwipe!' |
| 121 | call delete(testfile) |
| 122 | endfunc |
Bram Moolenaar | 4c25bd7 | 2019-04-20 23:38:07 +0200 | [diff] [blame] | 123 | |
| 124 | func Test_mode_message_at_leaving_insert_with_esc_mapped() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 125 | CheckFeature terminal |
| 126 | CheckNotGui |
Bram Moolenaar | 4c25bd7 | 2019-04-20 23:38:07 +0200 | [diff] [blame] | 127 | |
| 128 | " Set custom statusline built by user-defined function. |
| 129 | let testfile = 'Xtest.vim' |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 130 | let lines =<< trim END |
| 131 | set laststatus=2 |
| 132 | inoremap <Esc> <Esc>00 |
| 133 | END |
| 134 | call writefile(lines, testfile) |
Bram Moolenaar | 4c25bd7 | 2019-04-20 23:38:07 +0200 | [diff] [blame] | 135 | |
| 136 | let rows = 10 |
| 137 | let buf = term_start([GetVimProg(), '--clean', '-S', testfile], {'term_rows': rows}) |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 138 | 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] | 139 | call assert_equal('run', job_status(term_getjob(buf))) |
| 140 | |
| 141 | call term_sendkeys(buf, "i") |
| 142 | call WaitForAssert({-> assert_match('^-- INSERT --\s*$', term_getline(buf, rows))}) |
| 143 | call term_sendkeys(buf, "\<Esc>") |
| 144 | call WaitForAssert({-> assert_match('^\s*$', term_getline(buf, rows))}) |
| 145 | |
| 146 | call term_sendkeys(buf, ":qall!\<CR>") |
| 147 | call WaitForAssert({-> assert_equal('dead', job_status(term_getjob(buf)))}) |
| 148 | exe buf . 'bwipe!' |
| 149 | call delete(testfile) |
| 150 | endfunc |
Bram Moolenaar | 37f4cbd | 2019-08-23 20:58:45 +0200 | [diff] [blame] | 151 | |
| 152 | func Test_echospace() |
| 153 | set noruler noshowcmd laststatus=1 |
| 154 | call assert_equal(&columns - 1, v:echospace) |
| 155 | split |
| 156 | call assert_equal(&columns - 1, v:echospace) |
| 157 | set ruler |
| 158 | call assert_equal(&columns - 1, v:echospace) |
| 159 | close |
| 160 | call assert_equal(&columns - 19, v:echospace) |
| 161 | set showcmd noruler |
| 162 | call assert_equal(&columns - 12, v:echospace) |
| 163 | set showcmd ruler |
| 164 | call assert_equal(&columns - 29, v:echospace) |
| 165 | |
| 166 | set ruler& showcmd& |
| 167 | endfunc |
Bram Moolenaar | c6d539b | 2019-12-28 17:10:46 +0100 | [diff] [blame] | 168 | |
zeertzjq | bdedd2b | 2022-09-20 12:45:15 +0100 | [diff] [blame] | 169 | func Test_warning_scroll() |
| 170 | CheckRunVimInTerminal |
| 171 | let lines =<< trim END |
| 172 | call test_override('ui_delay', 50) |
| 173 | set noruler |
| 174 | set readonly |
| 175 | undo |
| 176 | END |
| 177 | call writefile(lines, 'XTestWarningScroll', 'D') |
| 178 | let buf = RunVimInTerminal('', #{rows: 8}) |
| 179 | |
| 180 | " When the warning comes from a script, messages are scrolled so that the |
| 181 | " stacktrace is visible. |
| 182 | call term_sendkeys(buf, ":source XTestWarningScroll\n") |
| 183 | " only match the final colon in the line that shows the source |
| 184 | call WaitForAssert({-> assert_match(':$', term_getline(buf, 5))}) |
| 185 | call WaitForAssert({-> assert_equal('line 4:W10: Warning: Changing a readonly file', term_getline(buf, 6))}) |
| 186 | call WaitForAssert({-> assert_equal('Already at oldest change', term_getline(buf, 7))}) |
| 187 | call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 8))}) |
| 188 | call term_sendkeys(buf, "\n") |
| 189 | |
| 190 | " When the warning does not come from a script, messages are not scrolled. |
| 191 | call term_sendkeys(buf, ":enew\n") |
| 192 | call term_sendkeys(buf, ":set readonly\n") |
| 193 | call term_sendkeys(buf, 'u') |
| 194 | call WaitForAssert({-> assert_equal('W10: Warning: Changing a readonly file', term_getline(buf, 8))}) |
| 195 | call WaitForAssert({-> assert_equal('Already at oldest change', term_getline(buf, 8))}) |
| 196 | |
| 197 | " clean up |
| 198 | call StopVimInTerminal(buf) |
| 199 | endfunc |
| 200 | |
Bram Moolenaar | c6d539b | 2019-12-28 17:10:46 +0100 | [diff] [blame] | 201 | " Test more-prompt (see :help more-prompt). |
| 202 | func Test_message_more() |
Bram Moolenaar | 494e906 | 2020-05-31 21:28:02 +0200 | [diff] [blame] | 203 | CheckRunVimInTerminal |
Bram Moolenaar | c6d539b | 2019-12-28 17:10:46 +0100 | [diff] [blame] | 204 | let buf = RunVimInTerminal('', {'rows': 6}) |
| 205 | call term_sendkeys(buf, ":call setline(1, range(1, 100))\n") |
| 206 | |
zeertzjq | 46af7bc | 2022-07-28 12:34:09 +0100 | [diff] [blame] | 207 | call term_sendkeys(buf, ":%pfoo\<C-H>\<C-H>\<C-H>#") |
| 208 | call WaitForAssert({-> assert_equal(':%p#', term_getline(buf, 6))}) |
| 209 | call term_sendkeys(buf, "\n") |
Bram Moolenaar | c6d539b | 2019-12-28 17:10:46 +0100 | [diff] [blame] | 210 | call WaitForAssert({-> assert_equal(' 5 5', term_getline(buf, 5))}) |
| 211 | call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))}) |
| 212 | |
| 213 | call term_sendkeys(buf, '?') |
| 214 | call WaitForAssert({-> assert_equal(' 5 5', term_getline(buf, 5))}) |
| 215 | call WaitForAssert({-> assert_equal('-- More -- SPACE/d/j: screen/page/line down, b/u/k: up, q: quit ', term_getline(buf, 6))}) |
| 216 | |
| 217 | " Down a line with j, <CR>, <NL> or <Down>. |
| 218 | call term_sendkeys(buf, "j") |
| 219 | call WaitForAssert({-> assert_equal(' 6 6', term_getline(buf, 5))}) |
| 220 | call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))}) |
| 221 | call term_sendkeys(buf, "\<NL>") |
| 222 | call WaitForAssert({-> assert_equal(' 7 7', term_getline(buf, 5))}) |
| 223 | call term_sendkeys(buf, "\<CR>") |
| 224 | call WaitForAssert({-> assert_equal(' 8 8', term_getline(buf, 5))}) |
| 225 | call term_sendkeys(buf, "\<Down>") |
| 226 | call WaitForAssert({-> assert_equal(' 9 9', term_getline(buf, 5))}) |
| 227 | |
| 228 | " Down a screen with <Space>, f, or <PageDown>. |
| 229 | call term_sendkeys(buf, 'f') |
| 230 | call WaitForAssert({-> assert_equal(' 14 14', term_getline(buf, 5))}) |
| 231 | call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))}) |
| 232 | call term_sendkeys(buf, ' ') |
| 233 | call WaitForAssert({-> assert_equal(' 19 19', term_getline(buf, 5))}) |
| 234 | call term_sendkeys(buf, "\<PageDown>") |
| 235 | call WaitForAssert({-> assert_equal(' 24 24', term_getline(buf, 5))}) |
| 236 | |
| 237 | " Down a page (half a screen) with d. |
| 238 | call term_sendkeys(buf, 'd') |
| 239 | call WaitForAssert({-> assert_equal(' 27 27', term_getline(buf, 5))}) |
| 240 | |
| 241 | " Down all the way with 'G'. |
| 242 | call term_sendkeys(buf, 'G') |
| 243 | call WaitForAssert({-> assert_equal('100 100', term_getline(buf, 5))}) |
| 244 | call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 6))}) |
| 245 | |
| 246 | " Up a line k, <BS> or <Up>. |
| 247 | call term_sendkeys(buf, 'k') |
| 248 | call WaitForAssert({-> assert_equal(' 99 99', term_getline(buf, 5))}) |
| 249 | call term_sendkeys(buf, "\<BS>") |
| 250 | call WaitForAssert({-> assert_equal(' 98 98', term_getline(buf, 5))}) |
| 251 | call term_sendkeys(buf, "\<Up>") |
| 252 | call WaitForAssert({-> assert_equal(' 97 97', term_getline(buf, 5))}) |
| 253 | |
| 254 | " Up a screen with b or <PageUp>. |
| 255 | call term_sendkeys(buf, 'b') |
| 256 | call WaitForAssert({-> assert_equal(' 92 92', term_getline(buf, 5))}) |
| 257 | call term_sendkeys(buf, "\<PageUp>") |
| 258 | call WaitForAssert({-> assert_equal(' 87 87', term_getline(buf, 5))}) |
| 259 | |
| 260 | " Up a page (half a screen) with u. |
| 261 | call term_sendkeys(buf, 'u') |
| 262 | call WaitForAssert({-> assert_equal(' 84 84', term_getline(buf, 5))}) |
| 263 | |
| 264 | " Up all the way with 'g'. |
| 265 | call term_sendkeys(buf, 'g') |
zeertzjq | ecdc82e | 2022-07-25 19:50:57 +0100 | [diff] [blame] | 266 | call WaitForAssert({-> assert_equal(' 4 4', term_getline(buf, 5))}) |
| 267 | call WaitForAssert({-> assert_equal(':%p#', term_getline(buf, 1))}) |
Bram Moolenaar | c6d539b | 2019-12-28 17:10:46 +0100 | [diff] [blame] | 268 | call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))}) |
| 269 | |
| 270 | " All the way down. Pressing f should do nothing but pressing |
| 271 | " space should end the more prompt. |
| 272 | call term_sendkeys(buf, 'G') |
| 273 | call WaitForAssert({-> assert_equal('100 100', term_getline(buf, 5))}) |
| 274 | call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 6))}) |
| 275 | call term_sendkeys(buf, 'f') |
| 276 | call WaitForAssert({-> assert_equal('100 100', term_getline(buf, 5))}) |
| 277 | call term_sendkeys(buf, ' ') |
| 278 | call WaitForAssert({-> assert_equal('100', term_getline(buf, 5))}) |
| 279 | |
| 280 | " Pressing g< shows the previous command output. |
| 281 | call term_sendkeys(buf, 'g<') |
| 282 | call WaitForAssert({-> assert_equal('100 100', term_getline(buf, 5))}) |
| 283 | call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 6))}) |
| 284 | |
zeertzjq | 46af7bc | 2022-07-28 12:34:09 +0100 | [diff] [blame] | 285 | " A command line that doesn't print text is appended to scrollback, |
| 286 | " even if it invokes a nested command line. |
| 287 | call term_sendkeys(buf, ":\<C-R>=':'\<CR>:\<CR>g<") |
| 288 | call WaitForAssert({-> assert_equal('100 100', term_getline(buf, 4))}) |
| 289 | call WaitForAssert({-> assert_equal(':::', term_getline(buf, 5))}) |
| 290 | call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 6))}) |
| 291 | |
Bram Moolenaar | c6d539b | 2019-12-28 17:10:46 +0100 | [diff] [blame] | 292 | call term_sendkeys(buf, ":%p#\n") |
| 293 | call WaitForAssert({-> assert_equal(' 5 5', term_getline(buf, 5))}) |
| 294 | call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))}) |
| 295 | |
| 296 | " Stop command output with q, <Esc> or CTRL-C. |
| 297 | call term_sendkeys(buf, 'q') |
| 298 | call WaitForAssert({-> assert_equal('100', term_getline(buf, 5))}) |
| 299 | |
Bram Moolenaar | f4fcedc | 2021-03-15 18:36:20 +0100 | [diff] [blame] | 300 | " Execute a : command from the more prompt |
| 301 | call term_sendkeys(buf, ":%p#\n") |
| 302 | call term_wait(buf) |
| 303 | call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))}) |
| 304 | call term_sendkeys(buf, ":") |
| 305 | call term_wait(buf) |
| 306 | call WaitForAssert({-> assert_equal(':', term_getline(buf, 6))}) |
| 307 | call term_sendkeys(buf, "echo 'Hello'\n") |
| 308 | call term_wait(buf) |
| 309 | call WaitForAssert({-> assert_equal('Hello ', term_getline(buf, 5))}) |
| 310 | |
Bram Moolenaar | 43c60ed | 2020-02-02 15:55:19 +0100 | [diff] [blame] | 311 | call StopVimInTerminal(buf) |
| 312 | endfunc |
| 313 | |
Bram Moolenaar | 838b746 | 2022-09-26 15:19:56 +0100 | [diff] [blame] | 314 | " Test more-prompt scrollback |
| 315 | func Test_message_more_scrollback() |
| 316 | CheckRunVimInTerminal |
| 317 | |
| 318 | let lines =<< trim END |
| 319 | set t_ut= |
| 320 | hi Normal ctermfg=15 ctermbg=0 |
| 321 | for i in range(100) |
| 322 | echo i |
| 323 | endfor |
| 324 | END |
| 325 | call writefile(lines, 'XmoreScrollback', 'D') |
| 326 | let buf = RunVimInTerminal('-S XmoreScrollback', {'rows': 10}) |
| 327 | call VerifyScreenDump(buf, 'Test_more_scrollback_1', {}) |
| 328 | |
| 329 | call term_sendkeys(buf, 'f') |
| 330 | call TermWait(buf) |
| 331 | call term_sendkeys(buf, 'b') |
| 332 | call VerifyScreenDump(buf, 'Test_more_scrollback_2', {}) |
| 333 | |
| 334 | call term_sendkeys(buf, 'q') |
| 335 | call TermWait(buf) |
| 336 | call StopVimInTerminal(buf) |
| 337 | endfunc |
| 338 | |
Bram Moolenaar | 1190139 | 2022-09-26 19:50:44 +0100 | [diff] [blame] | 339 | " Test verbose message before echo command |
| 340 | func Test_echo_verbose_system() |
| 341 | CheckRunVimInTerminal |
Bram Moolenaar | f802767 | 2022-09-27 15:55:43 +0100 | [diff] [blame] | 342 | CheckUnix " needs the "seq" command |
| 343 | CheckNotMac " doesn't use /tmp |
Bram Moolenaar | 1190139 | 2022-09-26 19:50:44 +0100 | [diff] [blame] | 344 | |
| 345 | let buf = RunVimInTerminal('', {'rows': 10}) |
| 346 | call term_sendkeys(buf, ":4 verbose echo system('seq 20')\<CR>") |
| 347 | " Note that the screendump is filtered to remove the name of the temp file |
| 348 | call VerifyScreenDump(buf, 'Test_verbose_system_1', {}) |
| 349 | |
| 350 | " display a page and go back, results in exactly the same view |
| 351 | call term_sendkeys(buf, ' ') |
| 352 | call TermWait(buf) |
| 353 | call term_sendkeys(buf, 'b') |
| 354 | call VerifyScreenDump(buf, 'Test_verbose_system_1', {}) |
| 355 | |
| 356 | " do the same with 'cmdheight' set to 2 |
| 357 | call term_sendkeys(buf, 'q') |
| 358 | call TermWait(buf) |
| 359 | call term_sendkeys(buf, ":set ch=2\<CR>") |
| 360 | call TermWait(buf) |
| 361 | call term_sendkeys(buf, ":4 verbose echo system('seq 20')\<CR>") |
| 362 | call VerifyScreenDump(buf, 'Test_verbose_system_2', {}) |
| 363 | |
| 364 | call term_sendkeys(buf, ' ') |
| 365 | call TermWait(buf) |
| 366 | call term_sendkeys(buf, 'b') |
| 367 | call VerifyScreenDump(buf, 'Test_verbose_system_2', {}) |
| 368 | |
| 369 | call term_sendkeys(buf, 'q') |
| 370 | call TermWait(buf) |
| 371 | call StopVimInTerminal(buf) |
| 372 | endfunc |
| 373 | |
Bram Moolenaar | 838b746 | 2022-09-26 15:19:56 +0100 | [diff] [blame] | 374 | |
Bram Moolenaar | 43c60ed | 2020-02-02 15:55:19 +0100 | [diff] [blame] | 375 | func Test_ask_yesno() |
Bram Moolenaar | 494e906 | 2020-05-31 21:28:02 +0200 | [diff] [blame] | 376 | CheckRunVimInTerminal |
Bram Moolenaar | 43c60ed | 2020-02-02 15:55:19 +0100 | [diff] [blame] | 377 | let buf = RunVimInTerminal('', {'rows': 6}) |
| 378 | call term_sendkeys(buf, ":call setline(1, range(1, 2))\n") |
| 379 | |
| 380 | call term_sendkeys(buf, ":2,1s/^/n/\n") |
| 381 | call WaitForAssert({-> assert_equal('Backwards range given, OK to swap (y/n)?', term_getline(buf, 6))}) |
| 382 | call term_sendkeys(buf, "n") |
| 383 | call WaitForAssert({-> assert_match('^Backwards range given, OK to swap (y/n)?n *1,1 *All$', term_getline(buf, 6))}) |
| 384 | call WaitForAssert({-> assert_equal('1', term_getline(buf, 1))}) |
| 385 | |
| 386 | call term_sendkeys(buf, ":2,1s/^/Esc/\n") |
| 387 | call WaitForAssert({-> assert_equal('Backwards range given, OK to swap (y/n)?', term_getline(buf, 6))}) |
| 388 | call term_sendkeys(buf, "\<Esc>") |
| 389 | call WaitForAssert({-> assert_match('^Backwards range given, OK to swap (y/n)?n *1,1 *All$', term_getline(buf, 6))}) |
| 390 | call WaitForAssert({-> assert_equal('1', term_getline(buf, 1))}) |
| 391 | |
| 392 | call term_sendkeys(buf, ":2,1s/^/y/\n") |
| 393 | call WaitForAssert({-> assert_equal('Backwards range given, OK to swap (y/n)?', term_getline(buf, 6))}) |
| 394 | call term_sendkeys(buf, "y") |
| 395 | call WaitForAssert({-> assert_match('^Backwards range given, OK to swap (y/n)?y *2,1 *All$', term_getline(buf, 6))}) |
| 396 | call WaitForAssert({-> assert_equal('y1', term_getline(buf, 1))}) |
| 397 | call WaitForAssert({-> assert_equal('y2', term_getline(buf, 2))}) |
| 398 | |
Bram Moolenaar | c6d539b | 2019-12-28 17:10:46 +0100 | [diff] [blame] | 399 | call StopVimInTerminal(buf) |
| 400 | endfunc |
Bram Moolenaar | 9db2afe | 2020-01-08 18:56:20 +0100 | [diff] [blame] | 401 | |
| 402 | func Test_null() |
| 403 | echom test_null_list() |
| 404 | echom test_null_dict() |
| 405 | echom test_null_blob() |
Bram Moolenaar | 9db2afe | 2020-01-08 18:56:20 +0100 | [diff] [blame] | 406 | echom test_null_string() |
Bram Moolenaar | 92b83cc | 2020-04-25 15:24:44 +0200 | [diff] [blame] | 407 | echom test_null_function() |
Bram Moolenaar | 9db2afe | 2020-01-08 18:56:20 +0100 | [diff] [blame] | 408 | echom test_null_partial() |
Bram Moolenaar | da292b0 | 2020-01-08 19:27:40 +0100 | [diff] [blame] | 409 | if has('job') |
| 410 | echom test_null_job() |
| 411 | echom test_null_channel() |
| 412 | endif |
Bram Moolenaar | 9db2afe | 2020-01-08 18:56:20 +0100 | [diff] [blame] | 413 | endfunc |
Bram Moolenaar | 92b83cc | 2020-04-25 15:24:44 +0200 | [diff] [blame] | 414 | |
Bram Moolenaar | b42c0d5 | 2020-05-29 22:41:41 +0200 | [diff] [blame] | 415 | func Test_mapping_at_hit_return_prompt() |
| 416 | nnoremap <C-B> :echo "hit ctrl-b"<CR> |
| 417 | call feedkeys(":ls\<CR>", "xt") |
Bram Moolenaar | fccd93f | 2020-05-31 22:06:51 +0200 | [diff] [blame] | 418 | call feedkeys("\<*C-B>", "xt") |
Bram Moolenaar | b42c0d5 | 2020-05-29 22:41:41 +0200 | [diff] [blame] | 419 | call assert_match('hit ctrl-b', Screenline(&lines - 1)) |
| 420 | nunmap <C-B> |
| 421 | endfunc |
| 422 | |
Bram Moolenaar | 3d30af8 | 2020-10-13 22:15:56 +0200 | [diff] [blame] | 423 | func Test_quit_long_message() |
| 424 | CheckScreendump |
| 425 | |
| 426 | let content =<< trim END |
| 427 | echom range(9999)->join("\x01") |
| 428 | END |
Bram Moolenaar | 124af71 | 2022-09-25 18:44:03 +0100 | [diff] [blame] | 429 | call writefile(content, 'Xtest_quit_message', 'D') |
| 430 | let buf = RunVimInTerminal('-S Xtest_quit_message', #{rows: 10, wait_for_ruler: 0}) |
| 431 | call WaitForAssert({-> assert_match('^-- More --', term_getline(buf, 10))}) |
Bram Moolenaar | 3d30af8 | 2020-10-13 22:15:56 +0200 | [diff] [blame] | 432 | call term_sendkeys(buf, "q") |
| 433 | call VerifyScreenDump(buf, 'Test_quit_long_message', {}) |
| 434 | |
| 435 | " clean up |
| 436 | call StopVimInTerminal(buf) |
Bram Moolenaar | 3d30af8 | 2020-10-13 22:15:56 +0200 | [diff] [blame] | 437 | endfunc |
| 438 | |
Bram Moolenaar | 2de5371 | 2021-12-19 11:06:35 +0000 | [diff] [blame] | 439 | " this was missing a terminating NUL |
| 440 | func Test_echo_string_partial() |
| 441 | function CountSpaces() |
| 442 | endfunction |
Yegappan Lakshmanan | bc404bf | 2021-12-19 19:19:31 +0000 | [diff] [blame] | 443 | 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] | 444 | endfunc |
| 445 | |
Rob Pilling | 726f7f9 | 2022-01-20 14:44:38 +0000 | [diff] [blame] | 446 | " Message output was previously overwritten by the fileinfo display, shown |
| 447 | " when switching buffers. If a buffer is switched to, then a message if |
| 448 | " echoed, we should show the message, rather than overwriting it with |
| 449 | " fileinfo. |
| 450 | func Test_fileinfo_after_echo() |
| 451 | CheckScreendump |
| 452 | |
| 453 | let content =<< trim END |
| 454 | file a.txt |
| 455 | |
| 456 | hide edit b.txt |
| 457 | call setline(1, "hi") |
| 458 | setlocal modified |
| 459 | |
| 460 | hide buffer a.txt |
| 461 | |
Bram Moolenaar | 9323ca5 | 2022-03-16 11:14:57 +0000 | [diff] [blame] | 462 | autocmd CursorHold * buf b.txt | w | echo "'b' written" |
Rob Pilling | 726f7f9 | 2022-01-20 14:44:38 +0000 | [diff] [blame] | 463 | END |
| 464 | |
| 465 | call writefile(content, 'Xtest_fileinfo_after_echo') |
| 466 | let buf = RunVimInTerminal('-S Xtest_fileinfo_after_echo', #{rows: 6}) |
Bram Moolenaar | 9323ca5 | 2022-03-16 11:14:57 +0000 | [diff] [blame] | 467 | call term_sendkeys(buf, ":set updatetime=50\<CR>") |
| 468 | call term_sendkeys(buf, "0$") |
Rob Pilling | 726f7f9 | 2022-01-20 14:44:38 +0000 | [diff] [blame] | 469 | call VerifyScreenDump(buf, 'Test_fileinfo_after_echo', {}) |
| 470 | |
| 471 | call term_sendkeys(buf, ":q\<CR>") |
| 472 | |
| 473 | " clean up |
| 474 | call StopVimInTerminal(buf) |
| 475 | call delete('Xtest_fileinfo_after_echo') |
Yegappan Lakshmanan | 7e765a3 | 2022-01-24 11:40:37 +0000 | [diff] [blame] | 476 | call delete('b.txt') |
Rob Pilling | 726f7f9 | 2022-01-20 14:44:38 +0000 | [diff] [blame] | 477 | endfunc |
| 478 | |
Bram Moolenaar | 37fef16 | 2022-08-29 18:16:32 +0100 | [diff] [blame] | 479 | func Test_echowindow() |
| 480 | CheckScreendump |
| 481 | |
| 482 | let lines =<< trim END |
| 483 | call setline(1, 'some text') |
| 484 | func ShowMessage(arg) |
| 485 | echowindow a:arg |
| 486 | endfunc |
| 487 | echowindow 'first line' |
Bram Moolenaar | b5b4f61 | 2022-09-01 16:43:17 +0100 | [diff] [blame] | 488 | func ManyMessages() |
| 489 | for n in range(20) |
| 490 | echowindow 'line' n |
| 491 | endfor |
| 492 | endfunc |
Bram Moolenaar | cf0995d | 2022-09-11 21:36:17 +0100 | [diff] [blame] | 493 | |
| 494 | def TwoMessages() |
| 495 | popup_clear() |
| 496 | set cmdheight=2 |
| 497 | redraw |
| 498 | timer_start(100, (_) => { |
| 499 | echowin 'message' |
| 500 | }) |
| 501 | echo 'one' |
| 502 | echo 'two' |
| 503 | enddef |
| 504 | |
| 505 | def ThreeMessages() |
| 506 | popup_clear() |
| 507 | redraw |
| 508 | timer_start(100, (_) => { |
| 509 | echowin 'later message' |
| 510 | }) |
| 511 | echo 'one' |
| 512 | echo 'two' |
| 513 | echo 'three' |
| 514 | enddef |
Bram Moolenaar | 37fef16 | 2022-08-29 18:16:32 +0100 | [diff] [blame] | 515 | END |
| 516 | call writefile(lines, 'XtestEchowindow') |
| 517 | let buf = RunVimInTerminal('-S XtestEchowindow', #{rows: 8}) |
| 518 | call VerifyScreenDump(buf, 'Test_echowindow_1', {}) |
| 519 | |
| 520 | call term_sendkeys(buf, ":call ShowMessage('second line')\<CR>") |
| 521 | call VerifyScreenDump(buf, 'Test_echowindow_2', {}) |
| 522 | |
| 523 | call term_sendkeys(buf, ":call popup_clear()\<CR>") |
| 524 | call VerifyScreenDump(buf, 'Test_echowindow_3', {}) |
| 525 | |
Bram Moolenaar | b5b4f61 | 2022-09-01 16:43:17 +0100 | [diff] [blame] | 526 | call term_sendkeys(buf, ":call ManyMessages()\<CR>") |
| 527 | call VerifyScreenDump(buf, 'Test_echowindow_4', {}) |
| 528 | |
Bram Moolenaar | cf0995d | 2022-09-11 21:36:17 +0100 | [diff] [blame] | 529 | call term_sendkeys(buf, ":call TwoMessages()\<CR>") |
| 530 | call VerifyScreenDump(buf, 'Test_echowindow_5', {}) |
| 531 | |
| 532 | call term_sendkeys(buf, ":call ThreeMessages()\<CR>") |
| 533 | sleep 120m |
| 534 | call VerifyScreenDump(buf, 'Test_echowindow_6', {}) |
| 535 | |
| 536 | call term_sendkeys(buf, "\<CR>") |
| 537 | call VerifyScreenDump(buf, 'Test_echowindow_7', {}) |
| 538 | |
Bram Moolenaar | 4569020 | 2022-09-26 12:57:11 +0100 | [diff] [blame] | 539 | call term_sendkeys(buf, ":tabnew\<CR>") |
| 540 | call term_sendkeys(buf, ":echowin 'more'\<CR>") |
| 541 | call VerifyScreenDump(buf, 'Test_echowindow_8', {}) |
| 542 | |
Bram Moolenaar | 37fef16 | 2022-08-29 18:16:32 +0100 | [diff] [blame] | 543 | " clean up |
| 544 | call StopVimInTerminal(buf) |
| 545 | call delete('XtestEchowindow') |
| 546 | endfunc |
| 547 | |
Yasuhiro Matsumoto | a02a8a4 | 2022-09-02 12:16:21 +0100 | [diff] [blame] | 548 | " messages window should not be used while evaluating the :echowin argument |
| 549 | func Test_echowin_eval() |
| 550 | CheckScreendump |
| 551 | |
| 552 | let lines =<< trim END |
| 553 | func ShowMessage() |
| 554 | echo 123 |
| 555 | return 'test' |
| 556 | endfunc |
| 557 | echowindow ShowMessage() |
| 558 | END |
| 559 | call writefile(lines, 'XtestEchowindow') |
| 560 | let buf = RunVimInTerminal('-S XtestEchowindow', #{rows: 8}) |
| 561 | call VerifyScreenDump(buf, 'Test_echowin_eval', {}) |
| 562 | |
| 563 | " clean up |
| 564 | call StopVimInTerminal(buf) |
| 565 | call delete('XtestEchowindow') |
| 566 | endfunc |
| 567 | |
Bram Moolenaar | 7cf5839 | 2022-09-09 20:19:40 +0100 | [diff] [blame] | 568 | " messages window should not be used for showing the mode |
| 569 | func Test_echowin_showmode() |
| 570 | CheckScreendump |
| 571 | |
| 572 | let lines =<< trim END |
| 573 | vim9script |
| 574 | setline(1, ['one', 'two']) |
| 575 | timer_start(100, (_) => { |
| 576 | echowin 'echo window' |
| 577 | }) |
| 578 | normal V |
| 579 | END |
| 580 | call writefile(lines, 'XtestEchowinMode', 'D') |
| 581 | let buf = RunVimInTerminal('-S XtestEchowinMode', #{rows: 8}) |
| 582 | call VerifyScreenDump(buf, 'Test_echowin_showmode', {}) |
| 583 | |
| 584 | " clean up |
| 585 | call StopVimInTerminal(buf) |
| 586 | endfunc |
| 587 | |
Bram Moolenaar | 4356864 | 2022-08-28 13:02:45 +0100 | [diff] [blame] | 588 | |
Bram Moolenaar | 92b83cc | 2020-04-25 15:24:44 +0200 | [diff] [blame] | 589 | " vim: shiftwidth=2 sts=2 expandtab |