blob: 4bdc1365e1b8260d78969df137044494bbc7c335 [file] [log] [blame]
Bram Moolenaar461a7fc2018-12-22 13:28:07 +01001" Tests for :messages, :echomsg, :echoerr
Bram Moolenaar451f8492016-04-14 17:16:22 +02002
3function Test_messages()
4 let oldmore = &more
5 try
6 set nomore
Bram Moolenaarbea1ede2016-04-14 19:44:36 +02007 " Avoid the "message maintainer" line.
8 let $LANG = ''
Bram Moolenaar451f8492016-04-14 17:16:22 +02009
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 Moolenaarbea1ede2016-04-14 19:44:36 +020016 " get last two messages
Bram Moolenaar451f8492016-04-14 17:16:22 +020017 redir => result
18 2messages | redraw
19 redir END
Bram Moolenaarbea1ede2016-04-14 19:44:36 +020020 let msg_list = split(result, "\n")
21 call assert_equal(["hello8", "hello9"], msg_list)
Bram Moolenaar451f8492016-04-14 17:16:22 +020022
23 " clear messages without last one
24 1messages clear
25 redir => result
Bram Moolenaarbea1ede2016-04-14 19:44:36 +020026 redraw | messages
Bram Moolenaar451f8492016-04-14 17:16:22 +020027 redir END
Bram Moolenaarbea1ede2016-04-14 19:44:36 +020028 let msg_list = split(result, "\n")
29 call assert_equal(['hello9'], msg_list)
Bram Moolenaar451f8492016-04-14 17:16:22 +020030
31 " clear all messages
32 messages clear
33 redir => result
Bram Moolenaarbea1ede2016-04-14 19:44:36 +020034 redraw | messages
Bram Moolenaar451f8492016-04-14 17:16:22 +020035 redir END
Bram Moolenaarbea1ede2016-04-14 19:44:36 +020036 call assert_equal('', result)
Bram Moolenaar451f8492016-04-14 17:16:22 +020037 finally
38 let &more = oldmore
39 endtry
40endfunction
Bram Moolenaar2abad542018-05-19 14:43:45 +020041
Bram Moolenaarf52f9ea2018-06-27 20:49:44 +020042" Patch 7.4.1696 defined the "clearmode()" function for clearing the mode
Bram Moolenaar2abad542018-05-19 14:43:45 +020043" 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 Moolenaar1e115362019-01-09 23:01:02 +010046func Test_stopinsert_does_not_break_message_output()
Bram Moolenaar2abad542018-05-19 14:43:45 +020047 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 Moolenaar1e115362019-01-09 23:01:02 +010061endfunc
Bram Moolenaarb513d302018-12-02 14:55:08 +010062
63func Test_message_completion()
64 call feedkeys(":message \<C-A>\<C-B>\"\<CR>", 'tx')
65 call assert_equal('"message clear', @:)
66endfunc
Bram Moolenaar461a7fc2018-12-22 13:28:07 +010067
68func 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}'))
80endfunc
81
82func 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')
94endfunc