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 | |
Christian Brabandt | eb380b9 | 2025-07-07 20:53:55 +0200 | [diff] [blame] | 3 | source util/screendump.vim |
Bram Moolenaar | abc7c7f | 2019-04-20 15:10:13 +0200 | [diff] [blame] | 4 | |
Bram Moolenaar | 49b2fb3 | 2020-04-25 17:13:56 +0200 | [diff] [blame] | 5 | func Test_messages() |
Bram Moolenaar | 451f849 | 2016-04-14 17:16:22 +0200 | [diff] [blame] | 6 | let oldmore = &more |
| 7 | try |
| 8 | set nomore |
| 9 | |
| 10 | let arr = map(range(10), '"hello" . v:val') |
| 11 | for s in arr |
| 12 | echomsg s | redraw |
| 13 | endfor |
Bram Moolenaar | 451f849 | 2016-04-14 17:16:22 +0200 | [diff] [blame] | 14 | |
Bram Moolenaar | bea1ede | 2016-04-14 19:44:36 +0200 | [diff] [blame] | 15 | " get last two messages |
Bram Moolenaar | 451f849 | 2016-04-14 17:16:22 +0200 | [diff] [blame] | 16 | redir => result |
| 17 | 2messages | redraw |
| 18 | redir END |
Bram Moolenaar | bea1ede | 2016-04-14 19:44:36 +0200 | [diff] [blame] | 19 | let msg_list = split(result, "\n") |
| 20 | call assert_equal(["hello8", "hello9"], msg_list) |
Bram Moolenaar | 451f849 | 2016-04-14 17:16:22 +0200 | [diff] [blame] | 21 | |
| 22 | " clear messages without last one |
| 23 | 1messages clear |
Bram Moolenaar | 49b2fb3 | 2020-04-25 17:13:56 +0200 | [diff] [blame] | 24 | let msg_list = GetMessages() |
Bram Moolenaar | bea1ede | 2016-04-14 19:44:36 +0200 | [diff] [blame] | 25 | call assert_equal(['hello9'], msg_list) |
Bram Moolenaar | 451f849 | 2016-04-14 17:16:22 +0200 | [diff] [blame] | 26 | |
| 27 | " clear all messages |
| 28 | messages clear |
Bram Moolenaar | 49b2fb3 | 2020-04-25 17:13:56 +0200 | [diff] [blame] | 29 | let msg_list = GetMessages() |
| 30 | call assert_equal([], msg_list) |
Bram Moolenaar | 451f849 | 2016-04-14 17:16:22 +0200 | [diff] [blame] | 31 | finally |
| 32 | let &more = oldmore |
| 33 | endtry |
Bram Moolenaar | 067297e | 2020-04-13 19:55:50 +0200 | [diff] [blame] | 34 | |
| 35 | call assert_fails('message 1', 'E474:') |
Bram Moolenaar | 49b2fb3 | 2020-04-25 17:13:56 +0200 | [diff] [blame] | 36 | endfunc |
Bram Moolenaar | 2abad54 | 2018-05-19 14:43:45 +0200 | [diff] [blame] | 37 | |
Bram Moolenaar | f52f9ea | 2018-06-27 20:49:44 +0200 | [diff] [blame] | 38 | " Patch 7.4.1696 defined the "clearmode()" function for clearing the mode |
Bram Moolenaar | 2abad54 | 2018-05-19 14:43:45 +0200 | [diff] [blame] | 39 | " indicator (e.g., "-- INSERT --") when ":stopinsert" is invoked. Message |
| 40 | " output could then be disturbed when 'cmdheight' was greater than one. |
| 41 | " This test ensures that the bugfix for this issue remains in place. |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 42 | func Test_stopinsert_does_not_break_message_output() |
Bram Moolenaar | 2abad54 | 2018-05-19 14:43:45 +0200 | [diff] [blame] | 43 | set cmdheight=2 |
| 44 | redraw! |
| 45 | |
| 46 | stopinsert | echo 'test echo' |
| 47 | call assert_equal(116, screenchar(&lines - 1, 1)) |
| 48 | call assert_equal(32, screenchar(&lines, 1)) |
| 49 | redraw! |
| 50 | |
| 51 | stopinsert | echomsg 'test echomsg' |
| 52 | call assert_equal(116, screenchar(&lines - 1, 1)) |
| 53 | call assert_equal(32, screenchar(&lines, 1)) |
| 54 | redraw! |
| 55 | |
| 56 | set cmdheight& |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 57 | endfunc |
Bram Moolenaar | b513d30 | 2018-12-02 14:55:08 +0100 | [diff] [blame] | 58 | |
| 59 | func Test_message_completion() |
| 60 | call feedkeys(":message \<C-A>\<C-B>\"\<CR>", 'tx') |
| 61 | call assert_equal('"message clear', @:) |
| 62 | endfunc |
Bram Moolenaar | 461a7fc | 2018-12-22 13:28:07 +0100 | [diff] [blame] | 63 | |
| 64 | func Test_echomsg() |
| 65 | call assert_equal("\nhello", execute(':echomsg "hello"')) |
| 66 | call assert_equal("\n", execute(':echomsg ""')) |
| 67 | call assert_equal("\n12345", execute(':echomsg 12345')) |
| 68 | call assert_equal("\n[]", execute(':echomsg []')) |
| 69 | call assert_equal("\n[1, 2, 3]", execute(':echomsg [1, 2, 3]')) |
Bram Moolenaar | db950e4 | 2020-04-22 19:13:19 +0200 | [diff] [blame] | 70 | 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] | 71 | call assert_equal("\n{}", execute(':echomsg {}')) |
| 72 | 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] | 73 | call assert_equal("\n1.23", execute(':echomsg 1.23')) |
Bram Moolenaar | 461a7fc | 2018-12-22 13:28:07 +0100 | [diff] [blame] | 74 | call assert_match("function('<lambda>\\d*')", execute(':echomsg {-> 1234}')) |
| 75 | endfunc |
| 76 | |
| 77 | func Test_echoerr() |
| 78 | call test_ignore_error('IgNoRe') |
| 79 | call assert_equal("\nIgNoRe hello", execute(':echoerr "IgNoRe hello"')) |
| 80 | call assert_equal("\n12345 IgNoRe", execute(':echoerr 12345 "IgNoRe"')) |
| 81 | call assert_equal("\n[1, 2, 'IgNoRe']", execute(':echoerr [1, 2, "IgNoRe"]')) |
| 82 | 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] | 83 | call assert_equal("\n1.23 IgNoRe", execute(':echoerr 1.23 "IgNoRe"')) |
Bram Moolenaar | ce90e36 | 2019-09-08 18:58:44 +0200 | [diff] [blame] | 84 | eval '<lambda>'->test_ignore_error() |
Bram Moolenaar | 461a7fc | 2018-12-22 13:28:07 +0100 | [diff] [blame] | 85 | call assert_match("function('<lambda>\\d*')", execute(':echoerr {-> 1234}')) |
| 86 | call test_ignore_error('RESET') |
| 87 | endfunc |
Bram Moolenaar | abc7c7f | 2019-04-20 15:10:13 +0200 | [diff] [blame] | 88 | |
| 89 | func Test_mode_message_at_leaving_insert_by_ctrl_c() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 90 | CheckFeature terminal |
| 91 | CheckNotGui |
Bram Moolenaar | abc7c7f | 2019-04-20 15:10:13 +0200 | [diff] [blame] | 92 | |
| 93 | " Set custom statusline built by user-defined function. |
| 94 | let testfile = 'Xtest.vim' |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 95 | let lines =<< trim END |
| 96 | func StatusLine() abort |
| 97 | return "" |
| 98 | endfunc |
| 99 | set statusline=%!StatusLine() |
| 100 | set laststatus=2 |
| 101 | END |
Bram Moolenaar | b152b6a | 2022-09-29 21:37:33 +0100 | [diff] [blame] | 102 | call writefile(lines, testfile, 'D') |
Bram Moolenaar | abc7c7f | 2019-04-20 15:10:13 +0200 | [diff] [blame] | 103 | |
| 104 | let rows = 10 |
| 105 | let buf = term_start([GetVimProg(), '--clean', '-S', testfile], {'term_rows': rows}) |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 106 | call TermWait(buf, 100) |
Bram Moolenaar | abc7c7f | 2019-04-20 15:10:13 +0200 | [diff] [blame] | 107 | call assert_equal('run', job_status(term_getjob(buf))) |
| 108 | |
| 109 | call term_sendkeys(buf, "i") |
| 110 | call WaitForAssert({-> assert_match('^-- INSERT --\s*$', term_getline(buf, rows))}) |
| 111 | call term_sendkeys(buf, "\<C-C>") |
| 112 | call WaitForAssert({-> assert_match('^\s*$', term_getline(buf, rows))}) |
| 113 | |
| 114 | call term_sendkeys(buf, ":qall!\<CR>") |
| 115 | call WaitForAssert({-> assert_equal('dead', job_status(term_getjob(buf)))}) |
Bram Moolenaar | b152b6a | 2022-09-29 21:37:33 +0100 | [diff] [blame] | 116 | |
Bram Moolenaar | abc7c7f | 2019-04-20 15:10:13 +0200 | [diff] [blame] | 117 | exe buf . 'bwipe!' |
Bram Moolenaar | abc7c7f | 2019-04-20 15:10:13 +0200 | [diff] [blame] | 118 | endfunc |
Bram Moolenaar | 4c25bd7 | 2019-04-20 23:38:07 +0200 | [diff] [blame] | 119 | |
| 120 | func Test_mode_message_at_leaving_insert_with_esc_mapped() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 121 | CheckFeature terminal |
| 122 | CheckNotGui |
Bram Moolenaar | 4c25bd7 | 2019-04-20 23:38:07 +0200 | [diff] [blame] | 123 | |
| 124 | " Set custom statusline built by user-defined function. |
| 125 | let testfile = 'Xtest.vim' |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 126 | let lines =<< trim END |
| 127 | set laststatus=2 |
| 128 | inoremap <Esc> <Esc>00 |
| 129 | END |
Bram Moolenaar | b152b6a | 2022-09-29 21:37:33 +0100 | [diff] [blame] | 130 | call writefile(lines, testfile, 'D') |
Bram Moolenaar | 4c25bd7 | 2019-04-20 23:38:07 +0200 | [diff] [blame] | 131 | |
| 132 | let rows = 10 |
| 133 | let buf = term_start([GetVimProg(), '--clean', '-S', testfile], {'term_rows': rows}) |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 134 | 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] | 135 | call assert_equal('run', job_status(term_getjob(buf))) |
| 136 | |
| 137 | call term_sendkeys(buf, "i") |
| 138 | call WaitForAssert({-> assert_match('^-- INSERT --\s*$', term_getline(buf, rows))}) |
| 139 | call term_sendkeys(buf, "\<Esc>") |
| 140 | call WaitForAssert({-> assert_match('^\s*$', term_getline(buf, rows))}) |
| 141 | |
| 142 | call term_sendkeys(buf, ":qall!\<CR>") |
| 143 | call WaitForAssert({-> assert_equal('dead', job_status(term_getjob(buf)))}) |
Bram Moolenaar | b152b6a | 2022-09-29 21:37:33 +0100 | [diff] [blame] | 144 | |
Bram Moolenaar | 4c25bd7 | 2019-04-20 23:38:07 +0200 | [diff] [blame] | 145 | exe buf . 'bwipe!' |
Bram Moolenaar | 4c25bd7 | 2019-04-20 23:38:07 +0200 | [diff] [blame] | 146 | endfunc |
Bram Moolenaar | 37f4cbd | 2019-08-23 20:58:45 +0200 | [diff] [blame] | 147 | |
| 148 | func Test_echospace() |
| 149 | set noruler noshowcmd laststatus=1 |
| 150 | call assert_equal(&columns - 1, v:echospace) |
| 151 | split |
| 152 | call assert_equal(&columns - 1, v:echospace) |
| 153 | set ruler |
| 154 | call assert_equal(&columns - 1, v:echospace) |
| 155 | close |
| 156 | call assert_equal(&columns - 19, v:echospace) |
| 157 | set showcmd noruler |
| 158 | call assert_equal(&columns - 12, v:echospace) |
| 159 | set showcmd ruler |
| 160 | call assert_equal(&columns - 29, v:echospace) |
Sam-programs | 062141b | 2024-02-29 17:40:29 +0100 | [diff] [blame] | 161 | set showcmdloc=statusline |
| 162 | call assert_equal(&columns - 19, v:echospace) |
| 163 | set showcmdloc=tabline |
| 164 | call assert_equal(&columns - 19, v:echospace) |
zeertzjq | c27fcf4 | 2024-03-01 23:01:43 +0100 | [diff] [blame] | 165 | call assert_fails('set showcmdloc=leap', 'E474:') |
| 166 | call assert_equal(&columns - 19, v:echospace) |
| 167 | set showcmdloc=last |
| 168 | call assert_equal(&columns - 29, v:echospace) |
| 169 | call assert_fails('set showcmdloc=jump', 'E474:') |
| 170 | call assert_equal(&columns - 29, v:echospace) |
Bram Moolenaar | 37f4cbd | 2019-08-23 20:58:45 +0200 | [diff] [blame] | 171 | |
Sam-programs | 062141b | 2024-02-29 17:40:29 +0100 | [diff] [blame] | 172 | set ruler& showcmd& showcmdloc& |
Bram Moolenaar | 37f4cbd | 2019-08-23 20:58:45 +0200 | [diff] [blame] | 173 | endfunc |
Bram Moolenaar | c6d539b | 2019-12-28 17:10:46 +0100 | [diff] [blame] | 174 | |
zeertzjq | bdedd2b | 2022-09-20 12:45:15 +0100 | [diff] [blame] | 175 | func Test_warning_scroll() |
| 176 | CheckRunVimInTerminal |
| 177 | let lines =<< trim END |
| 178 | call test_override('ui_delay', 50) |
| 179 | set noruler |
| 180 | set readonly |
| 181 | undo |
| 182 | END |
| 183 | call writefile(lines, 'XTestWarningScroll', 'D') |
| 184 | let buf = RunVimInTerminal('', #{rows: 8}) |
| 185 | |
| 186 | " When the warning comes from a script, messages are scrolled so that the |
| 187 | " stacktrace is visible. |
| 188 | call term_sendkeys(buf, ":source XTestWarningScroll\n") |
| 189 | " only match the final colon in the line that shows the source |
| 190 | call WaitForAssert({-> assert_match(':$', term_getline(buf, 5))}) |
| 191 | call WaitForAssert({-> assert_equal('line 4:W10: Warning: Changing a readonly file', term_getline(buf, 6))}) |
| 192 | call WaitForAssert({-> assert_equal('Already at oldest change', term_getline(buf, 7))}) |
| 193 | call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 8))}) |
| 194 | call term_sendkeys(buf, "\n") |
| 195 | |
| 196 | " When the warning does not come from a script, messages are not scrolled. |
| 197 | call term_sendkeys(buf, ":enew\n") |
| 198 | call term_sendkeys(buf, ":set readonly\n") |
| 199 | call term_sendkeys(buf, 'u') |
| 200 | call WaitForAssert({-> assert_equal('W10: Warning: Changing a readonly file', term_getline(buf, 8))}) |
| 201 | call WaitForAssert({-> assert_equal('Already at oldest change', term_getline(buf, 8))}) |
| 202 | |
| 203 | " clean up |
| 204 | call StopVimInTerminal(buf) |
| 205 | endfunc |
| 206 | |
Bram Moolenaar | c6d539b | 2019-12-28 17:10:46 +0100 | [diff] [blame] | 207 | " Test more-prompt (see :help more-prompt). |
| 208 | func Test_message_more() |
Bram Moolenaar | 494e906 | 2020-05-31 21:28:02 +0200 | [diff] [blame] | 209 | CheckRunVimInTerminal |
Christian Brabandt | 51d4d84 | 2024-12-06 17:26:25 +0100 | [diff] [blame] | 210 | |
Bram Moolenaar | c6d539b | 2019-12-28 17:10:46 +0100 | [diff] [blame] | 211 | let buf = RunVimInTerminal('', {'rows': 6}) |
| 212 | call term_sendkeys(buf, ":call setline(1, range(1, 100))\n") |
| 213 | |
zeertzjq | 46af7bc | 2022-07-28 12:34:09 +0100 | [diff] [blame] | 214 | call term_sendkeys(buf, ":%pfoo\<C-H>\<C-H>\<C-H>#") |
| 215 | call WaitForAssert({-> assert_equal(':%p#', term_getline(buf, 6))}) |
| 216 | call term_sendkeys(buf, "\n") |
Bram Moolenaar | c6d539b | 2019-12-28 17:10:46 +0100 | [diff] [blame] | 217 | call WaitForAssert({-> assert_equal(' 5 5', term_getline(buf, 5))}) |
| 218 | call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))}) |
| 219 | |
| 220 | call term_sendkeys(buf, '?') |
| 221 | call WaitForAssert({-> assert_equal(' 5 5', term_getline(buf, 5))}) |
| 222 | call WaitForAssert({-> assert_equal('-- More -- SPACE/d/j: screen/page/line down, b/u/k: up, q: quit ', term_getline(buf, 6))}) |
| 223 | |
| 224 | " Down a line with j, <CR>, <NL> or <Down>. |
| 225 | call term_sendkeys(buf, "j") |
| 226 | call WaitForAssert({-> assert_equal(' 6 6', term_getline(buf, 5))}) |
| 227 | call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))}) |
| 228 | call term_sendkeys(buf, "\<NL>") |
| 229 | call WaitForAssert({-> assert_equal(' 7 7', term_getline(buf, 5))}) |
| 230 | call term_sendkeys(buf, "\<CR>") |
| 231 | call WaitForAssert({-> assert_equal(' 8 8', term_getline(buf, 5))}) |
| 232 | call term_sendkeys(buf, "\<Down>") |
| 233 | call WaitForAssert({-> assert_equal(' 9 9', term_getline(buf, 5))}) |
| 234 | |
| 235 | " Down a screen with <Space>, f, or <PageDown>. |
| 236 | call term_sendkeys(buf, 'f') |
| 237 | call WaitForAssert({-> assert_equal(' 14 14', term_getline(buf, 5))}) |
| 238 | call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))}) |
| 239 | call term_sendkeys(buf, ' ') |
| 240 | call WaitForAssert({-> assert_equal(' 19 19', term_getline(buf, 5))}) |
| 241 | call term_sendkeys(buf, "\<PageDown>") |
| 242 | call WaitForAssert({-> assert_equal(' 24 24', term_getline(buf, 5))}) |
| 243 | |
| 244 | " Down a page (half a screen) with d. |
| 245 | call term_sendkeys(buf, 'd') |
| 246 | call WaitForAssert({-> assert_equal(' 27 27', term_getline(buf, 5))}) |
| 247 | |
| 248 | " Down all the way with 'G'. |
| 249 | call term_sendkeys(buf, 'G') |
| 250 | call WaitForAssert({-> assert_equal('100 100', term_getline(buf, 5))}) |
| 251 | call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 6))}) |
| 252 | |
| 253 | " Up a line k, <BS> or <Up>. |
| 254 | call term_sendkeys(buf, 'k') |
| 255 | call WaitForAssert({-> assert_equal(' 99 99', term_getline(buf, 5))}) |
| 256 | call term_sendkeys(buf, "\<BS>") |
| 257 | call WaitForAssert({-> assert_equal(' 98 98', term_getline(buf, 5))}) |
| 258 | call term_sendkeys(buf, "\<Up>") |
| 259 | call WaitForAssert({-> assert_equal(' 97 97', term_getline(buf, 5))}) |
| 260 | |
| 261 | " Up a screen with b or <PageUp>. |
| 262 | call term_sendkeys(buf, 'b') |
| 263 | call WaitForAssert({-> assert_equal(' 92 92', term_getline(buf, 5))}) |
| 264 | call term_sendkeys(buf, "\<PageUp>") |
| 265 | call WaitForAssert({-> assert_equal(' 87 87', term_getline(buf, 5))}) |
| 266 | |
| 267 | " Up a page (half a screen) with u. |
| 268 | call term_sendkeys(buf, 'u') |
| 269 | call WaitForAssert({-> assert_equal(' 84 84', term_getline(buf, 5))}) |
| 270 | |
| 271 | " Up all the way with 'g'. |
| 272 | call term_sendkeys(buf, 'g') |
zeertzjq | ecdc82e | 2022-07-25 19:50:57 +0100 | [diff] [blame] | 273 | call WaitForAssert({-> assert_equal(' 4 4', term_getline(buf, 5))}) |
| 274 | call WaitForAssert({-> assert_equal(':%p#', term_getline(buf, 1))}) |
Bram Moolenaar | c6d539b | 2019-12-28 17:10:46 +0100 | [diff] [blame] | 275 | call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))}) |
| 276 | |
| 277 | " All the way down. Pressing f should do nothing but pressing |
| 278 | " space should end the more prompt. |
| 279 | call term_sendkeys(buf, 'G') |
| 280 | call WaitForAssert({-> assert_equal('100 100', term_getline(buf, 5))}) |
| 281 | call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 6))}) |
| 282 | call term_sendkeys(buf, 'f') |
| 283 | call WaitForAssert({-> assert_equal('100 100', term_getline(buf, 5))}) |
| 284 | call term_sendkeys(buf, ' ') |
| 285 | call WaitForAssert({-> assert_equal('100', term_getline(buf, 5))}) |
| 286 | |
| 287 | " Pressing g< shows the previous command output. |
| 288 | call term_sendkeys(buf, 'g<') |
| 289 | call WaitForAssert({-> assert_equal('100 100', term_getline(buf, 5))}) |
| 290 | call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 6))}) |
| 291 | |
zeertzjq | 46af7bc | 2022-07-28 12:34:09 +0100 | [diff] [blame] | 292 | " A command line that doesn't print text is appended to scrollback, |
| 293 | " even if it invokes a nested command line. |
| 294 | call term_sendkeys(buf, ":\<C-R>=':'\<CR>:\<CR>g<") |
| 295 | call WaitForAssert({-> assert_equal('100 100', term_getline(buf, 4))}) |
| 296 | call WaitForAssert({-> assert_equal(':::', term_getline(buf, 5))}) |
| 297 | call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 6))}) |
| 298 | |
Bram Moolenaar | c6d539b | 2019-12-28 17:10:46 +0100 | [diff] [blame] | 299 | call term_sendkeys(buf, ":%p#\n") |
| 300 | call WaitForAssert({-> assert_equal(' 5 5', term_getline(buf, 5))}) |
| 301 | call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))}) |
| 302 | |
| 303 | " Stop command output with q, <Esc> or CTRL-C. |
| 304 | call term_sendkeys(buf, 'q') |
| 305 | call WaitForAssert({-> assert_equal('100', term_getline(buf, 5))}) |
| 306 | |
Bram Moolenaar | f4fcedc | 2021-03-15 18:36:20 +0100 | [diff] [blame] | 307 | " Execute a : command from the more prompt |
| 308 | call term_sendkeys(buf, ":%p#\n") |
| 309 | call term_wait(buf) |
| 310 | call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))}) |
| 311 | call term_sendkeys(buf, ":") |
| 312 | call term_wait(buf) |
| 313 | call WaitForAssert({-> assert_equal(':', term_getline(buf, 6))}) |
| 314 | call term_sendkeys(buf, "echo 'Hello'\n") |
| 315 | call term_wait(buf) |
| 316 | call WaitForAssert({-> assert_equal('Hello ', term_getline(buf, 5))}) |
| 317 | |
Bram Moolenaar | 43c60ed | 2020-02-02 15:55:19 +0100 | [diff] [blame] | 318 | call StopVimInTerminal(buf) |
| 319 | endfunc |
| 320 | |
Bram Moolenaar | 838b746 | 2022-09-26 15:19:56 +0100 | [diff] [blame] | 321 | " Test more-prompt scrollback |
| 322 | func Test_message_more_scrollback() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 323 | CheckScreendump |
Bram Moolenaar | 838b746 | 2022-09-26 15:19:56 +0100 | [diff] [blame] | 324 | CheckRunVimInTerminal |
| 325 | |
| 326 | let lines =<< trim END |
| 327 | set t_ut= |
| 328 | hi Normal ctermfg=15 ctermbg=0 |
| 329 | for i in range(100) |
| 330 | echo i |
| 331 | endfor |
| 332 | END |
| 333 | call writefile(lines, 'XmoreScrollback', 'D') |
| 334 | let buf = RunVimInTerminal('-S XmoreScrollback', {'rows': 10}) |
| 335 | call VerifyScreenDump(buf, 'Test_more_scrollback_1', {}) |
| 336 | |
| 337 | call term_sendkeys(buf, 'f') |
| 338 | call TermWait(buf) |
| 339 | call term_sendkeys(buf, 'b') |
| 340 | call VerifyScreenDump(buf, 'Test_more_scrollback_2', {}) |
| 341 | |
| 342 | call term_sendkeys(buf, 'q') |
| 343 | call TermWait(buf) |
| 344 | call StopVimInTerminal(buf) |
| 345 | endfunc |
| 346 | |
Bram Moolenaar | 800cdbb | 2023-06-15 16:40:02 +0100 | [diff] [blame] | 347 | func Test_message_not_cleared_after_mode() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 348 | CheckScreendump |
Bram Moolenaar | 800cdbb | 2023-06-15 16:40:02 +0100 | [diff] [blame] | 349 | CheckRunVimInTerminal |
| 350 | |
| 351 | let lines =<< trim END |
| 352 | nmap <silent> gx :call DebugSilent('normal')<CR> |
| 353 | vmap <silent> gx :call DebugSilent('visual')<CR> |
| 354 | function DebugSilent(arg) |
| 355 | echomsg "from DebugSilent" a:arg |
| 356 | endfunction |
| 357 | set showmode |
| 358 | set cmdheight=1 |
Bram Moolenaar | da51ad5 | 2023-06-15 18:44:50 +0100 | [diff] [blame] | 359 | call test_settime(1) |
| 360 | call setline(1, ['one', 'NoSuchFile', 'three']) |
Bram Moolenaar | 800cdbb | 2023-06-15 16:40:02 +0100 | [diff] [blame] | 361 | END |
| 362 | call writefile(lines, 'XmessageMode', 'D') |
| 363 | let buf = RunVimInTerminal('-S XmessageMode', {'rows': 10}) |
| 364 | |
| 365 | call term_sendkeys(buf, 'gx') |
| 366 | call TermWait(buf) |
| 367 | call VerifyScreenDump(buf, 'Test_message_not_cleared_after_mode_1', {}) |
| 368 | |
| 369 | " removing the mode message used to also clear the intended message |
| 370 | call term_sendkeys(buf, 'vEgx') |
| 371 | call TermWait(buf) |
| 372 | call VerifyScreenDump(buf, 'Test_message_not_cleared_after_mode_2', {}) |
| 373 | |
Bram Moolenaar | da51ad5 | 2023-06-15 18:44:50 +0100 | [diff] [blame] | 374 | " removing the mode message used to also clear the error message |
| 375 | call term_sendkeys(buf, ":set cmdheight=2\<CR>") |
| 376 | call term_sendkeys(buf, '2GvEgf') |
| 377 | call TermWait(buf) |
| 378 | call VerifyScreenDump(buf, 'Test_message_not_cleared_after_mode_3', {}) |
| 379 | |
Bram Moolenaar | 800cdbb | 2023-06-15 16:40:02 +0100 | [diff] [blame] | 380 | call StopVimInTerminal(buf) |
| 381 | endfunc |
| 382 | |
zeertzjq | fce1fa5 | 2025-02-27 19:19:36 +0100 | [diff] [blame] | 383 | func Test_mode_cleared_after_silent_message() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 384 | CheckScreendump |
zeertzjq | fce1fa5 | 2025-02-27 19:19:36 +0100 | [diff] [blame] | 385 | CheckRunVimInTerminal |
| 386 | |
| 387 | let lines =<< trim END |
| 388 | edit XsilentMessageMode.txt |
| 389 | call setline(1, 'foobar') |
| 390 | autocmd TextChanged * silent update |
| 391 | END |
| 392 | call writefile(lines, 'XsilentMessageMode', 'D') |
| 393 | let buf = RunVimInTerminal('-S XsilentMessageMode', {'rows': 10}) |
| 394 | |
| 395 | call term_sendkeys(buf, 'v') |
| 396 | call TermWait(buf) |
| 397 | call VerifyScreenDump(buf, 'Test_mode_cleared_after_silent_message_1', {}) |
| 398 | |
| 399 | call term_sendkeys(buf, 'd') |
| 400 | call TermWait(buf) |
| 401 | call VerifyScreenDump(buf, 'Test_mode_cleared_after_silent_message_2', {}) |
| 402 | |
| 403 | call StopVimInTerminal(buf) |
| 404 | call delete('XsilentMessageMode.txt') |
| 405 | endfunc |
| 406 | |
Bram Moolenaar | 1190139 | 2022-09-26 19:50:44 +0100 | [diff] [blame] | 407 | " Test verbose message before echo command |
| 408 | func Test_echo_verbose_system() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 409 | CheckScreendump |
Bram Moolenaar | 1190139 | 2022-09-26 19:50:44 +0100 | [diff] [blame] | 410 | CheckRunVimInTerminal |
Bram Moolenaar | f802767 | 2022-09-27 15:55:43 +0100 | [diff] [blame] | 411 | CheckUnix " needs the "seq" command |
Drew Vogel | f0ed0e6 | 2025-02-11 21:36:33 +0100 | [diff] [blame] | 412 | CheckNotMac " the macos TMPDIR is too long for snapshot testing |
Bram Moolenaar | 1190139 | 2022-09-26 19:50:44 +0100 | [diff] [blame] | 413 | |
| 414 | let buf = RunVimInTerminal('', {'rows': 10}) |
| 415 | call term_sendkeys(buf, ":4 verbose echo system('seq 20')\<CR>") |
| 416 | " Note that the screendump is filtered to remove the name of the temp file |
| 417 | call VerifyScreenDump(buf, 'Test_verbose_system_1', {}) |
| 418 | |
| 419 | " display a page and go back, results in exactly the same view |
| 420 | call term_sendkeys(buf, ' ') |
Bram Moolenaar | 19cf525 | 2022-11-27 14:39:31 +0000 | [diff] [blame] | 421 | call TermWait(buf, 50) |
Bram Moolenaar | 1190139 | 2022-09-26 19:50:44 +0100 | [diff] [blame] | 422 | call term_sendkeys(buf, 'b') |
| 423 | call VerifyScreenDump(buf, 'Test_verbose_system_1', {}) |
| 424 | |
| 425 | " do the same with 'cmdheight' set to 2 |
| 426 | call term_sendkeys(buf, 'q') |
| 427 | call TermWait(buf) |
| 428 | call term_sendkeys(buf, ":set ch=2\<CR>") |
| 429 | call TermWait(buf) |
| 430 | call term_sendkeys(buf, ":4 verbose echo system('seq 20')\<CR>") |
| 431 | call VerifyScreenDump(buf, 'Test_verbose_system_2', {}) |
| 432 | |
| 433 | call term_sendkeys(buf, ' ') |
Bram Moolenaar | 19cf525 | 2022-11-27 14:39:31 +0000 | [diff] [blame] | 434 | call TermWait(buf, 50) |
Bram Moolenaar | 1190139 | 2022-09-26 19:50:44 +0100 | [diff] [blame] | 435 | call term_sendkeys(buf, 'b') |
| 436 | call VerifyScreenDump(buf, 'Test_verbose_system_2', {}) |
| 437 | |
| 438 | call term_sendkeys(buf, 'q') |
| 439 | call TermWait(buf) |
| 440 | call StopVimInTerminal(buf) |
| 441 | endfunc |
| 442 | |
Bram Moolenaar | 838b746 | 2022-09-26 15:19:56 +0100 | [diff] [blame] | 443 | |
Bram Moolenaar | 43c60ed | 2020-02-02 15:55:19 +0100 | [diff] [blame] | 444 | func Test_ask_yesno() |
Bram Moolenaar | 494e906 | 2020-05-31 21:28:02 +0200 | [diff] [blame] | 445 | CheckRunVimInTerminal |
Bram Moolenaar | 43c60ed | 2020-02-02 15:55:19 +0100 | [diff] [blame] | 446 | let buf = RunVimInTerminal('', {'rows': 6}) |
| 447 | call term_sendkeys(buf, ":call setline(1, range(1, 2))\n") |
| 448 | |
| 449 | call term_sendkeys(buf, ":2,1s/^/n/\n") |
| 450 | call WaitForAssert({-> assert_equal('Backwards range given, OK to swap (y/n)?', term_getline(buf, 6))}) |
| 451 | call term_sendkeys(buf, "n") |
| 452 | call WaitForAssert({-> assert_match('^Backwards range given, OK to swap (y/n)?n *1,1 *All$', term_getline(buf, 6))}) |
| 453 | call WaitForAssert({-> assert_equal('1', term_getline(buf, 1))}) |
| 454 | |
| 455 | call term_sendkeys(buf, ":2,1s/^/Esc/\n") |
| 456 | call WaitForAssert({-> assert_equal('Backwards range given, OK to swap (y/n)?', term_getline(buf, 6))}) |
| 457 | call term_sendkeys(buf, "\<Esc>") |
| 458 | call WaitForAssert({-> assert_match('^Backwards range given, OK to swap (y/n)?n *1,1 *All$', term_getline(buf, 6))}) |
| 459 | call WaitForAssert({-> assert_equal('1', term_getline(buf, 1))}) |
| 460 | |
| 461 | call term_sendkeys(buf, ":2,1s/^/y/\n") |
| 462 | call WaitForAssert({-> assert_equal('Backwards range given, OK to swap (y/n)?', term_getline(buf, 6))}) |
| 463 | call term_sendkeys(buf, "y") |
| 464 | call WaitForAssert({-> assert_match('^Backwards range given, OK to swap (y/n)?y *2,1 *All$', term_getline(buf, 6))}) |
| 465 | call WaitForAssert({-> assert_equal('y1', term_getline(buf, 1))}) |
| 466 | call WaitForAssert({-> assert_equal('y2', term_getline(buf, 2))}) |
| 467 | |
Bram Moolenaar | c6d539b | 2019-12-28 17:10:46 +0100 | [diff] [blame] | 468 | call StopVimInTerminal(buf) |
| 469 | endfunc |
Bram Moolenaar | 9db2afe | 2020-01-08 18:56:20 +0100 | [diff] [blame] | 470 | |
| 471 | func Test_null() |
| 472 | echom test_null_list() |
| 473 | echom test_null_dict() |
| 474 | echom test_null_blob() |
Bram Moolenaar | 9db2afe | 2020-01-08 18:56:20 +0100 | [diff] [blame] | 475 | echom test_null_string() |
Bram Moolenaar | 92b83cc | 2020-04-25 15:24:44 +0200 | [diff] [blame] | 476 | echom test_null_function() |
Bram Moolenaar | 9db2afe | 2020-01-08 18:56:20 +0100 | [diff] [blame] | 477 | echom test_null_partial() |
Bram Moolenaar | da292b0 | 2020-01-08 19:27:40 +0100 | [diff] [blame] | 478 | if has('job') |
| 479 | echom test_null_job() |
| 480 | echom test_null_channel() |
| 481 | endif |
Bram Moolenaar | 9db2afe | 2020-01-08 18:56:20 +0100 | [diff] [blame] | 482 | endfunc |
Bram Moolenaar | 92b83cc | 2020-04-25 15:24:44 +0200 | [diff] [blame] | 483 | |
Bram Moolenaar | b42c0d5 | 2020-05-29 22:41:41 +0200 | [diff] [blame] | 484 | func Test_mapping_at_hit_return_prompt() |
| 485 | nnoremap <C-B> :echo "hit ctrl-b"<CR> |
| 486 | call feedkeys(":ls\<CR>", "xt") |
Bram Moolenaar | fccd93f | 2020-05-31 22:06:51 +0200 | [diff] [blame] | 487 | call feedkeys("\<*C-B>", "xt") |
Bram Moolenaar | b42c0d5 | 2020-05-29 22:41:41 +0200 | [diff] [blame] | 488 | call assert_match('hit ctrl-b', Screenline(&lines - 1)) |
| 489 | nunmap <C-B> |
| 490 | endfunc |
| 491 | |
Bram Moolenaar | 3d30af8 | 2020-10-13 22:15:56 +0200 | [diff] [blame] | 492 | func Test_quit_long_message() |
| 493 | CheckScreendump |
| 494 | |
| 495 | let content =<< trim END |
| 496 | echom range(9999)->join("\x01") |
| 497 | END |
Bram Moolenaar | 124af71 | 2022-09-25 18:44:03 +0100 | [diff] [blame] | 498 | call writefile(content, 'Xtest_quit_message', 'D') |
| 499 | let buf = RunVimInTerminal('-S Xtest_quit_message', #{rows: 10, wait_for_ruler: 0}) |
| 500 | call WaitForAssert({-> assert_match('^-- More --', term_getline(buf, 10))}) |
Bram Moolenaar | 3d30af8 | 2020-10-13 22:15:56 +0200 | [diff] [blame] | 501 | call term_sendkeys(buf, "q") |
| 502 | call VerifyScreenDump(buf, 'Test_quit_long_message', {}) |
| 503 | |
| 504 | " clean up |
| 505 | call StopVimInTerminal(buf) |
Bram Moolenaar | 3d30af8 | 2020-10-13 22:15:56 +0200 | [diff] [blame] | 506 | endfunc |
| 507 | |
Bram Moolenaar | 2de5371 | 2021-12-19 11:06:35 +0000 | [diff] [blame] | 508 | " this was missing a terminating NUL |
| 509 | func Test_echo_string_partial() |
| 510 | function CountSpaces() |
| 511 | endfunction |
Yegappan Lakshmanan | bc404bf | 2021-12-19 19:19:31 +0000 | [diff] [blame] | 512 | 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] | 513 | endfunc |
| 514 | |
zeertzjq | 40ed671 | 2023-11-23 20:37:01 +0100 | [diff] [blame] | 515 | " Test that fileinfo is shown properly when 'cmdheight' has just decreased |
| 516 | " due to switching tabpage and 'shortmess' doesn't contain 'o' or 'O'. |
| 517 | func Test_fileinfo_tabpage_cmdheight() |
| 518 | CheckRunVimInTerminal |
| 519 | |
| 520 | let content =<< trim END |
| 521 | set shortmess-=o |
| 522 | set shortmess-=O |
| 523 | set shortmess-=F |
| 524 | tabnew |
| 525 | set cmdheight=2 |
| 526 | tabprev |
| 527 | edit Xfileinfo.txt |
| 528 | END |
| 529 | |
| 530 | call writefile(content, 'Xtest_fileinfo_tabpage_cmdheight', 'D') |
| 531 | let buf = RunVimInTerminal('-S Xtest_fileinfo_tabpage_cmdheight', #{rows: 6}) |
| 532 | call WaitForAssert({-> assert_match('^"Xfileinfo.txt" \[New\]', term_getline(buf, 6))}) |
| 533 | |
| 534 | " clean up |
| 535 | call StopVimInTerminal(buf) |
| 536 | endfunc |
| 537 | |
Rob Pilling | 726f7f9 | 2022-01-20 14:44:38 +0000 | [diff] [blame] | 538 | " Message output was previously overwritten by the fileinfo display, shown |
| 539 | " when switching buffers. If a buffer is switched to, then a message if |
| 540 | " echoed, we should show the message, rather than overwriting it with |
| 541 | " fileinfo. |
| 542 | func Test_fileinfo_after_echo() |
| 543 | CheckScreendump |
| 544 | |
| 545 | let content =<< trim END |
| 546 | file a.txt |
| 547 | |
| 548 | hide edit b.txt |
| 549 | call setline(1, "hi") |
| 550 | setlocal modified |
| 551 | |
| 552 | hide buffer a.txt |
| 553 | |
Bram Moolenaar | 9323ca5 | 2022-03-16 11:14:57 +0000 | [diff] [blame] | 554 | autocmd CursorHold * buf b.txt | w | echo "'b' written" |
Rob Pilling | 726f7f9 | 2022-01-20 14:44:38 +0000 | [diff] [blame] | 555 | END |
| 556 | |
Bram Moolenaar | b152b6a | 2022-09-29 21:37:33 +0100 | [diff] [blame] | 557 | call writefile(content, 'Xtest_fileinfo_after_echo', 'D') |
Rob Pilling | 726f7f9 | 2022-01-20 14:44:38 +0000 | [diff] [blame] | 558 | let buf = RunVimInTerminal('-S Xtest_fileinfo_after_echo', #{rows: 6}) |
Bram Moolenaar | 9323ca5 | 2022-03-16 11:14:57 +0000 | [diff] [blame] | 559 | call term_sendkeys(buf, ":set updatetime=50\<CR>") |
| 560 | call term_sendkeys(buf, "0$") |
Rob Pilling | 726f7f9 | 2022-01-20 14:44:38 +0000 | [diff] [blame] | 561 | call VerifyScreenDump(buf, 'Test_fileinfo_after_echo', {}) |
| 562 | |
| 563 | call term_sendkeys(buf, ":q\<CR>") |
| 564 | |
| 565 | " clean up |
| 566 | call StopVimInTerminal(buf) |
Yegappan Lakshmanan | 7e765a3 | 2022-01-24 11:40:37 +0000 | [diff] [blame] | 567 | call delete('b.txt') |
Rob Pilling | 726f7f9 | 2022-01-20 14:44:38 +0000 | [diff] [blame] | 568 | endfunc |
| 569 | |
Bram Moolenaar | 37fef16 | 2022-08-29 18:16:32 +0100 | [diff] [blame] | 570 | func Test_echowindow() |
| 571 | CheckScreendump |
| 572 | |
| 573 | let lines =<< trim END |
| 574 | call setline(1, 'some text') |
| 575 | func ShowMessage(arg) |
| 576 | echowindow a:arg |
| 577 | endfunc |
| 578 | echowindow 'first line' |
Bram Moolenaar | b5b4f61 | 2022-09-01 16:43:17 +0100 | [diff] [blame] | 579 | func ManyMessages() |
| 580 | for n in range(20) |
| 581 | echowindow 'line' n |
| 582 | endfor |
| 583 | endfunc |
Bram Moolenaar | cf0995d | 2022-09-11 21:36:17 +0100 | [diff] [blame] | 584 | |
| 585 | def TwoMessages() |
| 586 | popup_clear() |
| 587 | set cmdheight=2 |
| 588 | redraw |
| 589 | timer_start(100, (_) => { |
| 590 | echowin 'message' |
| 591 | }) |
| 592 | echo 'one' |
| 593 | echo 'two' |
| 594 | enddef |
| 595 | |
| 596 | def ThreeMessages() |
| 597 | popup_clear() |
| 598 | redraw |
| 599 | timer_start(100, (_) => { |
| 600 | echowin 'later message' |
| 601 | }) |
| 602 | echo 'one' |
| 603 | echo 'two' |
| 604 | echo 'three' |
| 605 | enddef |
Bram Moolenaar | bdc09a1 | 2022-10-07 14:31:45 +0100 | [diff] [blame] | 606 | |
| 607 | def HideWin() |
| 608 | popup_hide(popup_findecho()) |
| 609 | enddef |
Bram Moolenaar | 37fef16 | 2022-08-29 18:16:32 +0100 | [diff] [blame] | 610 | END |
Bram Moolenaar | b152b6a | 2022-09-29 21:37:33 +0100 | [diff] [blame] | 611 | call writefile(lines, 'XtestEchowindow', 'D') |
Bram Moolenaar | 37fef16 | 2022-08-29 18:16:32 +0100 | [diff] [blame] | 612 | let buf = RunVimInTerminal('-S XtestEchowindow', #{rows: 8}) |
| 613 | call VerifyScreenDump(buf, 'Test_echowindow_1', {}) |
| 614 | |
| 615 | call term_sendkeys(buf, ":call ShowMessage('second line')\<CR>") |
| 616 | call VerifyScreenDump(buf, 'Test_echowindow_2', {}) |
| 617 | |
| 618 | call term_sendkeys(buf, ":call popup_clear()\<CR>") |
| 619 | call VerifyScreenDump(buf, 'Test_echowindow_3', {}) |
| 620 | |
Bram Moolenaar | b5b4f61 | 2022-09-01 16:43:17 +0100 | [diff] [blame] | 621 | call term_sendkeys(buf, ":call ManyMessages()\<CR>") |
| 622 | call VerifyScreenDump(buf, 'Test_echowindow_4', {}) |
| 623 | |
Bram Moolenaar | cf0995d | 2022-09-11 21:36:17 +0100 | [diff] [blame] | 624 | call term_sendkeys(buf, ":call TwoMessages()\<CR>") |
| 625 | call VerifyScreenDump(buf, 'Test_echowindow_5', {}) |
| 626 | |
| 627 | call term_sendkeys(buf, ":call ThreeMessages()\<CR>") |
| 628 | sleep 120m |
| 629 | call VerifyScreenDump(buf, 'Test_echowindow_6', {}) |
| 630 | |
| 631 | call term_sendkeys(buf, "\<CR>") |
| 632 | call VerifyScreenDump(buf, 'Test_echowindow_7', {}) |
| 633 | |
Bram Moolenaar | 4569020 | 2022-09-26 12:57:11 +0100 | [diff] [blame] | 634 | call term_sendkeys(buf, ":tabnew\<CR>") |
Bram Moolenaar | bdc09a1 | 2022-10-07 14:31:45 +0100 | [diff] [blame] | 635 | call term_sendkeys(buf, ":7echowin 'more'\<CR>") |
Bram Moolenaar | 4569020 | 2022-09-26 12:57:11 +0100 | [diff] [blame] | 636 | call VerifyScreenDump(buf, 'Test_echowindow_8', {}) |
| 637 | |
Bram Moolenaar | bdc09a1 | 2022-10-07 14:31:45 +0100 | [diff] [blame] | 638 | call term_sendkeys(buf, ":call HideWin()\<CR>") |
| 639 | call VerifyScreenDump(buf, 'Test_echowindow_9', {}) |
| 640 | |
Bram Moolenaar | 37fef16 | 2022-08-29 18:16:32 +0100 | [diff] [blame] | 641 | " clean up |
| 642 | call StopVimInTerminal(buf) |
Bram Moolenaar | 37fef16 | 2022-08-29 18:16:32 +0100 | [diff] [blame] | 643 | endfunc |
| 644 | |
Yasuhiro Matsumoto | a02a8a4 | 2022-09-02 12:16:21 +0100 | [diff] [blame] | 645 | " messages window should not be used while evaluating the :echowin argument |
| 646 | func Test_echowin_eval() |
| 647 | CheckScreendump |
| 648 | |
| 649 | let lines =<< trim END |
| 650 | func ShowMessage() |
| 651 | echo 123 |
| 652 | return 'test' |
| 653 | endfunc |
| 654 | echowindow ShowMessage() |
| 655 | END |
Bram Moolenaar | b152b6a | 2022-09-29 21:37:33 +0100 | [diff] [blame] | 656 | call writefile(lines, 'XtestEchowindow', 'D') |
Yasuhiro Matsumoto | a02a8a4 | 2022-09-02 12:16:21 +0100 | [diff] [blame] | 657 | let buf = RunVimInTerminal('-S XtestEchowindow', #{rows: 8}) |
| 658 | call VerifyScreenDump(buf, 'Test_echowin_eval', {}) |
| 659 | |
| 660 | " clean up |
| 661 | call StopVimInTerminal(buf) |
Yasuhiro Matsumoto | a02a8a4 | 2022-09-02 12:16:21 +0100 | [diff] [blame] | 662 | endfunc |
| 663 | |
Bram Moolenaar | 7cf5839 | 2022-09-09 20:19:40 +0100 | [diff] [blame] | 664 | " messages window should not be used for showing the mode |
| 665 | func Test_echowin_showmode() |
| 666 | CheckScreendump |
| 667 | |
| 668 | let lines =<< trim END |
| 669 | vim9script |
| 670 | setline(1, ['one', 'two']) |
| 671 | timer_start(100, (_) => { |
| 672 | echowin 'echo window' |
| 673 | }) |
| 674 | normal V |
| 675 | END |
| 676 | call writefile(lines, 'XtestEchowinMode', 'D') |
| 677 | let buf = RunVimInTerminal('-S XtestEchowinMode', #{rows: 8}) |
| 678 | call VerifyScreenDump(buf, 'Test_echowin_showmode', {}) |
| 679 | |
| 680 | " clean up |
| 681 | call StopVimInTerminal(buf) |
| 682 | endfunc |
| 683 | |
Christian Brabandt | 51d4d84 | 2024-12-06 17:26:25 +0100 | [diff] [blame] | 684 | func Test_messagesopt_history() |
| 685 | " After setting 'messagesopt' "history" to 2 and outputting a message 4 times |
| 686 | " with :echomsg, is the number of output lines of :messages 2? |
| 687 | set messagesopt=hit-enter,history:2 |
| 688 | echomsg 'foo' |
| 689 | echomsg 'bar' |
| 690 | echomsg 'baz' |
| 691 | echomsg 'foobar' |
| 692 | call assert_equal(['baz', 'foobar'], GetMessages()) |
| 693 | |
| 694 | " When the number of messages is 10 and 'messagesopt' "history" is changed to |
| 695 | " 5, is the number of output lines of :messages 5? |
| 696 | set messagesopt=hit-enter,history:10 |
| 697 | for num in range(1, 10) |
| 698 | echomsg num |
| 699 | endfor |
| 700 | set messagesopt=hit-enter,history:5 |
| 701 | call assert_equal(5, len(GetMessages())) |
| 702 | |
| 703 | " Check empty list |
| 704 | set messagesopt=hit-enter,history:0 |
| 705 | call assert_true(empty(GetMessages())) |
| 706 | |
| 707 | set messagesopt& |
| 708 | endfunc |
| 709 | |
| 710 | func Test_messagesopt_wait() |
| 711 | CheckRunVimInTerminal |
| 712 | |
| 713 | let buf = RunVimInTerminal('', {'rows': 6, 'cols': 45}) |
| 714 | call term_sendkeys(buf, ":set cmdheight=1\n") |
| 715 | |
| 716 | " Check hit-enter prompt |
| 717 | call term_sendkeys(buf, ":set messagesopt=hit-enter,history:500\n") |
zeertzjq | 8cc43da | 2024-12-07 16:09:08 +0100 | [diff] [blame] | 718 | call term_sendkeys(buf, ":echo 'foo' | echo 'bar' | echo 'baz'\n") |
Christian Brabandt | 51d4d84 | 2024-12-06 17:26:25 +0100 | [diff] [blame] | 719 | call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 6))}) |
| 720 | |
| 721 | " Check no hit-enter prompt when "wait:" is set |
| 722 | call term_sendkeys(buf, ":set messagesopt=wait:100,history:500\n") |
zeertzjq | 8cc43da | 2024-12-07 16:09:08 +0100 | [diff] [blame] | 723 | call term_sendkeys(buf, ":echo 'foo' | echo 'bar' | echo 'baz'\n") |
Christian Brabandt | 51d4d84 | 2024-12-06 17:26:25 +0100 | [diff] [blame] | 724 | call WaitForAssert({-> assert_equal(' 0,0-1 All', term_getline(buf, 6))}) |
| 725 | |
| 726 | " clean up |
| 727 | call StopVimInTerminal(buf) |
| 728 | endfunc |
Bram Moolenaar | 4356864 | 2022-08-28 13:02:45 +0100 | [diff] [blame] | 729 | |
Bram Moolenaar | 92b83cc | 2020-04-25 15:24:44 +0200 | [diff] [blame] | 730 | " vim: shiftwidth=2 sts=2 expandtab |