xref: /vim-8.2.3635/src/testdir/test_winbar.vim (revision a0122dcd)
1" Test WinBar
2
3source check.vim
4CheckFeature menu
5
6source shared.vim
7
8func Test_add_remove_menu()
9  new
10  amenu 1.10 WinBar.Next :let g:did_next = 11<CR>
11  amenu 1.20 WinBar.Cont :let g:did_cont = 12<CR>
12  redraw
13  call assert_match('Next    Cont', Screenline(1))
14
15  emenu WinBar.Next
16  call assert_equal(11, g:did_next)
17  emenu WinBar.Cont
18  call assert_equal(12, g:did_cont)
19
20  wincmd w
21  call assert_fails('emenu WinBar.Next', 'E334:')
22  wincmd p
23
24  aunmenu WinBar.Next
25  aunmenu WinBar.Cont
26  close
27endfunc
28
29" Create a WinBar with three buttons.
30" Columns of the button edges:
31" _Next_  _Cont_  _Close_
32" 2    7  10  15  18   24
33func SetupWinbar()
34  amenu 1.10 WinBar.Next :let g:did_next = 11<CR>
35  amenu 1.20 WinBar.Cont :let g:did_cont = 12<CR>
36  amenu 1.30 WinBar.Close :close<CR>
37  redraw
38  call assert_match('Next    Cont    Close', Screenline(1))
39endfunc
40
41func Test_click_in_winbar()
42  new
43  call SetupWinbar()
44  let save_mouse = &mouse
45  set mouse=a
46
47  let g:did_next = 0
48  let g:did_cont = 0
49  for col in [1, 8, 9, 16, 17, 25, 26]
50    call test_setmouse(1, col)
51    call feedkeys("\<LeftMouse>", "xt")
52    call assert_equal(0, g:did_next, 'col ' .. col)
53    call assert_equal(0, g:did_cont, 'col ' .. col)
54  endfor
55
56  for col in range(2, 7)
57    let g:did_next = 0
58    call test_setmouse(1, col)
59    call feedkeys("\<LeftMouse>", "xt")
60    call assert_equal(11, g:did_next, 'col ' .. col)
61  endfor
62
63  for col in range(10, 15)
64    let g:did_cont = 0
65    call test_setmouse(1, col)
66    call feedkeys("\<LeftMouse>", "xt")
67    call assert_equal(12, g:did_cont, 'col ' .. col)
68  endfor
69
70  let wincount = winnr('$')
71  call test_setmouse(1, 20)
72  call feedkeys("\<LeftMouse>", "xt")
73  call assert_equal(wincount - 1, winnr('$'))
74
75  let &mouse = save_mouse
76endfunc
77
78func Test_click_in_other_winbar()
79  new
80  call SetupWinbar()
81  let save_mouse = &mouse
82  set mouse=a
83  let winid = win_getid()
84
85  split
86  let [row, col] = win_screenpos(winid)
87
88  " Click on Next button in other window
89  let g:did_next = 0
90  call test_setmouse(row, 5)
91  call feedkeys("\<LeftMouse>", "xt")
92  call assert_equal(11, g:did_next)
93
94  " Click on Cont button in other window from Visual mode
95  let g:did_cont = 0
96  call setline(1, 'select XYZ here')
97  call test_setmouse(row, 12)
98  call feedkeys("0fXvfZ\<LeftMouse>x", "xt")
99  call assert_equal(12, g:did_cont)
100  call assert_equal('select  here', getline(1))
101
102  " Click on Close button in other window
103  let wincount = winnr('$')
104  let winid = win_getid()
105  call test_setmouse(row, 20)
106  call feedkeys("\<LeftMouse>", "xt")
107  call assert_equal(wincount - 1, winnr('$'))
108  call assert_equal(winid, win_getid())
109
110  bwipe!
111endfunc
112
113func Test_redraw_after_scroll()
114  new
115  amenu 1.10 WinBar.Next :let g:did_next = 11<CR>
116  redraw
117  call assert_equal("  Next", Screenline(1))
118  echo "some\nmore"
119  redraw
120  call assert_equal("  Next", Screenline(1))
121  bwipe!
122endfunc
123
124" vim: shiftwidth=2 sts=2 expandtab
125