Bram Moolenaar | 461a7fc | 2018-12-22 13:28:07 +0100 | [diff] [blame] | 1 | " Tests for :messages, :echomsg, :echoerr |
Bram Moolenaar | 451f849 | 2016-04-14 17:16:22 +0200 | [diff] [blame] | 2 | |
Bram Moolenaar | abc7c7f | 2019-04-20 15:10:13 +0200 | [diff] [blame] | 3 | source shared.vim |
| 4 | |
Bram Moolenaar | 451f849 | 2016-04-14 17:16:22 +0200 | [diff] [blame] | 5 | function Test_messages() |
| 6 | let oldmore = &more |
| 7 | try |
| 8 | set nomore |
Bram Moolenaar | bea1ede | 2016-04-14 19:44:36 +0200 | [diff] [blame] | 9 | " Avoid the "message maintainer" line. |
| 10 | let $LANG = '' |
Bram Moolenaar | 451f849 | 2016-04-14 17:16:22 +0200 | [diff] [blame] | 11 | |
| 12 | let arr = map(range(10), '"hello" . v:val') |
| 13 | for s in arr |
| 14 | echomsg s | redraw |
| 15 | endfor |
| 16 | let result = '' |
| 17 | |
Bram Moolenaar | bea1ede | 2016-04-14 19:44:36 +0200 | [diff] [blame] | 18 | " get last two messages |
Bram Moolenaar | 451f849 | 2016-04-14 17:16:22 +0200 | [diff] [blame] | 19 | redir => result |
| 20 | 2messages | redraw |
| 21 | redir END |
Bram Moolenaar | bea1ede | 2016-04-14 19:44:36 +0200 | [diff] [blame] | 22 | let msg_list = split(result, "\n") |
| 23 | call assert_equal(["hello8", "hello9"], msg_list) |
Bram Moolenaar | 451f849 | 2016-04-14 17:16:22 +0200 | [diff] [blame] | 24 | |
| 25 | " clear messages without last one |
| 26 | 1messages clear |
| 27 | redir => result |
Bram Moolenaar | bea1ede | 2016-04-14 19:44:36 +0200 | [diff] [blame] | 28 | redraw | messages |
Bram Moolenaar | 451f849 | 2016-04-14 17:16:22 +0200 | [diff] [blame] | 29 | redir END |
Bram Moolenaar | bea1ede | 2016-04-14 19:44:36 +0200 | [diff] [blame] | 30 | let msg_list = split(result, "\n") |
| 31 | call assert_equal(['hello9'], msg_list) |
Bram Moolenaar | 451f849 | 2016-04-14 17:16:22 +0200 | [diff] [blame] | 32 | |
| 33 | " clear all messages |
| 34 | messages clear |
| 35 | redir => result |
Bram Moolenaar | bea1ede | 2016-04-14 19:44:36 +0200 | [diff] [blame] | 36 | redraw | messages |
Bram Moolenaar | 451f849 | 2016-04-14 17:16:22 +0200 | [diff] [blame] | 37 | redir END |
Bram Moolenaar | bea1ede | 2016-04-14 19:44:36 +0200 | [diff] [blame] | 38 | call assert_equal('', result) |
Bram Moolenaar | 451f849 | 2016-04-14 17:16:22 +0200 | [diff] [blame] | 39 | finally |
| 40 | let &more = oldmore |
| 41 | endtry |
| 42 | endfunction |
Bram Moolenaar | 2abad54 | 2018-05-19 14:43:45 +0200 | [diff] [blame] | 43 | |
Bram Moolenaar | f52f9ea | 2018-06-27 20:49:44 +0200 | [diff] [blame] | 44 | " Patch 7.4.1696 defined the "clearmode()" function for clearing the mode |
Bram Moolenaar | 2abad54 | 2018-05-19 14:43:45 +0200 | [diff] [blame] | 45 | " indicator (e.g., "-- INSERT --") when ":stopinsert" is invoked. Message |
| 46 | " output could then be disturbed when 'cmdheight' was greater than one. |
| 47 | " This test ensures that the bugfix for this issue remains in place. |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 48 | func Test_stopinsert_does_not_break_message_output() |
Bram Moolenaar | 2abad54 | 2018-05-19 14:43:45 +0200 | [diff] [blame] | 49 | set cmdheight=2 |
| 50 | redraw! |
| 51 | |
| 52 | stopinsert | echo 'test echo' |
| 53 | call assert_equal(116, screenchar(&lines - 1, 1)) |
| 54 | call assert_equal(32, screenchar(&lines, 1)) |
| 55 | redraw! |
| 56 | |
| 57 | stopinsert | echomsg 'test echomsg' |
| 58 | call assert_equal(116, screenchar(&lines - 1, 1)) |
| 59 | call assert_equal(32, screenchar(&lines, 1)) |
| 60 | redraw! |
| 61 | |
| 62 | set cmdheight& |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 63 | endfunc |
Bram Moolenaar | b513d30 | 2018-12-02 14:55:08 +0100 | [diff] [blame] | 64 | |
| 65 | func Test_message_completion() |
| 66 | call feedkeys(":message \<C-A>\<C-B>\"\<CR>", 'tx') |
| 67 | call assert_equal('"message clear', @:) |
| 68 | endfunc |
Bram Moolenaar | 461a7fc | 2018-12-22 13:28:07 +0100 | [diff] [blame] | 69 | |
| 70 | func Test_echomsg() |
| 71 | call assert_equal("\nhello", execute(':echomsg "hello"')) |
| 72 | call assert_equal("\n", execute(':echomsg ""')) |
| 73 | call assert_equal("\n12345", execute(':echomsg 12345')) |
| 74 | call assert_equal("\n[]", execute(':echomsg []')) |
| 75 | call assert_equal("\n[1, 2, 3]", execute(':echomsg [1, 2, 3]')) |
| 76 | call assert_equal("\n{}", execute(':echomsg {}')) |
| 77 | call assert_equal("\n{'a': 1, 'b': 2}", execute(':echomsg {"a": 1, "b": 2}')) |
| 78 | if has('float') |
| 79 | call assert_equal("\n1.23", execute(':echomsg 1.23')) |
| 80 | endif |
| 81 | call assert_match("function('<lambda>\\d*')", execute(':echomsg {-> 1234}')) |
| 82 | endfunc |
| 83 | |
| 84 | func Test_echoerr() |
| 85 | call test_ignore_error('IgNoRe') |
| 86 | call assert_equal("\nIgNoRe hello", execute(':echoerr "IgNoRe hello"')) |
| 87 | call assert_equal("\n12345 IgNoRe", execute(':echoerr 12345 "IgNoRe"')) |
| 88 | call assert_equal("\n[1, 2, 'IgNoRe']", execute(':echoerr [1, 2, "IgNoRe"]')) |
| 89 | call assert_equal("\n{'IgNoRe': 2, 'a': 1}", execute(':echoerr {"a": 1, "IgNoRe": 2}')) |
| 90 | if has('float') |
| 91 | call assert_equal("\n1.23 IgNoRe", execute(':echoerr 1.23 "IgNoRe"')) |
| 92 | endif |
| 93 | call test_ignore_error('<lambda>') |
| 94 | call assert_match("function('<lambda>\\d*')", execute(':echoerr {-> 1234}')) |
| 95 | call test_ignore_error('RESET') |
| 96 | endfunc |
Bram Moolenaar | abc7c7f | 2019-04-20 15:10:13 +0200 | [diff] [blame] | 97 | |
| 98 | func Test_mode_message_at_leaving_insert_by_ctrl_c() |
| 99 | if !has('terminal') || has('gui_running') |
| 100 | return |
| 101 | endif |
| 102 | |
| 103 | " Set custom statusline built by user-defined function. |
| 104 | let testfile = 'Xtest.vim' |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 105 | let lines =<< trim END |
| 106 | func StatusLine() abort |
| 107 | return "" |
| 108 | endfunc |
| 109 | set statusline=%!StatusLine() |
| 110 | set laststatus=2 |
| 111 | END |
| 112 | call writefile(lines, testfile) |
Bram Moolenaar | abc7c7f | 2019-04-20 15:10:13 +0200 | [diff] [blame] | 113 | |
| 114 | let rows = 10 |
| 115 | let buf = term_start([GetVimProg(), '--clean', '-S', testfile], {'term_rows': rows}) |
| 116 | call term_wait(buf, 200) |
| 117 | call assert_equal('run', job_status(term_getjob(buf))) |
| 118 | |
| 119 | call term_sendkeys(buf, "i") |
| 120 | call WaitForAssert({-> assert_match('^-- INSERT --\s*$', term_getline(buf, rows))}) |
| 121 | call term_sendkeys(buf, "\<C-C>") |
| 122 | call WaitForAssert({-> assert_match('^\s*$', term_getline(buf, rows))}) |
| 123 | |
| 124 | call term_sendkeys(buf, ":qall!\<CR>") |
| 125 | call WaitForAssert({-> assert_equal('dead', job_status(term_getjob(buf)))}) |
| 126 | exe buf . 'bwipe!' |
| 127 | call delete(testfile) |
| 128 | endfunc |
Bram Moolenaar | 4c25bd7 | 2019-04-20 23:38:07 +0200 | [diff] [blame] | 129 | |
| 130 | func Test_mode_message_at_leaving_insert_with_esc_mapped() |
| 131 | if !has('terminal') || has('gui_running') |
| 132 | return |
| 133 | endif |
| 134 | |
| 135 | " Set custom statusline built by user-defined function. |
| 136 | let testfile = 'Xtest.vim' |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 137 | let lines =<< trim END |
| 138 | set laststatus=2 |
| 139 | inoremap <Esc> <Esc>00 |
| 140 | END |
| 141 | call writefile(lines, testfile) |
Bram Moolenaar | 4c25bd7 | 2019-04-20 23:38:07 +0200 | [diff] [blame] | 142 | |
| 143 | let rows = 10 |
| 144 | let buf = term_start([GetVimProg(), '--clean', '-S', testfile], {'term_rows': rows}) |
| 145 | call term_wait(buf, 200) |
| 146 | call assert_equal('run', job_status(term_getjob(buf))) |
| 147 | |
| 148 | call term_sendkeys(buf, "i") |
| 149 | call WaitForAssert({-> assert_match('^-- INSERT --\s*$', term_getline(buf, rows))}) |
| 150 | call term_sendkeys(buf, "\<Esc>") |
| 151 | call WaitForAssert({-> assert_match('^\s*$', term_getline(buf, rows))}) |
| 152 | |
| 153 | call term_sendkeys(buf, ":qall!\<CR>") |
| 154 | call WaitForAssert({-> assert_equal('dead', job_status(term_getjob(buf)))}) |
| 155 | exe buf . 'bwipe!' |
| 156 | call delete(testfile) |
| 157 | endfunc |
Bram Moolenaar | 37f4cbd | 2019-08-23 20:58:45 +0200 | [diff] [blame] | 158 | |
| 159 | func Test_echospace() |
| 160 | set noruler noshowcmd laststatus=1 |
| 161 | call assert_equal(&columns - 1, v:echospace) |
| 162 | split |
| 163 | call assert_equal(&columns - 1, v:echospace) |
| 164 | set ruler |
| 165 | call assert_equal(&columns - 1, v:echospace) |
| 166 | close |
| 167 | call assert_equal(&columns - 19, v:echospace) |
| 168 | set showcmd noruler |
| 169 | call assert_equal(&columns - 12, v:echospace) |
| 170 | set showcmd ruler |
| 171 | call assert_equal(&columns - 29, v:echospace) |
| 172 | |
| 173 | set ruler& showcmd& |
| 174 | endfunc |