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 | |
| 3 | function Test_messages() |
| 4 | let oldmore = &more |
| 5 | try |
| 6 | set nomore |
Bram Moolenaar | bea1ede | 2016-04-14 19:44:36 +0200 | [diff] [blame] | 7 | " Avoid the "message maintainer" line. |
| 8 | let $LANG = '' |
Bram Moolenaar | 451f849 | 2016-04-14 17:16:22 +0200 | [diff] [blame] | 9 | |
| 10 | let arr = map(range(10), '"hello" . v:val') |
| 11 | for s in arr |
| 12 | echomsg s | redraw |
| 13 | endfor |
| 14 | let result = '' |
| 15 | |
Bram Moolenaar | bea1ede | 2016-04-14 19:44:36 +0200 | [diff] [blame] | 16 | " get last two messages |
Bram Moolenaar | 451f849 | 2016-04-14 17:16:22 +0200 | [diff] [blame] | 17 | redir => result |
| 18 | 2messages | redraw |
| 19 | redir END |
Bram Moolenaar | bea1ede | 2016-04-14 19:44:36 +0200 | [diff] [blame] | 20 | let msg_list = split(result, "\n") |
| 21 | call assert_equal(["hello8", "hello9"], msg_list) |
Bram Moolenaar | 451f849 | 2016-04-14 17:16:22 +0200 | [diff] [blame] | 22 | |
| 23 | " clear messages without last one |
| 24 | 1messages clear |
| 25 | redir => result |
Bram Moolenaar | bea1ede | 2016-04-14 19:44:36 +0200 | [diff] [blame] | 26 | redraw | messages |
Bram Moolenaar | 451f849 | 2016-04-14 17:16:22 +0200 | [diff] [blame] | 27 | redir END |
Bram Moolenaar | bea1ede | 2016-04-14 19:44:36 +0200 | [diff] [blame] | 28 | let msg_list = split(result, "\n") |
| 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 |
| 33 | redir => result |
Bram Moolenaar | bea1ede | 2016-04-14 19:44:36 +0200 | [diff] [blame] | 34 | redraw | messages |
Bram Moolenaar | 451f849 | 2016-04-14 17:16:22 +0200 | [diff] [blame] | 35 | redir END |
Bram Moolenaar | bea1ede | 2016-04-14 19:44:36 +0200 | [diff] [blame] | 36 | call assert_equal('', result) |
Bram Moolenaar | 451f849 | 2016-04-14 17:16:22 +0200 | [diff] [blame] | 37 | finally |
| 38 | let &more = oldmore |
| 39 | endtry |
| 40 | endfunction |
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]')) |
| 74 | call assert_equal("\n{}", execute(':echomsg {}')) |
| 75 | call assert_equal("\n{'a': 1, 'b': 2}", execute(':echomsg {"a": 1, "b": 2}')) |
| 76 | if has('float') |
| 77 | call assert_equal("\n1.23", execute(':echomsg 1.23')) |
| 78 | endif |
| 79 | call assert_match("function('<lambda>\\d*')", execute(':echomsg {-> 1234}')) |
| 80 | endfunc |
| 81 | |
| 82 | func Test_echoerr() |
| 83 | call test_ignore_error('IgNoRe') |
| 84 | call assert_equal("\nIgNoRe hello", execute(':echoerr "IgNoRe hello"')) |
| 85 | call assert_equal("\n12345 IgNoRe", execute(':echoerr 12345 "IgNoRe"')) |
| 86 | call assert_equal("\n[1, 2, 'IgNoRe']", execute(':echoerr [1, 2, "IgNoRe"]')) |
| 87 | call assert_equal("\n{'IgNoRe': 2, 'a': 1}", execute(':echoerr {"a": 1, "IgNoRe": 2}')) |
| 88 | if has('float') |
| 89 | call assert_equal("\n1.23 IgNoRe", execute(':echoerr 1.23 "IgNoRe"')) |
| 90 | endif |
| 91 | call test_ignore_error('<lambda>') |
| 92 | call assert_match("function('<lambda>\\d*')", execute(':echoerr {-> 1234}')) |
| 93 | call test_ignore_error('RESET') |
| 94 | endfunc |