1" Tests for :messages, :echomsg, :echoerr
2
3function Test_messages()
4  let oldmore = &more
5  try
6    set nomore
7    " Avoid the "message maintainer" line.
8    let $LANG = ''
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
16    " get last two messages
17    redir => result
18    2messages | redraw
19    redir END
20    let msg_list = split(result, "\n")
21    call assert_equal(["hello8", "hello9"], msg_list)
22
23    " clear messages without last one
24    1messages clear
25    redir => result
26    redraw | messages
27    redir END
28    let msg_list = split(result, "\n")
29    call assert_equal(['hello9'], msg_list)
30
31    " clear all messages
32    messages clear
33    redir => result
34    redraw | messages
35    redir END
36    call assert_equal('', result)
37  finally
38    let &more = oldmore
39  endtry
40endfunction
41
42" Patch 7.4.1696 defined the "clearmode()" function for clearing the mode
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.
46func Test_stopinsert_does_not_break_message_output()
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&
61endfunc
62
63func Test_message_completion()
64  call feedkeys(":message \<C-A>\<C-B>\"\<CR>", 'tx')
65  call assert_equal('"message clear', @:)
66endfunc
67
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
95