blob: 630226f05b8c5b13ae1f9c7ced93fb530e6b8c00 [file] [log] [blame]
Naruhiko Nishinobe5bd4d2025-05-14 21:20:28 +02001" Tests for tabpanel
2
3source check.vim
4source screendump.vim
5CheckFeature tabpanel
6
7function! s:reset()
8 set tabpanel&
9 set tabpanelopt&
10 set showtabpanel&
11endfunc
12
13function! Test_tabpanel_mouse()
14 let save_showtabline = &showtabline
15 let save_mouse = &mouse
16 set showtabline=0 mouse=a
17
18 tabnew
19 tabnew
20
21 call test_setmouse(1, 1)
22 call feedkeys("\<LeftMouse>", 'xt')
23 call assert_equal(3, tabpagenr())
24
25 set showtabpanel=2 tabpanelopt=columns:10
26
27 call test_setmouse(1, 1)
28 call feedkeys("\<LeftMouse>", 'xt')
29 call assert_equal(1, tabpagenr())
30 call test_setmouse(2, 1)
31 call feedkeys("\<LeftMouse>", 'xt')
32 call assert_equal(2, tabpagenr())
33 call test_setmouse(3, 1)
34 call feedkeys("\<LeftMouse>", 'xt')
35 call assert_equal(3, tabpagenr())
36
37 call feedkeys("\<LeftMouse>", 'xt')
38 call test_setmouse(2, 3)
39 let pos = getmousepos()
40 call assert_equal(2, pos['winrow'])
41 call assert_equal(0, pos['wincol'])
42 call assert_equal(2, pos['screenrow'])
43 call assert_equal(3, pos['screencol'])
44
45 call test_setmouse(1, 11)
46 call feedkeys("\<LeftMouse>", 'xt')
47 let pos = getmousepos()
48 call assert_equal(1, pos['winrow'])
49 call assert_equal(1, pos['wincol'])
50 call assert_equal(1, pos['screenrow'])
51 call assert_equal(11, pos['screencol'])
52
53 new
54 wincmd x
55
56 call test_setmouse(10, 11)
57 call feedkeys("\<LeftMouse>", 'xt')
58 let pos = getmousepos()
59 call assert_equal(10, pos['winrow'])
60 call assert_equal(1, pos['wincol'])
61 call assert_equal(10, pos['screenrow'])
62 call assert_equal(11, pos['screencol'])
63
64 tabonly!
65 call s:reset()
66 let &mouse = save_mouse
67 let &showtabline = save_showtabline
68endfunc
69
70function! Test_tabpanel_drawing()
71 CheckScreendump
72
73 let lines =<< trim END
74 function! MyTabPanel()
75 let n = g:actual_curtabpage
76 let hi = n == tabpagenr() ? 'TabLineSel' : 'TabLine'
77 let label = printf("\n%%#%sTabNumber#%d:%%#%s#", hi, n, hi)
78 let label ..= '%1*%f%*'
79 return label
80 endfunction
81 hi User1 ctermfg=12
82
83 set showtabline=0
84 set showtabpanel=0
85 set tabpanelopt=columns:16
86 set tabpanel=
87 silent edit Xtabpanel1
88
89 nnoremap \01 <Cmd>set showtabpanel=2<CR>
90 nnoremap \02 <C-w>v
91 nnoremap \03 <Cmd>call setline(1, ['a', 'b', 'c'])<CR>
92 nnoremap \04 <Cmd>silent tabnew Xtabpanel2<CR><Cmd>call setline(1, ['d', 'e', 'f'])<CR>
93 nnoremap \05 <Cmd>set tabpanel=%!MyTabPanel()<CR>
94 nnoremap \06 <Cmd>set tabpanelopt+=align:right<CR>
95 nnoremap \07 <Cmd>tab terminal NONE<CR><C-w>N
96 nnoremap \08 <Cmd>tabclose!<CR><Cmd>tabclose!<CR>
97 END
98 call writefile(lines, 'XTest_tabpanel', 'D')
99
100 let buf = RunVimInTerminal('-S XTest_tabpanel', {'rows': 6, 'cols': 45})
101
102 call VerifyScreenDump(buf, 'Test_tabpanel_drawing_00', {})
103
104 for i in range(1, 8)
105 let n = printf('%02d', i)
106 call term_sendkeys(buf, '\' .. n)
107 call VerifyScreenDump(buf, 'Test_tabpanel_drawing_' .. n, {})
108 endfor
109
110 call StopVimInTerminal(buf)
111endfunc
112
113function! Test_tabpanel_drawing_with_popupwin()
114 CheckScreendump
115
116 let lines =<< trim END
117 set showtabpanel=2
118 set tabpanelopt=columns:20
119 set showtabline=0
120 tabnew
121 setlocal buftype=nofile
122 call setbufline(bufnr(), 1, repeat([repeat('.', &columns - 20)], &lines))
123 highlight TestingForTabPanelPopupwin guibg=#7777ff guifg=#000000
124 for line in [1, &lines]
125 for col in [1, &columns - 20 - 2]
126 call popup_create([
127 \ '@',
128 \ ], {
129 \ 'line': line,
130 \ 'col': col,
131 \ 'border': [],
132 \ 'highlight': 'TestingForTabPanelPopupwin',
133 \ })
134 endfor
135 endfor
136 call cursor(4, 10)
137 call popup_atcursor('atcursor', {
138 \ 'highlight': 'TestingForTabPanelPopupwin',
139 \ })
140 END
141 call writefile(lines, 'XTest_tabpanel_with_popupwin', 'D')
142
143 let buf = RunVimInTerminal('-S XTest_tabpanel_with_popupwin', {'rows': 10, 'cols': 45})
144
145 call VerifyScreenDump(buf, 'Test_tabpanel_drawing_with_popupwin_0', {})
146
147 call StopVimInTerminal(buf)
148endfunc
149
150function! Test_tabpanel_drawing_fill_tailing()
151 CheckScreendump
152
153 let lines =<< trim END
154 set showtabpanel=2
155 set tabpanelopt=columns:20
156 set showtabline=0
157 e aaa.txt
158 tabnew
159 e bbb.txt
160 let &tabpanel = "abc"
161 redraw!
162 " Check whether "abc" is cleared
163 let &tabpanel = "\nTOP\n%f\nBOTTOM"
164 END
165 call writefile(lines, 'XTest_tabpanel_fill_tailing', 'D')
166
167 let buf = RunVimInTerminal('-S XTest_tabpanel_fill_tailing', {'rows': 10, 'cols': 45})
168
169 call VerifyScreenDump(buf, 'Test_tabpanel_drawing_fill_tailing_0', {})
170
171 call StopVimInTerminal(buf)
172endfunc
173
174function! Test_tabpanel_drawing_pum()
175 CheckScreendump
176
177 let lines =<< trim END
178 set showtabpanel=2
179 set tabpanelopt=columns:20
180 set showtabline=0
181 e aaa.txt
182 tabnew
183 e bbb.txt
184 END
185 call writefile(lines, 'XTest_tabpanel_pum', 'D')
186
187 let buf = RunVimInTerminal('-S XTest_tabpanel_pum', {'rows': 10, 'cols': 45})
188
189 call term_sendkeys(buf, "i\<C-x>\<C-v>")
190 call VerifyScreenDump(buf, 'Test_tabpanel_drawing_pum_0', {})
191
192 call term_sendkeys(buf, "\<cr> ab\<C-x>\<C-v>")
193 call VerifyScreenDump(buf, 'Test_tabpanel_drawing_pum_1', {})
194
195 call StopVimInTerminal(buf)
196endfunc
197
198function! Test_tabpanel_scrolling()
199 CheckScreendump
200
201 let lines =<< trim END
202 set showtabpanel=2
203 set tabpanelopt=columns:20
204 set showtabline=0
205 set nowrap
206 set number
207 e aaa.txt
208 tabnew
209 e bbb.txt
210 vsplit
211 call setbufline(bufnr(), 1, repeat(['text text text text'], 100))
212 wincmd =
213 END
214 call writefile(lines, 'XTest_tabpanel_scrolling', 'D')
215
216 let buf = RunVimInTerminal('-S XTest_tabpanel_scrolling', {'rows': 10, 'cols': 45})
217 let n = 0
218 for c in ['H', 'J', 'K', 'L']
219 call term_sendkeys(buf, ":wincmd " .. c .. "\<cr>")
220 call term_sendkeys(buf, "\<C-d>\<C-d>")
221 call term_sendkeys(buf, "r@")
222 call VerifyScreenDump(buf, 'Test_tabpanel_drawing_scrolling_' .. n, {})
223 let n += 1
224 endfor
225
226 call StopVimInTerminal(buf)
227endfunc
228
229function! Test_tabpanel_many_tabpages()
230 CheckScreendump
231
232 let lines =<< trim END
233 set showtabpanel=2
234 set tabpanelopt=columns:10
235 set showtabline=0
236 set tabpanel=%{g:actual_curtabpage}:tab
237 execute join(repeat(['tabnew'], 20), ' | ')
238 END
239 call writefile(lines, 'XTest_tabpanel_many_tabpages', 'D')
240
241 let buf = RunVimInTerminal('-S XTest_tabpanel_many_tabpages', {'rows': 10, 'cols': 45})
242 for n in range(0, 3)
243 call term_sendkeys(buf, "gt")
244 call VerifyScreenDump(buf, 'Test_tabpanel_many_tabpages_' .. n, {})
245 endfor
246 call term_sendkeys(buf, ":tabnext +10\<cr>")
247 call term_sendkeys(buf, ":tabnext -3\<cr>")
248 call VerifyScreenDump(buf, 'Test_tabpanel_many_tabpages_4', {})
249
250 call StopVimInTerminal(buf)
251endfunc
252
253function! Test_tabpanel_visual()
254 CheckScreendump
255
256 let lines =<< trim END
257 set showtabpanel=2
258 set tabpanelopt=columns:10
259 set showtabline=0
260 tabnew
261 call setbufline(bufnr(), 1, ['aaa1 bbb1 ccc1 ddd1', 'aaa2 bbb2 ccc2 ddd2', 'aaa3 bbb3 ccc3 ddd3', 'aaa4 bbb4 ccc4 ddd4'])
262 END
263 call writefile(lines, 'XTest_tabpanel_visual', 'D')
264
265 let buf = RunVimInTerminal('-S XTest_tabpanel_visual', {'rows': 10, 'cols': 45})
266 call term_sendkeys(buf, "v2w")
267 call VerifyScreenDump(buf, 'Test_tabpanel_visual_0', {})
268 call term_sendkeys(buf, "\<esc>0jw")
269 call term_sendkeys(buf, "v2wge")
270 call VerifyScreenDump(buf, 'Test_tabpanel_visual_1', {})
271 call term_sendkeys(buf, "y:echo @\"\<cr>")
272 call VerifyScreenDump(buf, 'Test_tabpanel_visual_2', {})
273
274 call StopVimInTerminal(buf)
275endfunc
276
277function! Test_tabpanel_commandline()
278 CheckScreendump
279
280 let lines =<< trim END
281 set showtabpanel=2
282 set tabpanelopt=columns:10
283 set showtabline=0
284 tabnew
285 END
286 call writefile(lines, 'XTest_tabpanel_commandline', 'D')
287
288 let buf = RunVimInTerminal('-S XTest_tabpanel_commandline', {'rows': 10, 'cols': 45})
289 call term_sendkeys(buf, ":ab\<tab>")
290 call VerifyScreenDump(buf, 'Test_tabpanel_commandline_0', {})
291
292 call term_sendkeys(buf, "\<esc>")
293 call term_sendkeys(buf, ":set wildoptions=pum\<cr>")
294 call term_sendkeys(buf, ":ab\<tab>")
295 call VerifyScreenDump(buf, 'Test_tabpanel_commandline_1', {})
296
297 call StopVimInTerminal(buf)
298endfunc
299
300function! Test_tabpanel_tabline_and_tabpanel()
301 CheckScreendump
302
303 let lines =<< trim END
304 set showtabpanel=2
305 set tabpanelopt=columns:10,vert
306 set fillchars=tpl_vert:│
307 set showtabline=2
308 e aaa.txt
309 tabnew
310 e bbb.txt
311 tabnew
312 e ccc.txt
313 END
314 call writefile(lines, 'XTest_tabpanel_tabline_and_tabpanel', 'D')
315
316 let buf = RunVimInTerminal('-S XTest_tabpanel_tabline_and_tabpanel', {'rows': 10, 'cols': 45})
317 call VerifyScreenDump(buf, 'Test_tabpanel_tabline_and_tabpanel_0', {})
318
319 call StopVimInTerminal(buf)
320endfunc
321
322function! Test_tabpanel_dont_overflow_into_tabpanel()
323 CheckScreendump
324
325 let lines =<< trim END
326 set showtabpanel=2
327 set tabpanelopt=columns:10
328 set showtabline=2
329 tabnew
330 call setline(1, repeat('x', 100))
331 set wrap
332 END
333 call writefile(lines, 'XTest_tabpanel_dont_overflow_into_tabpanel', 'D')
334
335 let buf = RunVimInTerminal('-S XTest_tabpanel_dont_overflow_into_tabpanel', {'rows': 10, 'cols': 45})
336 call VerifyScreenDump(buf, 'Test_tabpanel_dont_overflow_into_tabpanel_0', {})
337
338 call StopVimInTerminal(buf)
339endfunc
340
341function! Test_tabpanel_dont_vert_is_multibytes_left()
342 CheckScreendump
343
344 let lines =<< trim END
345 set showtabpanel=2
346 set tabpanelopt=columns:10,vert
347 set fillchars=tpl_vert:│
348 set showtabline=2
349 tabnew
350 END
351 call writefile(lines, 'XTest_tabpanel_vert_is_multibyte_lefts', 'D')
352
353 let buf = RunVimInTerminal('-S XTest_tabpanel_vert_is_multibyte_lefts', {'rows': 10, 'cols': 45})
354 call VerifyScreenDump(buf, 'Test_tabpanel_vert_is_multibytes_left_0', {})
355
356 call term_sendkeys(buf, ":set tabpanelopt=columns:1,vert\<cr>")
357 call VerifyScreenDump(buf, 'Test_tabpanel_vert_is_multibytes_left_1', {})
358
359 call term_sendkeys(buf, ":set tabpanelopt=columns:10,vert\<cr>")
360 call VerifyScreenDump(buf, 'Test_tabpanel_vert_is_multibytes_left_2', {})
361
362 call term_sendkeys(buf, ":set tabpanelopt=columns:2,vert\<cr>")
363 call VerifyScreenDump(buf, 'Test_tabpanel_vert_is_multibytes_left_3', {})
364
365 call StopVimInTerminal(buf)
366endfunc
367
368function! Test_tabpanel_dont_vert_is_multibytes_right()
369 CheckScreendump
370
371 let lines =<< trim END
372 set showtabpanel=2
373 set tabpanelopt=align:right,columns:10,vert
374 set fillchars=tpl_vert:│
375 set showtabline=2
376 tabnew
377 END
378 call writefile(lines, 'XTest_tabpanel_vert_is_multibytes_right', 'D')
379
380 let buf = RunVimInTerminal('-S XTest_tabpanel_vert_is_multibytes_right', {'rows': 10, 'cols': 45})
381 call VerifyScreenDump(buf, 'Test_tabpanel_vert_is_multibytes_right_0', {})
382
383 call term_sendkeys(buf, ":set tabpanelopt=align:right,columns:1,vert\<cr>")
384 call VerifyScreenDump(buf, 'Test_tabpanel_vert_is_multibytes_right_1', {})
385
386 call term_sendkeys(buf, ":set tabpanelopt=align:right,columns:10,vert\<cr>")
387 call VerifyScreenDump(buf, 'Test_tabpanel_vert_is_multibytes_right_2', {})
388
389 call term_sendkeys(buf, ":set tabpanelopt=align:right,columns:2,vert\<cr>")
390 call VerifyScreenDump(buf, 'Test_tabpanel_vert_is_multibytes_right_3', {})
391
392 call StopVimInTerminal(buf)
393endfunc
394
395function! Test_tabpanel_eval_tabpanel_statusline_tabline()
396 CheckScreendump
397
398 let lines =<< trim END
399 function! Expr()
400 return "$%=[%f]%=$"
401 endfunction
402 set laststatus=2
403 set showtabline=2
404 set showtabpanel=2
405 set statusline=%!Expr()
406 set tabline=%!Expr()
407 set tabpanel=%!Expr()
408 set tabpanelopt=columns:10,vert
409 set fillchars=tpl_vert:│
410 e aaa
411 tabnew
412 e bbb
413 tabnew
414 e ccc
415 END
416 call writefile(lines, 'XTest_tabpanel_eval_tabpanel_statusline_tabline', 'D')
417
418 let buf = RunVimInTerminal('-S XTest_tabpanel_eval_tabpanel_statusline_tabline', {'rows': 10, 'cols': 45})
419 call VerifyScreenDump(buf, 'Test_tabpanel_eval_tabpanel_statusline_tabline_0', {})
420 call term_sendkeys(buf, ":set tabpanelopt+=align:right\<cr>")
421 call VerifyScreenDump(buf, 'Test_tabpanel_eval_tabpanel_statusline_tabline_1', {})
422
423 call StopVimInTerminal(buf)
424endfunc
425
426function! Test_tabpanel_noeval_tabpanel_statusline_tabline()
427 CheckScreendump
428
429 let lines =<< trim END
430 set laststatus=2
431 set showtabline=2
432 set showtabpanel=2
433 set statusline=$%=[%f]%=$
434 set tabline=$%=[%f]%=$
435 set tabpanel=$%=[%f]%=$
436 set tabpanelopt=columns:10,vert
437 set fillchars=tpl_vert:│
438 e aaa
439 tabnew
440 e bbb
441 tabnew
442 e ccc
443 END
444 call writefile(lines, 'XTest_tabpanel_noeval_tabpanel_statusline_tabline', 'D')
445
446 let buf = RunVimInTerminal('-S XTest_tabpanel_noeval_tabpanel_statusline_tabline', {'rows': 10, 'cols': 45})
447 call VerifyScreenDump(buf, 'Test_tabpanel_noeval_tabpanel_statusline_tabline_0', {})
448 call term_sendkeys(buf, ":set tabpanelopt+=align:right\<cr>")
449 call VerifyScreenDump(buf, 'Test_tabpanel_noeval_tabpanel_statusline_tabline_1', {})
450
451 call StopVimInTerminal(buf)
452endfunc
453
454function! Test_tabpanel_eval_tabpanel_with_linebreaks()
455 CheckScreendump
456
457 let lines =<< trim END
458 function! Expr()
459 return "top\n$%=[%f]%=$\nbottom"
460 endfunction
461 set showtabpanel=2
462 set tabpanel=%!Expr()
463 set tabpanelopt=columns:10
464 e aaa
465 tabnew
466 e bbb
467 tabnew
468 e ccc
469 END
470 call writefile(lines, 'XTest_tabpanel_eval_tabpanel_with_linebreaks', 'D')
471
472 let buf = RunVimInTerminal('-S XTest_tabpanel_eval_tabpanel_with_linebreaks', {'rows': 10, 'cols': 45})
473 call VerifyScreenDump(buf, 'Test_tabpanel_eval_tabpanel_with_linebreaks_0', {})
474 call term_sendkeys(buf, ":set tabpanelopt+=align:right\<cr>")
475 call VerifyScreenDump(buf, 'Test_tabpanel_eval_tabpanel_with_linebreaks_1', {})
476
477 call StopVimInTerminal(buf)
478endfunc
479
480" vim: shiftwidth=2 sts=2 expandtab