1" Tests for :messages
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.
46function! 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&
61endfunction
62