xref: /vim-8.2.3635/src/testdir/test_winbar.vim (revision 49c51b82)
1" Test WinBar
2
3source check.vim
4CheckFeature menu
5
6source shared.vim
7source screendump.vim
8
9func Test_add_remove_menu()
10  new
11  amenu 1.10 WinBar.Next :let g:did_next = 11<CR>
12  amenu 1.20 WinBar.Cont :let g:did_cont = 12<CR>
13  redraw
14  call assert_match('Next    Cont', Screenline(1))
15
16  emenu WinBar.Next
17  call assert_equal(11, g:did_next)
18  emenu WinBar.Cont
19  call assert_equal(12, g:did_cont)
20
21  wincmd w
22  call assert_fails('emenu WinBar.Next', 'E334:')
23  wincmd p
24
25  aunmenu WinBar.Next
26  aunmenu WinBar.Cont
27  close
28endfunc
29
30" Create a WinBar with three buttons.
31" Columns of the button edges:
32" _Next_  _Cont_  _Close_
33" 2    7  10  15  18   24
34func SetupWinbar()
35  amenu 1.10 WinBar.Next :let g:did_next = 11<CR>
36  amenu 1.20 WinBar.Cont :let g:did_cont = 12<CR>
37  amenu 1.30 WinBar.Close :close<CR>
38  redraw
39  call assert_match('Next    Cont    Close', Screenline(1))
40endfunc
41
42func Test_click_in_winbar()
43  new
44  call SetupWinbar()
45  let save_mouse = &mouse
46  set mouse=a
47
48  let g:did_next = 0
49  let g:did_cont = 0
50  for col in [1, 8, 9, 16, 17, 25, 26]
51    call test_setmouse(1, col)
52    call feedkeys("\<LeftMouse>", "xt")
53    call assert_equal(0, g:did_next, 'col ' .. col)
54    call assert_equal(0, g:did_cont, 'col ' .. col)
55  endfor
56
57  for col in range(2, 7)
58    let g:did_next = 0
59    call test_setmouse(1, col)
60    call feedkeys("\<LeftMouse>", "xt")
61    call assert_equal(11, g:did_next, 'col ' .. col)
62  endfor
63
64  for col in range(10, 15)
65    let g:did_cont = 0
66    call test_setmouse(1, col)
67    call feedkeys("\<LeftMouse>", "xt")
68    call assert_equal(12, g:did_cont, 'col ' .. col)
69  endfor
70
71  let wincount = winnr('$')
72  call test_setmouse(1, 20)
73  call feedkeys("\<LeftMouse>", "xt")
74  call assert_equal(wincount - 1, winnr('$'))
75
76  let &mouse = save_mouse
77endfunc
78
79func Test_click_in_other_winbar()
80  new
81  call SetupWinbar()
82  let save_mouse = &mouse
83  set mouse=a
84  let winid = win_getid()
85
86  split
87  let [row, col] = win_screenpos(winid)
88
89  " Click on Next button in other window
90  let g:did_next = 0
91  call test_setmouse(row, 5)
92  call feedkeys("\<LeftMouse>", "xt")
93  call assert_equal(11, g:did_next)
94
95  " Click on Cont button in other window from Visual mode
96  let g:did_cont = 0
97  call setline(1, 'select XYZ here')
98  call test_setmouse(row, 12)
99  call feedkeys("0fXvfZ\<LeftMouse>x", "xt")
100  call assert_equal(12, g:did_cont)
101  call assert_equal('select  here', getline(1))
102
103  " Click on Close button in other window
104  let wincount = winnr('$')
105  let winid = win_getid()
106  call test_setmouse(row, 20)
107  call feedkeys("\<LeftMouse>", "xt")
108  call assert_equal(wincount - 1, winnr('$'))
109  call assert_equal(winid, win_getid())
110
111  bwipe!
112endfunc
113
114func Test_redraw_after_scroll()
115  new
116  amenu 1.10 WinBar.Next :let g:did_next = 11<CR>
117  redraw
118  call assert_equal("  Next", Screenline(1))
119  echo "some\nmore"
120  redraw
121  call assert_equal("  Next", Screenline(1))
122  bwipe!
123endfunc
124
125func Test_winbar_not_visible()
126  CheckScreendump
127
128  let lines =<< trim END
129      split
130      nnoremenu WinBar.Test :test
131      set winminheight=0
132      wincmd j
133      wincmd _
134  END
135  call writefile(lines, 'XtestWinbarNotVisble')
136  let buf = RunVimInTerminal('-S XtestWinbarNotVisble', #{rows: 10})
137  call VerifyScreenDump(buf, 'Test_winbar_not_visible', {})
138
139  " clean up
140  call StopVimInTerminal(buf)
141  call delete('XtestWinbarNotVisble')
142endfunction
143
144func Test_winbar_not_visible_custom_statusline()
145  CheckScreendump
146
147  let lines =<< trim END
148      split
149      nnoremenu WinBar.Test :test
150      set winminheight=0
151      set statusline=abcde
152      wincmd j
153      wincmd _
154  END
155  call writefile(lines, 'XtestWinbarNotVisble')
156  let buf = RunVimInTerminal('-S XtestWinbarNotVisble', #{rows: 10})
157  call VerifyScreenDump(buf, 'Test_winbar_not_visible_custom_statusline', {})
158
159  " clean up
160  call StopVimInTerminal(buf)
161  call delete('XtestWinbarNotVisble')
162endfunction
163
164" vim: shiftwidth=2 sts=2 expandtab
165