blob: c898a233af1c31516ca1dd4b297e81a68dd0c77a [file] [log] [blame]
Bram Moolenaar991dea32016-05-24 11:31:32 +02001" Tests for window cmd (:wincmd, :split, :vsplit, :resize and etc...)
2
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02003source check.vim
Luuk van Baal20e58562022-09-23 12:57:09 +01004source screendump.vim
Bram Moolenaara27e1dc2019-10-07 22:27:36 +02005
Bram Moolenaar991dea32016-05-24 11:31:32 +02006func Test_window_cmd_ls0_with_split()
7 set ls=0
8 set splitbelow
9 split
10 quit
11 call assert_equal(0, &lines - &cmdheight - winheight(0))
12 new | only!
13 "
14 set splitbelow&vim
15 botright split
16 quit
17 call assert_equal(0, &lines - &cmdheight - winheight(0))
18 new | only!
19 set ls&vim
20endfunc
21
zeertzjqfbf20712023-04-26 19:01:44 +010022func Test_window_cmd_ls0_split_scrolling()
23 CheckRunVimInTerminal
24
25 let lines =<< trim END
26 set laststatus=0
27 call setline(1, range(1, 100))
28 normal! G
29 END
30 call writefile(lines, 'XTestLs0SplitScrolling', 'D')
31 let buf = RunVimInTerminal('-S XTestLs0SplitScrolling', #{rows: 10})
32
33 call term_sendkeys(buf, ":botright split\<CR>")
34 call WaitForAssert({-> assert_match('Bot$', term_getline(buf, 5))})
35 call assert_equal('100', term_getline(buf, 4))
36
37 call StopVimInTerminal(buf)
38endfunc
39
Bram Moolenaar991dea32016-05-24 11:31:32 +020040func Test_window_cmd_cmdwin_with_vsp()
Bram Moolenaar72cf47a2018-05-10 18:23:29 +020041 let efmt = 'Expected 0 but got %d (in ls=%d, %s window)'
Bram Moolenaar991dea32016-05-24 11:31:32 +020042 for v in range(0, 2)
43 exec "set ls=" . v
44 vsplit
45 call feedkeys("q:\<CR>")
46 let ac = &lines - (&cmdheight + winheight(0) + !!v)
47 let emsg = printf(efmt, ac, v, 'left')
48 call assert_equal(0, ac, emsg)
49 wincmd w
50 let ac = &lines - (&cmdheight + winheight(0) + !!v)
51 let emsg = printf(efmt, ac, v, 'right')
52 call assert_equal(0, ac, emsg)
53 new | only!
54 endfor
55 set ls&vim
56endfunc
57
Bram Moolenaar96bde992022-08-10 17:23:12 +010058func Test_cmdheight_not_changed()
59 set cmdheight=2
60 set winminheight=0
61 augroup Maximize
62 autocmd WinEnter * wincmd _
63 augroup END
64 split
65 tabnew
66 tabfirst
67 call assert_equal(2, &cmdheight)
68
69 tabonly!
70 only
71 set winminwidth& cmdheight&
72 augroup Maximize
73 au!
74 augroup END
75 augroup! Maximize
76endfunc
77
Bram Moolenaar5d3c9f82020-06-26 20:41:39 +020078" Test for jumping to windows
79func Test_window_jump()
80 new
81 " jumping to a window with a count greater than the max windows
82 exe "normal 4\<C-W>w"
83 call assert_equal(2, winnr())
84 only
85endfunc
86
87func Test_window_cmd_wincmd_gf()
Bram Moolenaar5d2ca042016-06-26 17:11:21 +020088 let fname = 'test_gf.txt'
89 let swp_fname = '.' . fname . '.swp'
Bram Moolenaardb4c9472022-10-15 22:06:06 +010090 call writefile([], fname, 'D')
91 call writefile([], swp_fname, 'D')
Bram Moolenaar5d2ca042016-06-26 17:11:21 +020092 function s:swap_exists()
93 let v:swapchoice = s:swap_choice
94 endfunc
Bram Moolenaareaa49e42019-07-13 18:08:59 +020095 " Remove the catch-all that runtest.vim adds
96 au! SwapExists
Bram Moolenaar5d2ca042016-06-26 17:11:21 +020097 augroup test_window_cmd_wincmd_gf
98 autocmd!
99 exec "autocmd SwapExists " . fname . " call s:swap_exists()"
100 augroup END
101
102 call setline(1, fname)
103 " (E)dit anyway
104 let s:swap_choice = 'e'
105 wincmd gf
106 call assert_equal(2, tabpagenr())
107 call assert_equal(fname, bufname("%"))
108 quit!
109
110 " (Q)uit
111 let s:swap_choice = 'q'
112 wincmd gf
113 call assert_equal(1, tabpagenr())
114 call assert_notequal(fname, bufname("%"))
115 new | only!
116
Bram Moolenaar5d2ca042016-06-26 17:11:21 +0200117 augroup! test_window_cmd_wincmd_gf
118endfunc
119
Bram Moolenaar4520d442017-03-19 16:09:46 +0100120func Test_window_quit()
121 e Xa
122 split Xb
Bram Moolenaarf92e58c2019-09-08 21:51:41 +0200123 call assert_equal(2, '$'->winnr())
Bram Moolenaar4520d442017-03-19 16:09:46 +0100124 call assert_equal('Xb', bufname(winbufnr(1)))
125 call assert_equal('Xa', bufname(winbufnr(2)))
126
127 wincmd q
128 call assert_equal(1, winnr('$'))
129 call assert_equal('Xa', bufname(winbufnr(1)))
130
131 bw Xa Xb
132endfunc
133
Sean Dewarbf44b692024-01-03 18:52:52 +0100134func Test_window_curwin_not_prevwin()
135 botright split
136 call assert_equal(2, winnr())
137 call assert_equal(1, winnr('#'))
138 quit
139 call assert_equal(1, winnr())
140 call assert_equal(0, winnr('#'))
141
142 botright split
143 botright split
144 call assert_equal(3, winnr())
145 call assert_equal(2, winnr('#'))
146 1quit
147 call assert_equal(2, winnr())
148 call assert_equal(1, winnr('#'))
149
150 botright split
151 call assert_equal(1, tabpagenr())
152 call assert_equal(3, winnr())
153 call assert_equal(2, winnr('#'))
154 wincmd T
155 call assert_equal(2, tabpagenr())
156 call assert_equal(1, winnr())
157 call assert_equal(0, winnr('#'))
158 tabfirst
159 call assert_equal(1, tabpagenr())
160 call assert_equal(2, winnr())
161 call assert_equal(0, winnr('#'))
162
163 tabonly
164 botright split
165 wincmd t
166 wincmd p
167 call assert_equal(3, winnr())
168 call assert_equal(1, winnr('#'))
169 quit
170 call assert_equal(2, winnr())
171 call assert_equal(1, winnr('#'))
172
173 botright split
174 wincmd t
175 wincmd p
176 call assert_equal(1, tabpagenr())
177 call assert_equal(3, winnr())
178 call assert_equal(1, winnr('#'))
179 wincmd T
180 call assert_equal(2, tabpagenr())
181 call assert_equal(1, winnr())
182 call assert_equal(0, winnr('#'))
183 tabfirst
184 call assert_equal(1, tabpagenr())
185 call assert_equal(2, winnr())
186 call assert_equal(1, winnr('#'))
187
188 tabonly
189 only
190endfunc
191
Bram Moolenaar4520d442017-03-19 16:09:46 +0100192func Test_window_horizontal_split()
193 call assert_equal(1, winnr('$'))
194 3wincmd s
195 call assert_equal(2, winnr('$'))
196 call assert_equal(3, winheight(0))
Bram Moolenaarf92e58c2019-09-08 21:51:41 +0200197 call assert_equal(winwidth(1), 2->winwidth())
Bram Moolenaar4520d442017-03-19 16:09:46 +0100198
199 call assert_fails('botright topleft wincmd s', 'E442:')
200 bw
201endfunc
202
203func Test_window_vertical_split()
204 call assert_equal(1, winnr('$'))
205 3wincmd v
206 call assert_equal(2, winnr('$'))
207 call assert_equal(3, winwidth(0))
208 call assert_equal(winheight(1), winheight(2))
209
210 call assert_fails('botright topleft wincmd v', 'E442:')
211 bw
212endfunc
213
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100214" Test the ":wincmd ^" and "<C-W>^" commands.
Bram Moolenaar4520d442017-03-19 16:09:46 +0100215func Test_window_split_edit_alternate()
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100216 " Test for failure when the alternate buffer/file no longer exists.
217 edit Xfoo | %bw
Bram Moolenaare2e40752020-09-04 21:18:46 +0200218 call assert_fails(':wincmd ^', 'E23:')
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100219
220 " Test for the expected behavior when we have two named buffers.
221 edit Xfoo | edit Xbar
Bram Moolenaar4520d442017-03-19 16:09:46 +0100222 wincmd ^
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100223 call assert_equal('Xfoo', bufname(winbufnr(1)))
224 call assert_equal('Xbar', bufname(winbufnr(2)))
225 only
Bram Moolenaar4520d442017-03-19 16:09:46 +0100226
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100227 " Test for the expected behavior when the alternate buffer is not named.
228 enew | let l:nr1 = bufnr('%')
229 edit Xfoo | let l:nr2 = bufnr('%')
230 wincmd ^
231 call assert_equal(l:nr1, winbufnr(1))
232 call assert_equal(l:nr2, winbufnr(2))
233 only
234
Bram Moolenaard42333d2018-11-10 20:28:19 +0100235 " FIXME: this currently fails on AppVeyor, but passes locally
236 if !has('win32')
237 " Test the Normal mode command.
238 call feedkeys("\<C-W>\<C-^>", 'tx')
239 call assert_equal(l:nr2, winbufnr(1))
240 call assert_equal(l:nr1, winbufnr(2))
241 endif
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100242
243 %bw!
244endfunc
245
246" Test the ":[count]wincmd ^" and "[count]<C-W>^" commands.
247func Test_window_split_edit_bufnr()
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100248 %bwipeout
249 let l:nr = bufnr('%') + 1
Bram Moolenaare2e40752020-09-04 21:18:46 +0200250 call assert_fails(':execute "normal! ' . l:nr . '\<C-W>\<C-^>"', 'E92:')
251 call assert_fails(':' . l:nr . 'wincmd ^', 'E16:')
252 call assert_fails(':0wincmd ^', 'E16:')
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100253
254 edit Xfoo | edit Xbar | edit Xbaz
255 let l:foo_nr = bufnr('Xfoo')
256 let l:bar_nr = bufnr('Xbar')
257 let l:baz_nr = bufnr('Xbaz')
258
Bram Moolenaar8617b402018-11-10 20:47:48 +0100259 " FIXME: this currently fails on AppVeyor, but passes locally
260 if !has('win32')
261 call feedkeys(l:foo_nr . "\<C-W>\<C-^>", 'tx')
262 call assert_equal('Xfoo', bufname(winbufnr(1)))
263 call assert_equal('Xbaz', bufname(winbufnr(2)))
264 only
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100265
Bram Moolenaar8617b402018-11-10 20:47:48 +0100266 call feedkeys(l:bar_nr . "\<C-W>\<C-^>", 'tx')
267 call assert_equal('Xbar', bufname(winbufnr(1)))
268 call assert_equal('Xfoo', bufname(winbufnr(2)))
269 only
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100270
Bram Moolenaar8617b402018-11-10 20:47:48 +0100271 execute l:baz_nr . 'wincmd ^'
272 call assert_equal('Xbaz', bufname(winbufnr(1)))
273 call assert_equal('Xbar', bufname(winbufnr(2)))
274 endif
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100275
276 %bw!
Bram Moolenaar4520d442017-03-19 16:09:46 +0100277endfunc
278
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100279func Test_window_split_no_room()
280 " N horizontal windows need >= 2*N + 1 lines:
281 " - 1 line + 1 status line in each window
282 " - 1 Ex command line
283 "
284 " 2*N + 1 <= &lines
285 " N <= (lines - 1)/2
286 "
287 " Beyond that number of windows, E36: Not enough room is expected.
288 let hor_win_count = (&lines - 1)/2
289 let hor_split_count = hor_win_count - 1
290 for s in range(1, hor_split_count) | split | endfor
291 call assert_fails('split', 'E36:')
292
Sean Dewar0fd44a52024-02-20 20:28:15 +0100293 botright vsplit
294 wincmd |
295 let layout = winlayout()
296 let restcmd = winrestcmd()
297 call assert_fails('wincmd J', 'E36:')
298 call assert_fails('wincmd K', 'E36:')
299 call assert_equal(layout, winlayout())
300 call assert_equal(restcmd, winrestcmd())
301 only
302
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100303 " N vertical windows need >= 2*(N - 1) + 1 columns:
304 " - 1 column + 1 separator for each window (except last window)
305 " - 1 column for the last window which does not have separator
306 "
307 " 2*(N - 1) + 1 <= &columns
308 " 2*N - 1 <= &columns
309 " N <= (&columns + 1)/2
310 let ver_win_count = (&columns + 1)/2
311 let ver_split_count = ver_win_count - 1
312 for s in range(1, ver_split_count) | vsplit | endfor
313 call assert_fails('vsplit', 'E36:')
314
Sean Dewar0fd44a52024-02-20 20:28:15 +0100315 split
316 wincmd |
317 let layout = winlayout()
318 let restcmd = winrestcmd()
319 call assert_fails('wincmd H', 'E36:')
320 call assert_fails('wincmd L', 'E36:')
321 call assert_equal(layout, winlayout())
322 call assert_equal(restcmd, winrestcmd())
323
324 " Check that the last statusline isn't lost.
325 set laststatus=0
326 let restcmd = winrestcmd()
327 wincmd j
328 call setwinvar(winnr('k'), '&statusline', '@#')
329 let last_stl_row = win_screenpos(0)[0] - 1
330 redraw
331 call assert_equal('@#|', GetScreenStr(last_stl_row))
332 call assert_equal('~ |', GetScreenStr(&lines - &cmdheight))
333 call assert_fails('wincmd H', 'E36:')
334 call assert_fails('wincmd L', 'E36:')
335 call assert_equal(layout, winlayout())
336 call assert_equal(restcmd, winrestcmd())
337 call setwinvar(winnr('k'), '&statusline', '=-')
338 redraw
339 call assert_equal('=-|', GetScreenStr(last_stl_row))
340 call assert_equal('~ |', GetScreenStr(&lines - &cmdheight))
341
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100342 %bw!
Sean Dewar0fd44a52024-02-20 20:28:15 +0100343 set laststatus&
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100344endfunc
345
Bram Moolenaar4520d442017-03-19 16:09:46 +0100346func Test_window_exchange()
347 e Xa
348
349 " Nothing happens with window exchange when there is 1 window
350 wincmd x
351 call assert_equal(1, winnr('$'))
352
353 split Xb
354 split Xc
355
356 call assert_equal('Xc', bufname(winbufnr(1)))
357 call assert_equal('Xb', bufname(winbufnr(2)))
358 call assert_equal('Xa', bufname(winbufnr(3)))
359
360 " Exchange current window 1 with window 3
361 3wincmd x
362 call assert_equal('Xa', bufname(winbufnr(1)))
363 call assert_equal('Xb', bufname(winbufnr(2)))
364 call assert_equal('Xc', bufname(winbufnr(3)))
365
366 " Exchange window with next when at the top window
367 wincmd x
368 call assert_equal('Xb', bufname(winbufnr(1)))
369 call assert_equal('Xa', bufname(winbufnr(2)))
370 call assert_equal('Xc', bufname(winbufnr(3)))
371
372 " Exchange window with next when at the middle window
373 wincmd j
374 wincmd x
375 call assert_equal('Xb', bufname(winbufnr(1)))
376 call assert_equal('Xc', bufname(winbufnr(2)))
377 call assert_equal('Xa', bufname(winbufnr(3)))
378
379 " Exchange window with next when at the bottom window.
380 " When there is no next window, it exchanges with the previous window.
381 wincmd j
382 wincmd x
383 call assert_equal('Xb', bufname(winbufnr(1)))
384 call assert_equal('Xa', bufname(winbufnr(2)))
385 call assert_equal('Xc', bufname(winbufnr(3)))
386
387 bw Xa Xb Xc
388endfunc
389
390func Test_window_rotate()
391 e Xa
392 split Xb
393 split Xc
394 call assert_equal('Xc', bufname(winbufnr(1)))
395 call assert_equal('Xb', bufname(winbufnr(2)))
396 call assert_equal('Xa', bufname(winbufnr(3)))
397
398 " Rotate downwards
399 wincmd r
400 call assert_equal('Xa', bufname(winbufnr(1)))
401 call assert_equal('Xc', bufname(winbufnr(2)))
402 call assert_equal('Xb', bufname(winbufnr(3)))
403
404 2wincmd r
405 call assert_equal('Xc', bufname(winbufnr(1)))
406 call assert_equal('Xb', bufname(winbufnr(2)))
407 call assert_equal('Xa', bufname(winbufnr(3)))
408
409 " Rotate upwards
410 wincmd R
411 call assert_equal('Xb', bufname(winbufnr(1)))
412 call assert_equal('Xa', bufname(winbufnr(2)))
413 call assert_equal('Xc', bufname(winbufnr(3)))
414
415 2wincmd R
416 call assert_equal('Xc', bufname(winbufnr(1)))
417 call assert_equal('Xb', bufname(winbufnr(2)))
418 call assert_equal('Xa', bufname(winbufnr(3)))
419
420 bot vsplit
421 call assert_fails('wincmd R', 'E443:')
422
423 bw Xa Xb Xc
424endfunc
425
426func Test_window_height()
427 e Xa
428 split Xb
429
430 let [wh1, wh2] = [winheight(1), winheight(2)]
431 " Active window (1) should have the same height or 1 more
432 " than the other window.
433 call assert_inrange(wh2, wh2 + 1, wh1)
434
435 wincmd -
436 call assert_equal(wh1 - 1, winheight(1))
437 call assert_equal(wh2 + 1, winheight(2))
438
439 wincmd +
440 call assert_equal(wh1, winheight(1))
Bram Moolenaarf92e58c2019-09-08 21:51:41 +0200441 call assert_equal(wh2, 2->winheight())
Bram Moolenaar4520d442017-03-19 16:09:46 +0100442
443 2wincmd _
444 call assert_equal(2, winheight(1))
445 call assert_equal(wh1 + wh2 - 2, winheight(2))
446
447 wincmd =
448 call assert_equal(wh1, winheight(1))
449 call assert_equal(wh2, winheight(2))
450
451 2wincmd _
452 set winfixheight
453 split Xc
454 let [wh1, wh2, wh3] = [winheight(1), winheight(2), winheight(3)]
455 call assert_equal(2, winheight(2))
456 call assert_inrange(wh3, wh3 + 1, wh1)
457 3wincmd +
458 call assert_equal(2, winheight(2))
459 call assert_equal(wh1 + 3, winheight(1))
460 call assert_equal(wh3 - 3, winheight(3))
461 wincmd =
462 call assert_equal(2, winheight(2))
463 call assert_equal(wh1, winheight(1))
464 call assert_equal(wh3, winheight(3))
465
466 wincmd j
467 set winfixheight&
468
469 wincmd =
470 let [wh1, wh2, wh3] = [winheight(1), winheight(2), winheight(3)]
471 " Current window (2) should have the same height or 1 more
472 " than the other windows.
473 call assert_inrange(wh1, wh1 + 1, wh2)
474 call assert_inrange(wh3, wh3 + 1, wh2)
475
476 bw Xa Xb Xc
477endfunc
478
Bram Moolenaar21c3a802022-08-31 17:49:14 +0100479func Test_wincmd_equal()
480 edit Xone
481 below split Xtwo
482 rightbelow vsplit Xthree
483 call assert_equal('Xone', bufname(winbufnr(1)))
484 call assert_equal('Xtwo', bufname(winbufnr(2)))
485 call assert_equal('Xthree', bufname(winbufnr(3)))
486
487 " Xone and Xtwo should be about the same height
488 let [wh1, wh2] = [winheight(1), winheight(2)]
489 call assert_inrange(wh1 - 1, wh1 + 1, wh2)
490 " Xtwo and Xthree should be about the same width
491 let [ww2, ww3] = [winwidth(2), winwidth(3)]
492 call assert_inrange(ww2 - 1, ww2 + 1, ww3)
493
494 1wincmd w
495 10wincmd _
496 2wincmd w
497 20wincmd |
498 call assert_equal(10, winheight(1))
499 call assert_equal(20, winwidth(2))
500
501 " equalizing horizontally doesn't change the heights
502 hor wincmd =
503 call assert_equal(10, winheight(1))
504 let [ww2, ww3] = [winwidth(2), winwidth(3)]
505 call assert_inrange(ww2 - 1, ww2 + 1, ww3)
506
507 2wincmd w
508 20wincmd |
509 call assert_equal(20, winwidth(2))
510 " equalizing vertically doesn't change the widths
511 vert wincmd =
512 call assert_equal(20, winwidth(2))
513 let [wh1, wh2] = [winheight(1), winheight(2)]
514 call assert_inrange(wh1 - 1, wh1 + 1, wh2)
515
516 bwipe Xone Xtwo Xthree
517endfunc
518
Bram Moolenaar4520d442017-03-19 16:09:46 +0100519func Test_window_width()
520 e Xa
521 vsplit Xb
522
523 let [ww1, ww2] = [winwidth(1), winwidth(2)]
524 " Active window (1) should have the same width or 1 more
525 " than the other window.
526 call assert_inrange(ww2, ww2 + 1, ww1)
527
528 wincmd <
529 call assert_equal(ww1 - 1, winwidth(1))
530 call assert_equal(ww2 + 1, winwidth(2))
531
532 wincmd >
533 call assert_equal(ww1, winwidth(1))
534 call assert_equal(ww2, winwidth(2))
535
536 2wincmd |
537 call assert_equal(2, winwidth(1))
538 call assert_equal(ww1 + ww2 - 2, winwidth(2))
539
540 wincmd =
541 call assert_equal(ww1, winwidth(1))
542 call assert_equal(ww2, winwidth(2))
543
544 2wincmd |
545 set winfixwidth
546 vsplit Xc
547 let [ww1, ww2, ww3] = [winwidth(1), winwidth(2), winwidth(3)]
Bram Moolenaar38e34832017-03-19 20:22:36 +0100548 call assert_equal(2, winwidth(2))
Bram Moolenaar4520d442017-03-19 16:09:46 +0100549 call assert_inrange(ww3, ww3 + 1, ww1)
550 3wincmd >
Bram Moolenaar38e34832017-03-19 20:22:36 +0100551 call assert_equal(2, winwidth(2))
Bram Moolenaar4520d442017-03-19 16:09:46 +0100552 call assert_equal(ww1 + 3, winwidth(1))
553 call assert_equal(ww3 - 3, winwidth(3))
554 wincmd =
Bram Moolenaar38e34832017-03-19 20:22:36 +0100555 call assert_equal(2, winwidth(2))
Bram Moolenaar4520d442017-03-19 16:09:46 +0100556 call assert_equal(ww1, winwidth(1))
557 call assert_equal(ww3, winwidth(3))
558
559 wincmd l
560 set winfixwidth&
561
562 wincmd =
563 let [ww1, ww2, ww3] = [winwidth(1), winwidth(2), winwidth(3)]
564 " Current window (2) should have the same width or 1 more
565 " than the other windows.
566 call assert_inrange(ww1, ww1 + 1, ww2)
567 call assert_inrange(ww3, ww3 + 1, ww2)
568
Yegappan Lakshmanan59585492021-06-12 13:46:41 +0200569 " when the current window width is less than the new 'winwidth', the current
570 " window width should be increased.
571 enew | only
572 split
573 10vnew
574 set winwidth=15
575 call assert_equal(15, winwidth(0))
576
577 %bw!
Bram Moolenaar4520d442017-03-19 16:09:46 +0100578endfunc
579
Bram Moolenaar8eeeba82017-06-25 22:45:39 +0200580func Test_equalalways_on_close()
581 set equalalways
582 vsplit
583 windo split
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100584 split
Bram Moolenaar8eeeba82017-06-25 22:45:39 +0200585 wincmd J
586 " now we have a frame top-left with two windows, a frame top-right with two
587 " windows and a frame at the bottom, full-width.
588 let height_1 = winheight(1)
589 let height_2 = winheight(2)
590 let height_3 = winheight(3)
591 let height_4 = winheight(4)
592 " closing the bottom window causes all windows to be resized.
593 close
594 call assert_notequal(height_1, winheight(1))
595 call assert_notequal(height_2, winheight(2))
596 call assert_notequal(height_3, winheight(3))
597 call assert_notequal(height_4, winheight(4))
598 call assert_equal(winheight(1), winheight(3))
599 call assert_equal(winheight(2), winheight(4))
600
601 1wincmd w
602 split
603 4wincmd w
604 resize + 5
605 " left column has three windows, equalized heights.
606 " right column has two windows, top one a bit higher
607 let height_1 = winheight(1)
608 let height_2 = winheight(2)
609 let height_4 = winheight(4)
610 let height_5 = winheight(5)
611 3wincmd w
612 " closing window in left column equalizes heights in left column but not in
613 " the right column
614 close
615 call assert_notequal(height_1, winheight(1))
616 call assert_notequal(height_2, winheight(2))
617 call assert_equal(height_4, winheight(3))
618 call assert_equal(height_5, winheight(4))
619
620 only
621 set equalalways&
622endfunc
623
Bram Moolenaar22044dc2017-12-02 15:43:37 +0100624func Test_win_screenpos()
Bram Moolenaar5a4c3082019-12-01 15:23:11 +0100625 CheckFeature quickfix
626
Bram Moolenaar22044dc2017-12-02 15:43:37 +0100627 call assert_equal(1, winnr('$'))
628 split
629 vsplit
630 10wincmd _
631 30wincmd |
632 call assert_equal([1, 1], win_screenpos(1))
633 call assert_equal([1, 32], win_screenpos(2))
634 call assert_equal([12, 1], win_screenpos(3))
635 call assert_equal([0, 0], win_screenpos(4))
Bram Moolenaar99fa7212020-04-26 15:59:55 +0200636 call assert_fails('let l = win_screenpos([])', 'E745:')
Bram Moolenaar22044dc2017-12-02 15:43:37 +0100637 only
638endfunc
639
Bram Moolenaar4520d442017-03-19 16:09:46 +0100640func Test_window_jump_tag()
Bram Moolenaar5a4c3082019-12-01 15:23:11 +0100641 CheckFeature quickfix
642
Bram Moolenaar4520d442017-03-19 16:09:46 +0100643 help
644 /iccf
645 call assert_match('^|iccf|', getline('.'))
646 call assert_equal(2, winnr('$'))
647 2wincmd }
648 call assert_equal(3, winnr('$'))
649 call assert_match('^|iccf|', getline('.'))
650 wincmd k
651 call assert_match('\*iccf\*', getline('.'))
652 call assert_equal(2, winheight(0))
653
654 wincmd z
655 set previewheight=4
656 help
657 /bugs
658 wincmd }
659 wincmd k
660 call assert_match('\*bugs\*', getline('.'))
661 call assert_equal(4, winheight(0))
662 set previewheight&
663
664 %bw!
665endfunc
666
667func Test_window_newtab()
668 e Xa
669
670 call assert_equal(1, tabpagenr('$'))
671 call assert_equal("\nAlready only one window", execute('wincmd T'))
672
673 split Xb
674 split Xc
675
676 wincmd T
677 call assert_equal(2, tabpagenr('$'))
678 call assert_equal(['Xb', 'Xa'], map(tabpagebuflist(1), 'bufname(v:val)'))
Bram Moolenaarce90e362019-09-08 18:58:44 +0200679 call assert_equal(['Xc' ], map(2->tabpagebuflist(), 'bufname(v:val)'))
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100680 call assert_equal(['Xc' ], map(tabpagebuflist(), 'bufname(v:val)'))
Bram Moolenaar4520d442017-03-19 16:09:46 +0100681
682 %bw!
683endfunc
684
Bram Moolenaarf79225e2017-03-18 23:11:04 +0100685func Test_next_split_all()
686 " This was causing an illegal memory access.
687 n x
688 norm axxx
689 split
690 split
691 s/x
692 s/x
693 all
694 bwipe!
695endfunc
696
Bram Moolenaar75373f32017-08-07 22:02:30 +0200697" Tests for adjusting window and contents
698func GetScreenStr(row)
699 let str = ""
700 for c in range(1,3)
701 let str .= nr2char(screenchar(a:row, c))
702 endfor
703 return str
704endfunc
705
706func Test_window_contents()
707 enew! | only | new
708 call setline(1, range(1,256))
709
710 exe "norm! \<C-W>t\<C-W>=1Gzt\<C-W>w\<C-W>+"
711 redraw
Bram Moolenaar72cf47a2018-05-10 18:23:29 +0200712 let s3 = GetScreenStr(1)
Bram Moolenaar75373f32017-08-07 22:02:30 +0200713 wincmd p
714 call assert_equal(1, line("w0"))
715 call assert_equal('1 ', s3)
716
717 exe "norm! \<C-W>t\<C-W>=50Gzt\<C-W>w\<C-W>+"
718 redraw
Bram Moolenaar72cf47a2018-05-10 18:23:29 +0200719 let s3 = GetScreenStr(1)
Bram Moolenaar75373f32017-08-07 22:02:30 +0200720 wincmd p
721 call assert_equal(50, line("w0"))
722 call assert_equal('50 ', s3)
723
724 exe "norm! \<C-W>t\<C-W>=59Gzt\<C-W>w\<C-W>+"
725 redraw
Bram Moolenaar72cf47a2018-05-10 18:23:29 +0200726 let s3 = GetScreenStr(1)
Bram Moolenaar75373f32017-08-07 22:02:30 +0200727 wincmd p
728 call assert_equal(59, line("w0"))
729 call assert_equal('59 ', s3)
730
Bram Moolenaar8b633132020-03-20 18:20:51 +0100731 %d
732 call setline(1, ['one', 'two', 'three'])
733 call assert_equal(1, line('w0'))
734 call assert_equal(3, line('w$'))
735
Bram Moolenaar75373f32017-08-07 22:02:30 +0200736 bwipeout!
737 call test_garbagecollect_now()
738endfunc
739
Bram Moolenaar2efb3232017-12-19 12:27:23 +0100740func Test_window_colon_command()
741 " This was reading invalid memory.
742 exe "norm! v\<C-W>:\<C-U>echo v:version"
743endfunc
744
Bram Moolenaar6f361c92018-01-31 19:06:50 +0100745func Test_access_freed_mem()
Bram Moolenaar1417c762019-07-27 17:31:36 +0200746 call assert_equal(&columns, winwidth(0))
Bram Moolenaar9a046fd2021-01-28 13:47:59 +0100747 " This was accessing freed memory (but with what events?)
748 au BufEnter,BufLeave,WinEnter,WinLeave 0 vs xxx
Bram Moolenaar6f361c92018-01-31 19:06:50 +0100749 arg 0
750 argadd
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +0200751 call assert_fails("all", "E242:")
Bram Moolenaar6f361c92018-01-31 19:06:50 +0100752 au!
753 bwipe xxx
Bram Moolenaar1417c762019-07-27 17:31:36 +0200754 call assert_equal(&columns, winwidth(0))
Bram Moolenaar6f361c92018-01-31 19:06:50 +0100755endfunc
756
Bram Moolenaara27e1dc2019-10-07 22:27:36 +0200757func Test_insert_cleared_on_switch_to_term()
758 CheckFeature terminal
759
760 set showmode
761 terminal
762 wincmd p
763
764 call feedkeys("i\<C-O>", 'ntx')
765 redraw
766
767 " The "-- (insert) --" indicator should be visible.
768 let chars = map(range(1, &columns), 'nr2char(screenchar(&lines, v:val))')
769 let str = trim(join(chars, ''))
770 call assert_equal('-- (insert) --', str)
771
772 call feedkeys("\<C-W>p", 'ntx')
773 redraw
774
775 " The "-- (insert) --" indicator should have been cleared.
776 let chars = map(range(1, &columns), 'nr2char(screenchar(&lines, v:val))')
777 let str = trim(join(chars, ''))
778 call assert_equal('', str)
779
780 set showmode&
781 %bw!
782endfunc
783
Bram Moolenaar5bab5552018-04-13 20:41:29 +0200784func Test_visual_cleared_after_window_split()
785 new | only!
786 let smd_save = &showmode
787 set showmode
788 let ls_save = &laststatus
789 set laststatus=1
790 call setline(1, ['a', 'b', 'c', 'd', ''])
791 norm! G
792 exe "norm! kkvk"
793 redraw
794 exe "norm! \<C-W>v"
795 redraw
796 " check if '-- VISUAL --' disappeared from command line
797 let columns = range(1, &columns)
798 let cmdlinechars = map(columns, 'nr2char(screenchar(&lines, v:val))')
799 let cmdline = join(cmdlinechars, '')
800 let cmdline_ltrim = substitute(cmdline, '^\s*', "", "")
801 let mode_shown = substitute(cmdline_ltrim, '\s*$', "", "")
802 call assert_equal('', mode_shown)
803 let &showmode = smd_save
804 let &laststatus = ls_save
805 bwipe!
806endfunc
807
Bram Moolenaar72cf47a2018-05-10 18:23:29 +0200808func Test_winrestcmd()
809 2split
810 3vsplit
Bram Moolenaara0c8aea2021-03-20 19:55:35 +0100811 let restcmd = winrestcmd()
Bram Moolenaar72cf47a2018-05-10 18:23:29 +0200812 call assert_equal(2, winheight(0))
813 call assert_equal(3, winwidth(0))
814 wincmd =
815 call assert_notequal(2, winheight(0))
816 call assert_notequal(3, winwidth(0))
Bram Moolenaara0c8aea2021-03-20 19:55:35 +0100817 exe restcmd
Bram Moolenaar72cf47a2018-05-10 18:23:29 +0200818 call assert_equal(2, winheight(0))
819 call assert_equal(3, winwidth(0))
820 only
Bram Moolenaara0c8aea2021-03-20 19:55:35 +0100821
822 wincmd v
823 wincmd s
824 wincmd v
825 redraw
826 let restcmd = winrestcmd()
827 wincmd _
828 wincmd |
829 exe restcmd
830 redraw
831 call assert_equal(restcmd, winrestcmd())
832
833 only
Bram Moolenaar72cf47a2018-05-10 18:23:29 +0200834endfunc
835
Bram Moolenaar1e115362019-01-09 23:01:02 +0100836func Fun_RenewFile()
Bram Moolenaar026587b2019-08-17 15:08:00 +0200837 " Need to wait a bit for the timestamp to be older.
Bram Moolenaarce90e362019-09-08 18:58:44 +0200838 let old_ftime = getftime("tmp.txt")
839 while getftime("tmp.txt") == old_ftime
840 sleep 100m
841 silent execute '!echo "1" > tmp.txt'
842 endwhile
Bram Moolenaara42df592018-12-24 00:22:39 +0100843 sp
844 wincmd p
845 edit! tmp.txt
Bram Moolenaar1e115362019-01-09 23:01:02 +0100846endfunc
Bram Moolenaara42df592018-12-24 00:22:39 +0100847
848func Test_window_prevwin()
849 " Can we make this work on MS-Windows?
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200850 CheckUnix
Bram Moolenaara42df592018-12-24 00:22:39 +0100851
852 set hidden autoread
Bram Moolenaardb4c9472022-10-15 22:06:06 +0100853 call writefile(['2'], 'tmp.txt', 'D')
Bram Moolenaara42df592018-12-24 00:22:39 +0100854 new tmp.txt
855 q
Bram Moolenaara42df592018-12-24 00:22:39 +0100856 call Fun_RenewFile()
857 call assert_equal(2, winnr())
858 wincmd p
859 call assert_equal(1, winnr())
860 wincmd p
861 q
862 call Fun_RenewFile()
863 call assert_equal(2, winnr())
864 wincmd p
865 call assert_equal(1, winnr())
866 wincmd p
867 " reset
868 q
Bram Moolenaara42df592018-12-24 00:22:39 +0100869 set hidden&vim autoread&vim
870 delfunc Fun_RenewFile
871endfunc
872
Bram Moolenaar8fcb60f2019-03-04 13:18:30 +0100873func Test_relative_cursor_position_in_one_line_window()
874 new
875 only
876 call setline(1, range(1, 10000))
877 normal 50%
878 let lnum = getcurpos()[1]
879 split
880 split
881 " make third window take as many lines as possible, other windows will
882 " become one line
883 3wincmd w
884 for i in range(1, &lines - 6)
885 wincmd +
886 redraw!
887 endfor
888
889 " first and second window should show cursor line
890 let wininfo = getwininfo()
891 call assert_equal(lnum, wininfo[0].topline)
892 call assert_equal(lnum, wininfo[1].topline)
893
894 only!
895 bwipe!
Yegappan Lakshmanan04c4c572022-08-30 19:48:24 +0100896 call assert_fails('call winrestview(test_null_dict())', 'E1297:')
Bram Moolenaar8fcb60f2019-03-04 13:18:30 +0100897endfunc
898
899func Test_relative_cursor_position_after_move_and_resize()
900 let so_save = &so
901 set so=0
902 enew
903 call setline(1, range(1, 10000))
904 normal 50%
905 split
906 1wincmd w
907 " Move cursor to first line in window
908 normal H
909 redraw!
910 " Reduce window height to two lines
911 let height = winheight(0)
912 while winheight(0) > 2
913 wincmd -
914 redraw!
915 endwhile
916 " move cursor to second/last line in window
917 normal j
918 " restore previous height
919 while winheight(0) < height
920 wincmd +
921 redraw!
922 endwhile
923 " make window two lines again
924 while winheight(0) > 2
925 wincmd -
926 redraw!
927 endwhile
928
929 " cursor should be at bottom line
930 let info = getwininfo(win_getid())[0]
931 call assert_equal(info.topline + 1, getcurpos()[1])
932
933 only!
934 bwipe!
935 let &so = so_save
936endfunc
937
938func Test_relative_cursor_position_after_resize()
939 let so_save = &so
940 set so=0
941 enew
942 call setline(1, range(1, 10000))
943 normal 50%
944 split
945 1wincmd w
946 let winid1 = win_getid()
947 let info = getwininfo(winid1)[0]
948 " Move cursor to second line in window
949 exe "normal " . (info.topline + 1) . "G"
950 redraw!
951 let lnum = getcurpos()[1]
952
953 " Make the window only two lines high, cursor should end up in top line
954 2wincmd w
955 exe (info.height - 2) . "wincmd +"
956 redraw!
957 let info = getwininfo(winid1)[0]
958 call assert_equal(lnum, info.topline)
959
960 only!
961 bwipe!
962 let &so = so_save
963endfunc
964
965func Test_relative_cursor_second_line_after_resize()
966 let so_save = &so
967 set so=0
968 enew
969 call setline(1, range(1, 10000))
970 normal 50%
971 split
972 1wincmd w
973 let winid1 = win_getid()
974 let info = getwininfo(winid1)[0]
975
976 " Make the window only two lines high
977 2wincmd _
978
979 " Move cursor to second line in window
980 normal H
981 normal j
982
983 " Make window size bigger, then back to 2 lines
984 for i in range(1, 10)
985 wincmd +
986 redraw!
987 endfor
988 for i in range(1, 10)
989 wincmd -
990 redraw!
991 endfor
992
993 " cursor should end up in bottom line
994 let info = getwininfo(winid1)[0]
995 call assert_equal(info.topline + 1, getcurpos()[1])
996
997 only!
998 bwipe!
999 let &so = so_save
1000endfunc
1001
Bram Moolenaara9b25352019-05-12 14:25:30 +02001002func Test_split_noscroll()
1003 let so_save = &so
Bram Moolenaarbd2d68c2019-05-18 15:36:11 +02001004 enew
1005 call setline(1, range(1, 8))
Bram Moolenaara9b25352019-05-12 14:25:30 +02001006 normal 100%
1007 split
1008
1009 1wincmd w
1010 let winid1 = win_getid()
1011 let info1 = getwininfo(winid1)[0]
1012
1013 2wincmd w
1014 let winid2 = win_getid()
1015 let info2 = getwininfo(winid2)[0]
1016
1017 call assert_equal(1, info1.topline)
1018 call assert_equal(1, info2.topline)
1019
Bram Moolenaarbd2d68c2019-05-18 15:36:11 +02001020 " window that fits all lines by itself, but not when split: closing other
1021 " window should restore fraction.
Bram Moolenaara9b25352019-05-12 14:25:30 +02001022 only!
Bram Moolenaarbd2d68c2019-05-18 15:36:11 +02001023 call setline(1, range(1, &lines - 10))
1024 exe &lines / 4
1025 let winid1 = win_getid()
1026 let info1 = getwininfo(winid1)[0]
1027 call assert_equal(1, info1.topline)
1028 new
1029 redraw
1030 close
1031 let info1 = getwininfo(winid1)[0]
1032 call assert_equal(1, info1.topline)
1033
Bram Moolenaara9b25352019-05-12 14:25:30 +02001034 bwipe!
1035 let &so = so_save
1036endfunc
1037
Bram Moolenaar46ad2882019-04-08 20:01:47 +02001038" Tests for the winnr() function
1039func Test_winnr()
1040 only | tabonly
1041 call assert_equal(1, winnr('j'))
1042 call assert_equal(1, winnr('k'))
1043 call assert_equal(1, winnr('h'))
1044 call assert_equal(1, winnr('l'))
1045
1046 " create a set of horizontally and vertically split windows
1047 leftabove new | wincmd p
1048 leftabove new | wincmd p
1049 rightbelow new | wincmd p
1050 rightbelow new | wincmd p
1051 leftabove vnew | wincmd p
1052 leftabove vnew | wincmd p
1053 rightbelow vnew | wincmd p
1054 rightbelow vnew | wincmd p
1055
1056 call assert_equal(8, winnr('j'))
1057 call assert_equal(2, winnr('k'))
1058 call assert_equal(4, winnr('h'))
1059 call assert_equal(6, winnr('l'))
1060 call assert_equal(9, winnr('2j'))
1061 call assert_equal(1, winnr('2k'))
1062 call assert_equal(3, winnr('2h'))
1063 call assert_equal(7, winnr('2l'))
1064
1065 " Error cases
1066 call assert_fails("echo winnr('0.2k')", 'E15:')
1067 call assert_equal(2, winnr('-2k'))
1068 call assert_fails("echo winnr('-2xj')", 'E15:')
1069 call assert_fails("echo winnr('j2j')", 'E15:')
1070 call assert_fails("echo winnr('ll')", 'E15:')
1071 call assert_fails("echo winnr('5')", 'E15:')
1072 call assert_equal(4, winnr('0h'))
Bram Moolenaar99fa7212020-04-26 15:59:55 +02001073 call assert_fails("let w = winnr([])", 'E730:')
1074 call assert_equal('unknown', win_gettype(-1))
1075 call assert_equal(-1, winheight(-1))
1076 call assert_equal(-1, winwidth(-1))
Bram Moolenaar46ad2882019-04-08 20:01:47 +02001077
1078 tabnew
1079 call assert_equal(8, tabpagewinnr(1, 'j'))
Bram Moolenaarce90e362019-09-08 18:58:44 +02001080 call assert_equal(2, 1->tabpagewinnr('k'))
Bram Moolenaar46ad2882019-04-08 20:01:47 +02001081 call assert_equal(4, tabpagewinnr(1, 'h'))
1082 call assert_equal(6, tabpagewinnr(1, 'l'))
1083
1084 only | tabonly
1085endfunc
1086
Bram Moolenaarf92e58c2019-09-08 21:51:41 +02001087func Test_winrestview()
1088 split runtest.vim
1089 normal 50%
1090 let view = winsaveview()
1091 close
1092 split runtest.vim
1093 eval view->winrestview()
1094 call assert_equal(view, winsaveview())
1095
1096 bwipe!
Yegappan Lakshmanan04c4c572022-08-30 19:48:24 +01001097 call assert_fails('call winrestview(test_null_dict())', 'E1297:')
Bram Moolenaarf92e58c2019-09-08 21:51:41 +02001098endfunc
1099
Bram Moolenaard20dcb32019-09-10 21:22:58 +02001100func Test_win_splitmove()
Bram Moolenaar5a4c3082019-12-01 15:23:11 +01001101 CheckFeature quickfix
1102
Bram Moolenaard20dcb32019-09-10 21:22:58 +02001103 edit a
1104 leftabove split b
1105 leftabove vsplit c
1106 leftabove split d
1107 call assert_equal(0, win_splitmove(winnr(), winnr('l')))
1108 call assert_equal(bufname(winbufnr(1)), 'c')
1109 call assert_equal(bufname(winbufnr(2)), 'd')
1110 call assert_equal(bufname(winbufnr(3)), 'b')
1111 call assert_equal(bufname(winbufnr(4)), 'a')
1112 call assert_equal(0, win_splitmove(winnr(), winnr('j'), {'vertical': 1}))
1113 call assert_equal(0, win_splitmove(winnr(), winnr('j'), {'vertical': 1}))
1114 call assert_equal(bufname(winbufnr(1)), 'c')
1115 call assert_equal(bufname(winbufnr(2)), 'b')
1116 call assert_equal(bufname(winbufnr(3)), 'd')
1117 call assert_equal(bufname(winbufnr(4)), 'a')
1118 call assert_equal(0, win_splitmove(winnr(), winnr('k'), {'vertical': 1}))
1119 call assert_equal(bufname(winbufnr(1)), 'd')
1120 call assert_equal(bufname(winbufnr(2)), 'c')
1121 call assert_equal(bufname(winbufnr(3)), 'b')
1122 call assert_equal(bufname(winbufnr(4)), 'a')
1123 call assert_equal(0, win_splitmove(winnr(), winnr('j'), {'rightbelow': v:true}))
1124 call assert_equal(bufname(winbufnr(1)), 'c')
1125 call assert_equal(bufname(winbufnr(2)), 'b')
1126 call assert_equal(bufname(winbufnr(3)), 'a')
1127 call assert_equal(bufname(winbufnr(4)), 'd')
Yegappan Lakshmanan04c4c572022-08-30 19:48:24 +01001128 call assert_fails('call win_splitmove(winnr(), winnr("k"), test_null_dict())', 'E1297:')
Bram Moolenaard20dcb32019-09-10 21:22:58 +02001129 only | bd
1130
1131 call assert_fails('call win_splitmove(winnr(), 123)', 'E957:')
1132 call assert_fails('call win_splitmove(123, winnr())', 'E957:')
1133 call assert_fails('call win_splitmove(winnr(), winnr())', 'E957:')
Bram Moolenaar7b94e772020-01-06 21:03:24 +01001134
1135 tabnew
1136 call assert_fails('call win_splitmove(1, win_getid(1, 1))', 'E957:')
1137 tabclose
Sean Dewar0fd44a52024-02-20 20:28:15 +01001138
1139 split
1140 augroup WinSplitMove
1141 au!
1142 au WinEnter * ++once call win_gotoid(win_getid(winnr('#')))
1143 augroup END
1144 call assert_fails('call win_splitmove(winnr(), winnr("#"))', 'E855:')
1145
1146 augroup WinSplitMove
1147 au!
1148 au WinLeave * ++once quit
1149 augroup END
1150 call assert_fails('call win_splitmove(winnr(), winnr("#"))', 'E855:')
1151
1152 split
1153 split
1154 augroup WinSplitMove
1155 au!
1156 au WinEnter * ++once let s:triggered = v:true
1157 \| call assert_fails('call win_splitmove(winnr("$"), winnr())', 'E242:')
1158 augroup END
1159 quit
1160 call assert_equal(v:true, s:triggered)
1161 unlet! s:triggered
1162
1163 new
1164 augroup WinSplitMove
1165 au!
1166 au BufHidden * ++once let s:triggered = v:true
1167 \| call assert_fails('call win_splitmove(winnr("#"), winnr())', 'E1159:')
1168 augroup END
1169 hide
1170 call assert_equal(v:true, s:triggered)
1171 unlet! s:triggered
1172
1173 au! WinSplitMove
1174 augroup! WinSplitMove
1175 %bw!
Bram Moolenaard20dcb32019-09-10 21:22:58 +02001176endfunc
1177
Bram Moolenaare20b9ec2020-02-03 21:40:04 +01001178" Test for the :only command
1179func Test_window_only()
1180 new
1181 set modified
1182 new
1183 call assert_fails('only', 'E445:')
1184 only!
Bram Moolenaarbc2b71d2020-02-17 21:33:30 +01001185 " Test for :only with a count
1186 let wid = win_getid()
1187 new
1188 new
1189 3only
1190 call assert_equal(1, winnr('$'))
1191 call assert_equal(wid, win_getid())
1192 call assert_fails('close', 'E444:')
1193 call assert_fails('%close', 'E16:')
Bram Moolenaare20b9ec2020-02-03 21:40:04 +01001194endfunc
1195
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001196" Test for errors with :wincmd
1197func Test_wincmd_errors()
1198 call assert_fails('wincmd g', 'E474:')
1199 call assert_fails('wincmd ab', 'E474:')
1200endfunc
1201
1202" Test for errors with :winpos
1203func Test_winpos_errors()
1204 if !has("gui_running") && !has('win32')
1205 call assert_fails('winpos', 'E188:')
1206 endif
1207 call assert_fails('winpos 10', 'E466:')
1208endfunc
1209
Bram Moolenaar406cd902020-02-18 21:54:41 +01001210" Test for +cmd in a :split command
1211func Test_split_cmd()
1212 split +set\ readonly
1213 call assert_equal(1, &readonly)
1214 call assert_equal(2, winnr('$'))
1215 close
1216endfunc
1217
Bram Moolenaar5080b0a2020-03-22 21:23:47 +01001218" Create maximum number of horizontally or vertically split windows and then
1219" run commands that create a new horizontally/vertically split window
1220func Run_noroom_for_newwindow_test(dir_arg)
1221 let dir = (a:dir_arg == 'v') ? 'vert ' : ''
1222
1223 " Open as many windows as possible
Bram Moolenaarab505b12020-03-23 19:28:44 +01001224 while v:true
Bram Moolenaar5080b0a2020-03-22 21:23:47 +01001225 try
1226 exe dir . 'new'
1227 catch /E36:/
1228 break
1229 endtry
Bram Moolenaarab505b12020-03-23 19:28:44 +01001230 endwhile
Bram Moolenaar5080b0a2020-03-22 21:23:47 +01001231
Bram Moolenaardb4c9472022-10-15 22:06:06 +01001232 call writefile(['first', 'second', 'third'], 'Xnorfile1', 'D')
1233 call writefile([], 'Xnorfile2', 'D')
1234 call writefile([], 'Xnorfile3', 'D')
Bram Moolenaar5080b0a2020-03-22 21:23:47 +01001235
1236 " Argument list related commands
Bram Moolenaarb18b4962022-09-02 21:55:50 +01001237 args Xnorfile1 Xnorfile2 Xnorfile3
Bram Moolenaar5080b0a2020-03-22 21:23:47 +01001238 next
1239 for cmd in ['sargument 2', 'snext', 'sprevious', 'sNext', 'srewind',
1240 \ 'sfirst', 'slast']
1241 call assert_fails(dir .. cmd, 'E36:')
1242 endfor
1243 %argdelete
1244
1245 " Buffer related commands
1246 set modified
1247 hide enew
Bram Moolenaarb18b4962022-09-02 21:55:50 +01001248 for cmd in ['sbuffer Xnorfile1', 'sbnext', 'sbprevious', 'sbNext', 'sbrewind',
Bram Moolenaar5080b0a2020-03-22 21:23:47 +01001249 \ 'sbfirst', 'sblast', 'sball', 'sbmodified', 'sunhide']
1250 call assert_fails(dir .. cmd, 'E36:')
1251 endfor
1252
1253 " Window related commands
Bram Moolenaarb18b4962022-09-02 21:55:50 +01001254 for cmd in ['split', 'split Xnorfile2', 'new', 'new Xnorfile3', 'sview Xnorfile1',
Bram Moolenaar5080b0a2020-03-22 21:23:47 +01001255 \ 'sfind runtest.vim']
1256 call assert_fails(dir .. cmd, 'E36:')
1257 endfor
1258
1259 " Help
1260 call assert_fails(dir .. 'help', 'E36:')
1261 call assert_fails(dir .. 'helpgrep window', 'E36:')
1262
1263 " Command-line window
1264 if a:dir_arg == 'h'
1265 " Cmd-line window is always a horizontally split window
1266 call assert_beeps('call feedkeys("q:\<CR>", "xt")')
1267 endif
1268
1269 " Quickfix and location list window
1270 if has('quickfix')
1271 cexpr ''
1272 call assert_fails(dir .. 'copen', 'E36:')
1273 lexpr ''
1274 call assert_fails(dir .. 'lopen', 'E36:')
1275
1276 " Preview window
Bram Moolenaarb18b4962022-09-02 21:55:50 +01001277 call assert_fails(dir .. 'pedit Xnorfile2', 'E36:')
Bram Moolenaar5080b0a2020-03-22 21:23:47 +01001278 call setline(1, 'abc')
1279 call assert_fails(dir .. 'psearch abc', 'E36:')
1280 endif
1281
1282 " Window commands (CTRL-W ^ and CTRL-W f)
1283 if a:dir_arg == 'h'
1284 call assert_fails('call feedkeys("\<C-W>^", "xt")', 'E36:')
Bram Moolenaarb18b4962022-09-02 21:55:50 +01001285 call setline(1, 'Xnorfile1')
Bram Moolenaar5080b0a2020-03-22 21:23:47 +01001286 call assert_fails('call feedkeys("gg\<C-W>f", "xt")', 'E36:')
1287 endif
1288 enew!
1289
1290 " Tag commands (:stag, :stselect and :stjump)
1291 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//",
Bram Moolenaarb18b4962022-09-02 21:55:50 +01001292 \ "second\tXnorfile1\t2",
1293 \ "third\tXnorfile1\t3",],
Bram Moolenaar5080b0a2020-03-22 21:23:47 +01001294 \ 'Xtags')
1295 set tags=Xtags
1296 call assert_fails(dir .. 'stag second', 'E36:')
1297 call assert_fails('call feedkeys(":" .. dir .. "stselect second\n1\n", "xt")', 'E36:')
1298 call assert_fails(dir .. 'stjump second', 'E36:')
1299 call assert_fails(dir .. 'ptag second', 'E36:')
1300 set tags&
1301 call delete('Xtags')
1302
1303 " :isplit and :dsplit
1304 call setline(1, ['#define FOO 1', 'FOO'])
1305 normal 2G
1306 call assert_fails(dir .. 'isplit FOO', 'E36:')
1307 call assert_fails(dir .. 'dsplit FOO', 'E36:')
1308
1309 " terminal
1310 if has('terminal')
1311 call assert_fails(dir .. 'terminal', 'E36:')
1312 endif
1313
1314 %bwipe!
Bram Moolenaar5080b0a2020-03-22 21:23:47 +01001315 only
1316endfunc
1317
1318func Test_split_cmds_with_no_room()
1319 call Run_noroom_for_newwindow_test('h')
1320 call Run_noroom_for_newwindow_test('v')
1321endfunc
1322
Bram Moolenaarad48e6c2020-04-21 22:19:45 +02001323" Test for various wincmd failures
1324func Test_wincmd_fails()
1325 only!
1326 call assert_beeps("normal \<C-W>w")
1327 call assert_beeps("normal \<C-W>p")
1328 call assert_beeps("normal \<C-W>gk")
1329 call assert_beeps("normal \<C-W>r")
1330 call assert_beeps("normal \<C-W>K")
1331 call assert_beeps("normal \<C-W>H")
1332 call assert_beeps("normal \<C-W>2gt")
1333endfunc
1334
Bram Moolenaarfe6dce82020-09-04 14:41:21 +02001335func Test_window_resize()
1336 " Vertical :resize (absolute, relative, min and max size).
1337 vsplit
1338 vert resize 8
1339 call assert_equal(8, winwidth(0))
1340 vert resize +2
1341 call assert_equal(10, winwidth(0))
1342 vert resize -2
1343 call assert_equal(8, winwidth(0))
1344 vert resize
1345 call assert_equal(&columns - 2, winwidth(0))
1346 vert resize 0
1347 call assert_equal(1, winwidth(0))
1348 vert resize 99999
1349 call assert_equal(&columns - 2, winwidth(0))
1350
1351 %bwipe!
1352
1353 " Horizontal :resize (with absolute, relative size, min and max size).
1354 split
1355 resize 8
1356 call assert_equal(8, winheight(0))
1357 resize +2
1358 call assert_equal(10, winheight(0))
1359 resize -2
1360 call assert_equal(8, winheight(0))
1361 resize
1362 call assert_equal(&lines - 4, winheight(0))
1363 resize 0
1364 call assert_equal(1, winheight(0))
1365 resize 99999
1366 call assert_equal(&lines - 4, winheight(0))
1367
1368 " :resize with explicit window number.
1369 let other_winnr = winnr('j')
1370 exe other_winnr .. 'resize 10'
1371 call assert_equal(10, winheight(other_winnr))
1372 call assert_equal(&lines - 10 - 3, winheight(0))
Bram Moolenaar9668cc52020-10-17 17:39:55 +02001373 exe other_winnr .. 'resize +1'
1374 exe other_winnr .. 'resize +1'
1375 call assert_equal(12, winheight(other_winnr))
1376 call assert_equal(&lines - 10 - 3 -2, winheight(0))
Bram Moolenaar89015a62020-12-29 12:46:51 +01001377 close
1378
1379 vsplit
1380 wincmd l
1381 let other_winnr = winnr('h')
1382 call assert_notequal(winnr(), other_winnr)
Bram Moolenaar5efe0e52021-01-01 14:31:34 +01001383 exe 'vert ' .. other_winnr .. 'resize -' .. &columns
Bram Moolenaar89015a62020-12-29 12:46:51 +01001384 call assert_equal(0, winwidth(other_winnr))
Bram Moolenaarfe6dce82020-09-04 14:41:21 +02001385
1386 %bwipe!
1387endfunc
1388
Bram Moolenaar5d3c9f82020-06-26 20:41:39 +02001389" Test for adjusting the window width when a window is closed with some
1390" windows using 'winfixwidth'
1391func Test_window_width_adjust()
1392 only
1393 " Three vertical windows. Windows 1 and 2 have 'winfixwidth' set and close
1394 " window 2.
1395 wincmd v
1396 vert resize 10
1397 set winfixwidth
1398 wincmd v
1399 set winfixwidth
1400 wincmd c
1401 call assert_inrange(10, 12, winwidth(1))
1402 " Three vertical windows. Windows 2 and 3 have 'winfixwidth' set and close
1403 " window 3.
1404 only
1405 set winfixwidth
1406 wincmd v
1407 vert resize 10
1408 set winfixwidth
1409 wincmd v
1410 set nowinfixwidth
1411 wincmd b
1412 wincmd c
1413 call assert_inrange(10, 12, winwidth(2))
1414
1415 new | only
1416endfunc
1417
1418" Test for jumping to a vertical/horizontal neighbor window based on the
1419" current cursor position
dundargocc57b5bc2022-11-02 13:30:51 +00001420func Test_window_goto_neighbor()
Bram Moolenaar5d3c9f82020-06-26 20:41:39 +02001421 %bw!
1422
1423 " Vertical window movement
1424
1425 " create the following window layout:
1426 " +--+--+
1427 " |w1|w3|
1428 " +--+ |
1429 " |w2| |
1430 " +--+--+
1431 " |w4 |
1432 " +-----+
1433 new
1434 vsplit
1435 split
1436 " vertically jump from w4
1437 wincmd b
1438 call setline(1, repeat(' ', &columns))
1439 call cursor(1, 1)
1440 wincmd k
1441 call assert_equal(2, winnr())
1442 wincmd b
1443 call cursor(1, &columns)
1444 redraw!
1445 wincmd k
1446 call assert_equal(3, winnr())
1447 %bw!
1448
1449 " create the following window layout:
1450 " +--+--+--+
1451 " |w1|w2|w3|
1452 " +--+--+--+
1453 " |w4 |
1454 " +--------+
1455 new
1456 vsplit
1457 vsplit
1458 wincmd b
1459 call setline(1, repeat(' ', &columns))
1460 call cursor(1, 1)
1461 wincmd k
1462 call assert_equal(1, winnr())
1463 wincmd b
1464 call cursor(1, &columns / 2)
1465 redraw!
1466 wincmd k
1467 call assert_equal(2, winnr())
1468 wincmd b
1469 call cursor(1, &columns)
1470 redraw!
1471 wincmd k
1472 call assert_equal(3, winnr())
1473 %bw!
1474
1475 " Horizontal window movement
1476
1477 " create the following window layout:
1478 " +--+--+--+
1479 " |w1|w2|w4|
1480 " +--+--+ |
1481 " |w3 | |
1482 " +-----+--+
1483 vsplit
1484 split
1485 vsplit
1486 4wincmd l
1487 call setline(1, repeat([' '], &lines))
1488 call cursor(1, 1)
1489 redraw!
1490 wincmd h
1491 call assert_equal(2, winnr())
1492 4wincmd l
1493 call cursor(&lines, 1)
1494 redraw!
1495 wincmd h
1496 call assert_equal(3, winnr())
1497 %bw!
1498
1499 " create the following window layout:
1500 " +--+--+
1501 " |w1|w4|
1502 " +--+ +
1503 " |w2| |
1504 " +--+ +
1505 " |w3| |
1506 " +--+--+
1507 vsplit
1508 split
1509 split
1510 wincmd l
1511 call setline(1, repeat([' '], &lines))
1512 call cursor(1, 1)
1513 redraw!
1514 wincmd h
1515 call assert_equal(1, winnr())
1516 wincmd l
1517 call cursor(&lines / 2, 1)
1518 redraw!
1519 wincmd h
1520 call assert_equal(2, winnr())
1521 wincmd l
1522 call cursor(&lines, 1)
1523 redraw!
1524 wincmd h
1525 call assert_equal(3, winnr())
1526 %bw!
1527endfunc
1528
1529" Test for an autocmd closing the destination window when jumping from one
1530" window to another.
1531func Test_close_dest_window()
1532 split
Bram Moolenaarb18b4962022-09-02 21:55:50 +01001533 edit Xdstfile
Bram Moolenaar5d3c9f82020-06-26 20:41:39 +02001534
1535 " Test for BufLeave
1536 augroup T1
1537 au!
Bram Moolenaarb18b4962022-09-02 21:55:50 +01001538 au BufLeave Xdstfile $wincmd c
Bram Moolenaar5d3c9f82020-06-26 20:41:39 +02001539 augroup END
1540 wincmd b
1541 call assert_equal(1, winnr('$'))
Bram Moolenaarb18b4962022-09-02 21:55:50 +01001542 call assert_equal('Xdstfile', @%)
Bram Moolenaar5d3c9f82020-06-26 20:41:39 +02001543 augroup T1
1544 au!
1545 augroup END
1546
1547 " Test for WinLeave
1548 new
1549 wincmd p
1550 augroup T1
1551 au!
1552 au WinLeave * 1wincmd c
1553 augroup END
1554 wincmd t
1555 call assert_equal(1, winnr('$'))
Bram Moolenaarb18b4962022-09-02 21:55:50 +01001556 call assert_equal('Xdstfile', @%)
Bram Moolenaar5d3c9f82020-06-26 20:41:39 +02001557 augroup T1
1558 au!
1559 augroup END
1560 augroup! T1
1561 %bw!
1562endfunc
1563
Bram Moolenaard0fb9072021-12-09 11:57:22 +00001564func Test_window_minimal_size()
1565 set winminwidth=0 winminheight=0
1566
1567 " check size is fixed vertically
1568 new
1569 call win_execute(win_getid(2), 'wincmd _')
1570 call assert_equal(0, winheight(0))
1571 call feedkeys('0', 'tx')
1572 call assert_equal(1, winheight(0))
1573 bwipe!
1574
1575 " check size is fixed horizontally
1576 vert new
1577 call win_execute(win_getid(2), 'wincmd |')
1578 call assert_equal(0, winwidth(0))
1579 call feedkeys('0', 'tx')
1580 call assert_equal(1, winwidth(0))
1581 bwipe!
1582
1583 if has('timers')
1584 " check size is fixed in Insert mode
ichizokfa9a8e02021-12-12 16:42:09 +00001585 func s:CheckSize(timer) abort
1586 call win_execute(win_getid(2), 'wincmd _')
1587 call assert_equal(0, winheight(0))
1588 call feedkeys(" \<Esc>", 't!')
1589 endfunc
Bram Moolenaard0fb9072021-12-09 11:57:22 +00001590 new
ichizokfa9a8e02021-12-12 16:42:09 +00001591 call timer_start(100, function('s:CheckSize'))
Bram Moolenaard0fb9072021-12-09 11:57:22 +00001592 call feedkeys('a', 'tx!')
1593 call assert_equal(1, winheight(0))
1594 bwipe!
ichizokfa9a8e02021-12-12 16:42:09 +00001595 delfunc s:CheckSize
Bram Moolenaard0fb9072021-12-09 11:57:22 +00001596 endif
1597
1598 set winminwidth& winminheight&
1599endfunc
1600
Daniel Steinbergee630312022-01-10 13:36:34 +00001601func Test_win_move_separator()
1602 edit a
1603 leftabove vsplit b
1604 let w = winwidth(0)
1605 " check win_move_separator from left window on left window
1606 call assert_equal(1, winnr())
1607 for offset in range(5)
1608 call assert_true(win_move_separator(0, offset))
1609 call assert_equal(w + offset, winwidth(0))
1610 call assert_true(0->win_move_separator(-offset))
1611 call assert_equal(w, winwidth(0))
1612 endfor
1613 " check win_move_separator from right window on left window number
1614 wincmd l
1615 call assert_notequal(1, winnr())
1616 for offset in range(5)
1617 call assert_true(1->win_move_separator(offset))
1618 call assert_equal(w + offset, winwidth(1))
1619 call assert_true(win_move_separator(1, -offset))
1620 call assert_equal(w, winwidth(1))
1621 endfor
1622 " check win_move_separator from right window on left window ID
1623 let id = win_getid(1)
1624 for offset in range(5)
1625 call assert_true(win_move_separator(id, offset))
1626 call assert_equal(w + offset, winwidth(id))
1627 call assert_true(id->win_move_separator(-offset))
1628 call assert_equal(w, winwidth(id))
1629 endfor
zeertzjqa0c4e2f2022-01-29 10:59:53 +00001630 " check win_move_separator from right window on right window is no-op
1631 let w0 = winwidth(0)
1632 call assert_true(win_move_separator(0, 1))
1633 call assert_equal(w0, winwidth(0))
1634 call assert_true(win_move_separator(0, -1))
1635 call assert_equal(w0, winwidth(0))
zeertzjq873f41a2022-11-01 11:44:43 +00001636
Daniel Steinbergee630312022-01-10 13:36:34 +00001637 " check that win_move_separator doesn't error with offsets beyond moving
1638 " possibility
1639 call assert_true(win_move_separator(id, 5000))
1640 call assert_true(winwidth(id) > w)
1641 call assert_true(win_move_separator(id, -5000))
1642 call assert_true(winwidth(id) < w)
zeertzjq873f41a2022-11-01 11:44:43 +00001643
Daniel Steinbergee630312022-01-10 13:36:34 +00001644 " check that win_move_separator returns false for an invalid window
1645 wincmd =
1646 let w = winwidth(0)
1647 call assert_false(win_move_separator(-1, 1))
1648 call assert_equal(w, winwidth(0))
zeertzjq873f41a2022-11-01 11:44:43 +00001649
Daniel Steinbergee630312022-01-10 13:36:34 +00001650 " check that win_move_separator returns false for a popup window
1651 let id = popup_create(['hello', 'world'], {})
1652 let w = winwidth(id)
1653 call assert_false(win_move_separator(id, 1))
1654 call assert_equal(w, winwidth(id))
1655 call popup_close(id)
zeertzjq873f41a2022-11-01 11:44:43 +00001656
1657 " check that using another tabpage fails without crash
1658 let id = win_getid()
1659 tabnew
1660 call assert_fails('call win_move_separator(id, -1)', 'E1308:')
1661 tabclose
1662
Daniel Steinbergee630312022-01-10 13:36:34 +00001663 %bwipe!
1664endfunc
1665
1666func Test_win_move_statusline()
1667 edit a
1668 leftabove split b
1669 let h = winheight(0)
1670 " check win_move_statusline from top window on top window
1671 call assert_equal(1, winnr())
1672 for offset in range(5)
1673 call assert_true(win_move_statusline(0, offset))
1674 call assert_equal(h + offset, winheight(0))
1675 call assert_true(0->win_move_statusline(-offset))
1676 call assert_equal(h, winheight(0))
1677 endfor
1678 " check win_move_statusline from bottom window on top window number
1679 wincmd j
1680 call assert_notequal(1, winnr())
1681 for offset in range(5)
1682 call assert_true(1->win_move_statusline(offset))
1683 call assert_equal(h + offset, winheight(1))
1684 call assert_true(win_move_statusline(1, -offset))
1685 call assert_equal(h, winheight(1))
1686 endfor
zeertzjqa0c4e2f2022-01-29 10:59:53 +00001687 " check win_move_statusline from bottom window on bottom window
1688 let h0 = winheight(0)
1689 for offset in range(5)
1690 call assert_true(0->win_move_statusline(-offset))
1691 call assert_equal(h0 - offset, winheight(0))
1692 call assert_equal(1 + offset, &cmdheight)
1693 call assert_true(win_move_statusline(0, offset))
1694 call assert_equal(h0, winheight(0))
1695 call assert_equal(1, &cmdheight)
1696 endfor
1697 call assert_true(win_move_statusline(0, 1))
Bram Moolenaara2a89732022-08-31 14:46:18 +01001698 call assert_equal(h0, winheight(0))
1699 call assert_equal(1, &cmdheight)
Daniel Steinbergee630312022-01-10 13:36:34 +00001700 " check win_move_statusline from bottom window on top window ID
1701 let id = win_getid(1)
1702 for offset in range(5)
1703 call assert_true(win_move_statusline(id, offset))
1704 call assert_equal(h + offset, winheight(id))
1705 call assert_true(id->win_move_statusline(-offset))
1706 call assert_equal(h, winheight(id))
1707 endfor
Bram Moolenaar86e67172022-10-31 12:24:12 +00001708
Daniel Steinbergee630312022-01-10 13:36:34 +00001709 " check that win_move_statusline doesn't error with offsets beyond moving
1710 " possibility
1711 call assert_true(win_move_statusline(id, 5000))
1712 call assert_true(winheight(id) > h)
1713 call assert_true(win_move_statusline(id, -5000))
1714 call assert_true(winheight(id) < h)
Bram Moolenaar86e67172022-10-31 12:24:12 +00001715
Daniel Steinbergee630312022-01-10 13:36:34 +00001716 " check that win_move_statusline returns false for an invalid window
1717 wincmd =
1718 let h = winheight(0)
1719 call assert_false(win_move_statusline(-1, 1))
1720 call assert_equal(h, winheight(0))
Bram Moolenaar86e67172022-10-31 12:24:12 +00001721
Daniel Steinbergee630312022-01-10 13:36:34 +00001722 " check that win_move_statusline returns false for a popup window
1723 let id = popup_create(['hello', 'world'], {})
1724 let h = winheight(id)
1725 call assert_false(win_move_statusline(id, 1))
1726 call assert_equal(h, winheight(id))
1727 call popup_close(id)
Bram Moolenaar86e67172022-10-31 12:24:12 +00001728
1729 " check that using another tabpage fails without crash
1730 let id = win_getid()
1731 tabnew
1732 call assert_fails('call win_move_statusline(id, -1)', 'E1308:')
1733 tabclose
1734
Daniel Steinbergee630312022-01-10 13:36:34 +00001735 %bwipe!
1736endfunc
1737
Yegappan Lakshmanan72bb47e2022-04-03 11:22:38 +01001738" Test for window allocation failure
1739func Test_window_alloc_failure()
1740 %bw!
1741
1742 " test for creating a new window above current window
1743 call test_alloc_fail(GetAllocId('newwin_wvars'), 0, 0)
1744 call assert_fails('above new', 'E342:')
1745 call assert_equal(1, winnr('$'))
1746
1747 " test for creating a new window below current window
1748 call test_alloc_fail(GetAllocId('newwin_wvars'), 0, 0)
1749 call assert_fails('below new', 'E342:')
1750 call assert_equal(1, winnr('$'))
1751
1752 " test for popup window creation failure
1753 call test_alloc_fail(GetAllocId('newwin_wvars'), 0, 0)
1754 call assert_fails('call popup_create("Hello", {})', 'E342:')
1755 call assert_equal([], popup_list())
1756
1757 call test_alloc_fail(GetAllocId('newwin_wvars'), 0, 0)
1758 call assert_fails('split', 'E342:')
1759 call assert_equal(1, winnr('$'))
1760
Bram Moolenaarb18b4962022-09-02 21:55:50 +01001761 edit Xwaffile1
1762 edit Xwaffile2
Yegappan Lakshmanan72bb47e2022-04-03 11:22:38 +01001763 call test_alloc_fail(GetAllocId('newwin_wvars'), 0, 0)
Bram Moolenaarb18b4962022-09-02 21:55:50 +01001764 call assert_fails('sb Xwaffile1', 'E342:')
Yegappan Lakshmanan72bb47e2022-04-03 11:22:38 +01001765 call assert_equal(1, winnr('$'))
Bram Moolenaarb18b4962022-09-02 21:55:50 +01001766 call assert_equal('Xwaffile2', @%)
Yegappan Lakshmanan72bb47e2022-04-03 11:22:38 +01001767 %bw!
1768
1769 " FIXME: The following test crashes Vim
1770 " test for new tabpage creation failure
1771 " call test_alloc_fail(GetAllocId('newwin_wvars'), 0, 0)
1772 " call assert_fails('tabnew', 'E342:')
1773 " call assert_equal(1, tabpagenr('$'))
1774 " call assert_equal(1, winnr('$'))
1775
1776 " This test messes up the internal Vim window/frame information. So the
1777 " Test_window_cmd_cmdwin_with_vsp() test fails after running this test.
1778 " Open a new tab and close everything else to fix this issue.
1779 tabnew
1780 tabonly
1781endfunc
Bram Moolenaard0fb9072021-12-09 11:57:22 +00001782
Luuk van Baalfd7e60a2022-09-07 14:42:49 +01001783func Test_win_equal_last_status()
1784 let save_lines = &lines
1785 set lines=20
1786 set splitbelow
1787 set laststatus=0
1788
1789 split | split | quit
1790 call assert_equal(winheight(1), winheight(2))
1791
1792 let &lines = save_lines
1793 set splitbelow&
1794 set laststatus&
1795endfunc
1796
Luuk van Baal13ece2a2022-10-03 15:28:08 +01001797" Test "screen" and "cursor" values for 'splitkeep' with a sequence of
Luuk van Baalfaf1d412022-09-19 16:45:29 +01001798" split operations for various options: with and without a winbar,
1799" tabline, for each possible value of 'laststatus', 'scrolloff',
Luuk van Baal13ece2a2022-10-03 15:28:08 +01001800" 'equalalways', and with the cursor at the top, middle and bottom.
1801func Test_splitkeep_options()
Luuk van Baal594f9e02022-09-16 12:52:58 +01001802 " disallow window resizing
1803 let save_WS = &t_WS
1804 set t_WS=
1805
Luuk van Baal29ab5242022-09-11 16:59:53 +01001806 let gui = has("gui_running")
Luuk van Baal594f9e02022-09-16 12:52:58 +01001807 inoremap <expr> c "<cmd>copen<bar>wincmd k<CR>"
Luuk van Baal13ece2a2022-10-03 15:28:08 +01001808 for run in range(0, 20)
1809 let &splitkeep = run > 10 ? 'topline' : 'screen'
1810 let &scrolloff = (!(run % 4) ? 0 : run)
1811 let &laststatus = (run % 3)
1812 let &splitbelow = (run % 3)
1813 let &equalalways = (run % 2)
1814 let wsb = (run % 2) && &splitbelow
1815 let tl = (gui ? 0 : ((run % 5) ? 1 : 0))
1816 let pos = !(run % 3) ? 'H' : ((run % 2) ? 'M' : 'L')
1817 tabnew | tabonly! | redraw
Luuk van Baal594f9e02022-09-16 12:52:58 +01001818 execute (run % 5) ? 'tabnew' : ''
1819 execute (run % 2) ? 'nnoremenu 1.10 WinBar.Test :echo' : ''
Luuk van Baal594f9e02022-09-16 12:52:58 +01001820 call setline(1, range(1, 256))
1821 " No scroll for restore_snapshot
1822 norm G
1823 try
1824 copen | close | colder
1825 catch /E380/
1826 endtry
1827 call assert_equal(257 - winheight(0), line("w0"))
Luuk van Baal29ab5242022-09-11 16:59:53 +01001828
Luuk van Baal594f9e02022-09-16 12:52:58 +01001829 " No scroll for firstwin horizontal split
1830 execute 'norm gg' . pos
1831 split | redraw | wincmd k
1832 call assert_equal(1, line("w0"))
1833 call assert_equal(&scroll, winheight(0) / 2)
1834 wincmd j
Luuk van Baal13ece2a2022-10-03 15:28:08 +01001835 call assert_equal(&spk == 'topline' ? 1 : win_screenpos(0)[0] - tl - wsb, line("w0"))
Luuk van Baal29ab5242022-09-11 16:59:53 +01001836
Luuk van Baal594f9e02022-09-16 12:52:58 +01001837 " No scroll when resizing windows
Luuk van Baal13ece2a2022-10-03 15:28:08 +01001838 wincmd k | resize +2 | redraw
Luuk van Baal594f9e02022-09-16 12:52:58 +01001839 call assert_equal(1, line("w0"))
1840 wincmd j
Luuk van Baal13ece2a2022-10-03 15:28:08 +01001841 call assert_equal(&spk == 'topline' ? 1 : win_screenpos(0)[0] - tl - wsb, line("w0"))
Luuk van Baal29ab5242022-09-11 16:59:53 +01001842
Luuk van Baal594f9e02022-09-16 12:52:58 +01001843 " No scroll when dragging statusline
1844 call win_move_statusline(1, -3)
Luuk van Baal13ece2a2022-10-03 15:28:08 +01001845 call assert_equal(&spk == 'topline' ? 1 : win_screenpos(0)[0] - tl - wsb, line("w0"))
Luuk van Baal594f9e02022-09-16 12:52:58 +01001846 wincmd k
1847 call assert_equal(1, line("w0"))
Luuk van Baal29ab5242022-09-11 16:59:53 +01001848
Luuk van Baal594f9e02022-09-16 12:52:58 +01001849 " No scroll when changing shellsize
1850 set lines+=2
1851 call assert_equal(1, line("w0"))
1852 wincmd j
Luuk van Baal13ece2a2022-10-03 15:28:08 +01001853 call assert_equal(&spk == 'topline' ? 1 : win_screenpos(0)[0] - tl - wsb, line("w0"))
Luuk van Baal594f9e02022-09-16 12:52:58 +01001854 set lines-=2
Luuk van Baal13ece2a2022-10-03 15:28:08 +01001855 call assert_equal(&spk == 'topline' ? 1 : win_screenpos(0)[0] - tl - wsb, line("w0"))
Luuk van Baal594f9e02022-09-16 12:52:58 +01001856 wincmd k
1857 call assert_equal(1, line("w0"))
Luuk van Baal29ab5242022-09-11 16:59:53 +01001858
Luuk van Baal594f9e02022-09-16 12:52:58 +01001859 " No scroll when equalizing windows
1860 wincmd =
1861 call assert_equal(1, line("w0"))
1862 wincmd j
Luuk van Baal13ece2a2022-10-03 15:28:08 +01001863 call assert_equal(&spk == 'topline' ? 1 : win_screenpos(0)[0] - tl - wsb, line("w0"))
Luuk van Baal594f9e02022-09-16 12:52:58 +01001864 wincmd k
1865 call assert_equal(1, line("w0"))
Luuk van Baal29ab5242022-09-11 16:59:53 +01001866
Luuk van Baal594f9e02022-09-16 12:52:58 +01001867 " No scroll in windows split multiple times
1868 vsplit | split | 4wincmd w
Luuk van Baal13ece2a2022-10-03 15:28:08 +01001869 call assert_equal(&spk == 'topline' ? 1 : win_screenpos(0)[0] - tl - wsb, line("w0"))
Luuk van Baal594f9e02022-09-16 12:52:58 +01001870 1wincmd w | quit | wincmd l | split
Luuk van Baal13ece2a2022-10-03 15:28:08 +01001871 call assert_equal(&spk == 'topline' ? 1 : win_screenpos(0)[0] - tl - wsb, line("w0"))
Luuk van Baal594f9e02022-09-16 12:52:58 +01001872 wincmd j
Luuk van Baal13ece2a2022-10-03 15:28:08 +01001873 call assert_equal(&spk == 'topline' ? 1 : win_screenpos(0)[0] - tl - wsb, line("w0"))
Luuk van Baal29ab5242022-09-11 16:59:53 +01001874
Luuk van Baal594f9e02022-09-16 12:52:58 +01001875 " No scroll in small window
1876 2wincmd w | only | 5split | wincmd k
1877 call assert_equal(1, line("w0"))
1878 wincmd j
Luuk van Baal13ece2a2022-10-03 15:28:08 +01001879 call assert_equal(&spk == 'topline' ? 1 : win_screenpos(0)[0] - tl - wsb, line("w0"))
Luuk van Baal29ab5242022-09-11 16:59:53 +01001880
Luuk van Baal594f9e02022-09-16 12:52:58 +01001881 " No scroll for vertical split
1882 quit | vsplit | wincmd l
1883 call assert_equal(1, line("w0"))
1884 wincmd h
1885 call assert_equal(1, line("w0"))
Luuk van Baal29ab5242022-09-11 16:59:53 +01001886
Luuk van Baal594f9e02022-09-16 12:52:58 +01001887 " No scroll in windows split and quit multiple times
Luuk van Baal13ece2a2022-10-03 15:28:08 +01001888 quit | redraw | split | split | quit | redraw
1889 call assert_equal(&spk == 'topline' ? 1 : win_screenpos(0)[0] - tl - wsb, line("w0"))
Luuk van Baal29ab5242022-09-11 16:59:53 +01001890
Luuk van Baal594f9e02022-09-16 12:52:58 +01001891 " No scroll for new buffer
1892 1wincmd w | only | copen | wincmd k
1893 call assert_equal(1, line("w0"))
1894 only
1895 call assert_equal(1, line("w0"))
1896 above copen | wincmd j
Luuk van Baal13ece2a2022-10-03 15:28:08 +01001897 call assert_equal(&spk == 'topline' ? 1 : win_screenpos(0)[0] - tl, line("w0"))
Luuk van Baal29ab5242022-09-11 16:59:53 +01001898
Luuk van Baal594f9e02022-09-16 12:52:58 +01001899 " No scroll when opening cmdwin, and no cursor move when closing cmdwin.
1900 only | norm ggL
1901 let curpos = getcurpos()
1902 norm q:
1903 call assert_equal(1, line("w0"))
1904 call assert_equal(curpos, getcurpos())
Luuk van Baal29ab5242022-09-11 16:59:53 +01001905
Bram Moolenaarfdbd14e2023-02-14 21:56:42 +00001906 " Scroll when cursor becomes invalid in insert mode.
Luuk van Baal594f9e02022-09-16 12:52:58 +01001907 norm Lic
Luuk van Baalbc3dc292023-02-15 16:45:27 +00001908 call assert_equal(curpos, getcurpos(), 'run ' .. run)
Luuk van Baal29ab5242022-09-11 16:59:53 +01001909
Luuk van Baal594f9e02022-09-16 12:52:58 +01001910 " No scroll when topline not equal to 1
1911 only | execute "norm gg5\<C-e>" | split | wincmd k
1912 call assert_equal(6, line("w0"))
1913 wincmd j
Luuk van Baal13ece2a2022-10-03 15:28:08 +01001914 call assert_equal(&spk == 'topline' ? 6 : 5 + win_screenpos(0)[0] - tl - wsb, line("w0"))
Luuk van Baal29ab5242022-09-11 16:59:53 +01001915 endfor
1916
1917 tabnew | tabonly! | %bwipeout!
1918 iunmap c
Luuk van Baal29ab5242022-09-11 16:59:53 +01001919 set scrolloff&
1920 set splitbelow&
1921 set laststatus&
1922 set equalalways&
Luuk van Baal13ece2a2022-10-03 15:28:08 +01001923 set splitkeep&
Luuk van Baal594f9e02022-09-16 12:52:58 +01001924 let &t_WS = save_WS
Luuk van Baal29ab5242022-09-11 16:59:53 +01001925endfunc
Luuk van Baalfd7e60a2022-09-07 14:42:49 +01001926
Bram Moolenaare0f86912023-03-01 17:55:31 +00001927func Test_splitkeep_cmdwin_cursor_position()
Luuk van Baal13ece2a2022-10-03 15:28:08 +01001928 set splitkeep=screen
mityu12167d82022-09-15 17:44:07 +01001929 call setline(1, range(&lines))
1930
1931 " No scroll when cursor is at near bottom of window and cusor position
1932 " recompution (done by line('w0') in this test) happens while in cmdwin.
1933 normal! G
1934 let firstline = line('w0')
1935 autocmd CmdwinEnter * ++once autocmd WinEnter * ++once call line('w0')
1936 execute "normal! q:\<C-w>q"
1937 redraw!
1938 call assert_equal(firstline, line('w0'))
1939
1940 " User script can change cursor position successfully while in cmdwin and it
1941 " shouldn't be changed when closing cmdwin.
1942 execute "normal! Gq:\<Cmd>call win_execute(winnr('#')->win_getid(), 'call cursor(1, 1)')\<CR>\<C-w>q"
1943 call assert_equal(1, line('.'))
1944 call assert_equal(1, col('.'))
1945
1946 execute "normal! Gq:\<Cmd>autocmd WinEnter * ++once call cursor(1, 1)\<CR>\<C-w>q"
1947 call assert_equal(1, line('.'))
1948 call assert_equal(1, col('.'))
1949
1950 %bwipeout!
Luuk van Baal13ece2a2022-10-03 15:28:08 +01001951 set splitkeep&
Bram Moolenaare0f86912023-03-01 17:55:31 +00001952endfunc
Luuk van Baald5bc7622022-09-17 16:16:35 +01001953
Bram Moolenaare0f86912023-03-01 17:55:31 +00001954func Test_splitkeep_misc()
Luuk van Baal13ece2a2022-10-03 15:28:08 +01001955 set splitkeep=screen
Luuk van Baald5bc7622022-09-17 16:16:35 +01001956
1957 call setline(1, range(1, &lines))
Luuk van Baala109f392023-06-02 14:16:35 +01001958 " Cursor is adjusted to start and end of buffer
1959 norm M
1960 wincmd s
1961 resize 1
1962 call assert_equal(1, line('.'))
1963 wincmd j
1964 norm GM
1965 resize 1
1966 call assert_equal(&lines, line('.'))
1967 only!
1968
1969 set splitbelow
Luuk van Baald5bc7622022-09-17 16:16:35 +01001970 norm Gzz
1971 let top = line('w0')
Luuk van Baalfaf1d412022-09-19 16:45:29 +01001972 " No scroll when aucmd_win is opened
Luuk van Baald5bc7622022-09-17 16:16:35 +01001973 call setbufvar(bufnr("test", 1) , '&buftype', 'nofile')
1974 call assert_equal(top, line('w0'))
Luuk van Baalfaf1d412022-09-19 16:45:29 +01001975 " No scroll when tab is changed/closed
1976 tab help | close
1977 call assert_equal(top, line('w0'))
1978 " No scroll when help is closed and buffer line count < window height
1979 norm ggdG
1980 call setline(1, range(1, &lines - 10))
Luuk van Baald5bc7622022-09-17 16:16:35 +01001981 norm G
1982 let top = line('w0')
1983 help | quit
1984 call assert_equal(top, line('w0'))
Luuk van Baal346823d2022-10-05 18:26:42 +01001985 " No error when resizing window in autocmd and buffer length changed
1986 autocmd FileType qf exe "resize" line('$')
1987 cexpr getline(1, '$')
1988 copen
1989 wincmd p
1990 norm dd
1991 cexpr getline(1, '$')
Luuk van Baald5bc7622022-09-17 16:16:35 +01001992
Luuk van Baalfaf1d412022-09-19 16:45:29 +01001993 %bwipeout!
Luuk van Baald5bc7622022-09-17 16:16:35 +01001994 set splitbelow&
Luuk van Baal13ece2a2022-10-03 15:28:08 +01001995 set splitkeep&
Luuk van Baald5bc7622022-09-17 16:16:35 +01001996endfunc
1997
Luuk van Baal16af9132023-08-20 20:44:59 +02001998func Test_splitkeep_cursor()
1999 CheckScreendump
2000 let lines =<< trim END
2001 set splitkeep=screen
2002 autocmd CursorMoved * wincmd p | wincmd p
2003 call setline(1, range(1, 200))
2004 func CursorEqualize()
2005 call cursor(100, 1)
2006 wincmd =
2007 endfunc
2008 wincmd s
2009 call CursorEqualize()
2010 END
2011 call writefile(lines, 'XTestSplitkeepCallback', 'D')
2012 let buf = RunVimInTerminal('-S XTestSplitkeepCallback', #{rows: 8})
2013
2014 call VerifyScreenDump(buf, 'Test_splitkeep_cursor_1', {})
2015
2016 call term_sendkeys(buf, "j")
2017 call VerifyScreenDump(buf, 'Test_splitkeep_cursor_2', {})
2018
2019 call term_sendkeys(buf, ":set scrolloff=0\<CR>G")
2020 call VerifyScreenDump(buf, 'Test_splitkeep_cursor_3', {})
2021
2022 call StopVimInTerminal(buf)
2023endfunc
2024
Bram Moolenaare0f86912023-03-01 17:55:31 +00002025func Test_splitkeep_callback()
Luuk van Baal20e58562022-09-23 12:57:09 +01002026 CheckScreendump
2027 let lines =<< trim END
Luuk van Baal13ece2a2022-10-03 15:28:08 +01002028 set splitkeep=screen
Luuk van Baal20e58562022-09-23 12:57:09 +01002029 call setline(1, range(&lines))
Luuk van Baal13ece2a2022-10-03 15:28:08 +01002030 function C1(a, b)
Luuk van Baal20e58562022-09-23 12:57:09 +01002031 split | wincmd p
2032 endfunction
Luuk van Baal13ece2a2022-10-03 15:28:08 +01002033 function C2(a, b)
Luuk van Baal20e58562022-09-23 12:57:09 +01002034 close | split
2035 endfunction
Luuk van Baal13ece2a2022-10-03 15:28:08 +01002036 nn j <cmd>call job_start([&sh, &shcf, "true"], { 'exit_cb': 'C1' })<CR>
2037 nn t <cmd>call popup_create(term_start([&sh, &shcf, "true"],
2038 \ { 'hidden': 1, 'exit_cb': 'C2' }), {})<CR>
Luuk van Baal20e58562022-09-23 12:57:09 +01002039 END
Luuk van Baal13ece2a2022-10-03 15:28:08 +01002040 call writefile(lines, 'XTestSplitkeepCallback', 'D')
2041 let buf = RunVimInTerminal('-S XTestSplitkeepCallback', #{rows: 8})
Luuk van Baal20e58562022-09-23 12:57:09 +01002042
2043 call term_sendkeys(buf, "j")
Luuk van Baal13ece2a2022-10-03 15:28:08 +01002044 call VerifyScreenDump(buf, 'Test_splitkeep_callback_1', {})
Luuk van Baal20e58562022-09-23 12:57:09 +01002045
Luuk van Baal13ece2a2022-10-03 15:28:08 +01002046 call term_sendkeys(buf, ":quit\<CR>Ht")
2047 call VerifyScreenDump(buf, 'Test_splitkeep_callback_2', {})
Luuk van Baal20e58562022-09-23 12:57:09 +01002048
2049 call term_sendkeys(buf, ":set sb\<CR>:quit\<CR>Gj")
Luuk van Baal13ece2a2022-10-03 15:28:08 +01002050 call VerifyScreenDump(buf, 'Test_splitkeep_callback_3', {})
Luuk van Baal20e58562022-09-23 12:57:09 +01002051
Luuk van Baal13ece2a2022-10-03 15:28:08 +01002052 call term_sendkeys(buf, ":quit\<CR>Gt")
2053 call VerifyScreenDump(buf, 'Test_splitkeep_callback_4', {})
zeertzjq378e6c02023-01-14 11:46:49 +00002054
2055 call StopVimInTerminal(buf)
Luuk van Baal20e58562022-09-23 12:57:09 +01002056endfunc
2057
Bram Moolenaare0f86912023-03-01 17:55:31 +00002058func Test_splitkeep_fold()
Luuk van Baal13ece2a2022-10-03 15:28:08 +01002059 CheckScreendump
Luuk van Baal7c1cbb62022-09-27 12:31:15 +01002060
Luuk van Baal13ece2a2022-10-03 15:28:08 +01002061 let lines =<< trim END
2062 set splitkeep=screen
2063 set foldmethod=marker
2064 set number
2065 let line = 1
2066 for n in range(1, &lines)
2067 call setline(line, ['int FuncName() {/*{{{*/', 1, 2, 3, 4, 5, '}/*}}}*/',
2068 \ 'after fold'])
2069 let line += 8
2070 endfor
2071 END
2072 call writefile(lines, 'XTestSplitkeepFold', 'D')
2073 let buf = RunVimInTerminal('-S XTestSplitkeepFold', #{rows: 10})
Luuk van Baal7c1cbb62022-09-27 12:31:15 +01002074
2075 call term_sendkeys(buf, "L:wincmd s\<CR>")
Luuk van Baal13ece2a2022-10-03 15:28:08 +01002076 call VerifyScreenDump(buf, 'Test_splitkeep_fold_1', {})
Luuk van Baal7c1cbb62022-09-27 12:31:15 +01002077
2078 call term_sendkeys(buf, ":quit\<CR>")
Luuk van Baal13ece2a2022-10-03 15:28:08 +01002079 call VerifyScreenDump(buf, 'Test_splitkeep_fold_2', {})
Luuk van Baal7c1cbb62022-09-27 12:31:15 +01002080
2081 call term_sendkeys(buf, "H:below split\<CR>")
Luuk van Baal13ece2a2022-10-03 15:28:08 +01002082 call VerifyScreenDump(buf, 'Test_splitkeep_fold_3', {})
Luuk van Baal7c1cbb62022-09-27 12:31:15 +01002083
2084 call term_sendkeys(buf, ":wincmd k\<CR>:quit\<CR>")
Luuk van Baal13ece2a2022-10-03 15:28:08 +01002085 call VerifyScreenDump(buf, 'Test_splitkeep_fold_4', {})
zeertzjq378e6c02023-01-14 11:46:49 +00002086
2087 call StopVimInTerminal(buf)
Bram Moolenaare0f86912023-03-01 17:55:31 +00002088endfunc
Luuk van Baal7c1cbb62022-09-27 12:31:15 +01002089
Bram Moolenaare0f86912023-03-01 17:55:31 +00002090func Test_splitkeep_status()
Luuk van Baal74a694d2022-11-28 16:49:36 +00002091 CheckScreendump
2092
2093 let lines =<< trim END
2094 call setline(1, ['a', 'b', 'c'])
2095 set nomodified
2096 set splitkeep=screen
2097 let win = winnr()
2098 wincmd s
2099 wincmd j
2100 END
2101 call writefile(lines, 'XTestSplitkeepStatus', 'D')
2102 let buf = RunVimInTerminal('-S XTestSplitkeepStatus', #{rows: 10})
2103
2104 call term_sendkeys(buf, ":call win_move_statusline(win, 1)\<CR>")
2105 call VerifyScreenDump(buf, 'Test_splitkeep_status_1', {})
zeertzjq378e6c02023-01-14 11:46:49 +00002106
2107 call StopVimInTerminal(buf)
Bram Moolenaare0f86912023-03-01 17:55:31 +00002108endfunc
Luuk van Baal74a694d2022-11-28 16:49:36 +00002109
Luuk van Baalb926bf42023-05-06 12:53:50 +01002110" skipcol is not reset unnecessarily and is copied to new window
2111func Test_splitkeep_skipcol()
2112 CheckScreendump
2113
2114 let lines =<< trim END
2115 set splitkeep=topline smoothscroll splitbelow scrolloff=0
2116 call setline(1, 'with lots of text in one line '->repeat(6))
2117 norm 2
2118 wincmd s
2119 END
2120
2121 call writefile(lines, 'XTestSplitkeepSkipcol', 'D')
2122 let buf = RunVimInTerminal('-S XTestSplitkeepSkipcol', #{rows: 12, cols: 40})
2123
2124 call VerifyScreenDump(buf, 'Test_splitkeep_skipcol_1', {})
2125endfunc
2126
Bram Moolenaare0f86912023-03-01 17:55:31 +00002127func Test_new_help_window_on_error()
Rob Pillingcb94c912022-12-13 12:26:09 +00002128 help change.txt
2129 execute "normal! /CTRL-@\<CR>"
2130 silent! execute "normal! \<C-W>]"
2131
2132 let wincount = winnr('$')
2133 help 'mod'
2134
2135 call assert_equal(wincount, winnr('$'))
2136 call assert_equal(expand("<cword>"), "'mod'")
Bram Moolenaare0f86912023-03-01 17:55:31 +00002137endfunc
2138
2139func Test_smoothscroll_in_zero_width_window()
Sean Dewar0fd44a52024-02-20 20:28:15 +01002140 set cpo+=n number smoothscroll
2141 set winwidth=99999 winminwidth=0
Bram Moolenaare0f86912023-03-01 17:55:31 +00002142
Sean Dewar0fd44a52024-02-20 20:28:15 +01002143 vsplit
2144 call assert_equal(0, winwidth(winnr('#')))
2145 call win_execute(win_getid(winnr('#')), "norm! \<C-Y>")
Bram Moolenaare0f86912023-03-01 17:55:31 +00002146
2147 only!
Sean Dewar0fd44a52024-02-20 20:28:15 +01002148 set winwidth& winminwidth&
2149 set cpo-=n nonumber nosmoothscroll
Bram Moolenaare0f86912023-03-01 17:55:31 +00002150endfunc
Rob Pillingcb94c912022-12-13 12:26:09 +00002151
Sean Dewar0fd44a52024-02-20 20:28:15 +01002152func Test_splitmove_flatten_frame()
2153 split
2154 vsplit
2155
2156 wincmd L
2157 let layout = winlayout()
2158 wincmd K
2159 wincmd L
2160 call assert_equal(winlayout(), layout)
2161
2162 only!
2163endfunc
2164
2165func Test_splitmove_autocmd_window_no_room()
2166 " Open as many windows as possible
2167 while v:true
2168 try
2169 split
2170 catch /E36:/
2171 break
2172 endtry
2173 endwhile
2174 while v:true
2175 try
2176 vsplit
2177 catch /E36:/
2178 break
2179 endtry
2180 endwhile
2181
2182 wincmd j
2183 vsplit
2184 call assert_fails('wincmd H', 'E36:')
2185 call assert_fails('wincmd J', 'E36:')
2186 call assert_fails('wincmd K', 'E36:')
2187 call assert_fails('wincmd L', 'E36:')
2188
2189 edit unload me
2190 enew
2191 bunload! unload\ me
2192 augroup SplitMoveAucmdWin
2193 au!
2194 au BufEnter * ++once let s:triggered = v:true
2195 \| call assert_equal('autocmd', win_gettype())
2196 augroup END
2197 let layout = winlayout()
2198 let restcmd = winrestcmd()
2199 " bufload opening the autocommand window shouldn't give E36.
2200 call bufload('unload me')
2201 call assert_equal(v:true, s:triggered)
2202 call assert_equal(winlayout(), layout)
2203 call assert_equal(winrestcmd(), restcmd)
2204
2205 unlet! s:triggered
2206 au! SplitMoveAucmdWin
2207 augroup! SplitMoveAucmdWin
2208 %bw!
2209endfunc
Rob Pillingcb94c912022-12-13 12:26:09 +00002210
Bram Moolenaar9e4d8212016-08-18 23:04:48 +02002211" vim: shiftwidth=2 sts=2 expandtab