blob: 5506dbebf2285624be4af20871519abfa0f74ae4 [file] [log] [blame]
Bram Moolenaar991dea32016-05-24 11:31:32 +02001" Tests for window cmd (:wincmd, :split, :vsplit, :resize and etc...)
2
Bram Moolenaara27e1dc2019-10-07 22:27:36 +02003so check.vim
4
Bram Moolenaar991dea32016-05-24 11:31:32 +02005func Test_window_cmd_ls0_with_split()
6 set ls=0
7 set splitbelow
8 split
9 quit
10 call assert_equal(0, &lines - &cmdheight - winheight(0))
11 new | only!
12 "
13 set splitbelow&vim
14 botright split
15 quit
16 call assert_equal(0, &lines - &cmdheight - winheight(0))
17 new | only!
18 set ls&vim
19endfunc
20
21func Test_window_cmd_cmdwin_with_vsp()
Bram Moolenaar72cf47a2018-05-10 18:23:29 +020022 let efmt = 'Expected 0 but got %d (in ls=%d, %s window)'
Bram Moolenaar991dea32016-05-24 11:31:32 +020023 for v in range(0, 2)
24 exec "set ls=" . v
25 vsplit
26 call feedkeys("q:\<CR>")
27 let ac = &lines - (&cmdheight + winheight(0) + !!v)
28 let emsg = printf(efmt, ac, v, 'left')
29 call assert_equal(0, ac, emsg)
30 wincmd w
31 let ac = &lines - (&cmdheight + winheight(0) + !!v)
32 let emsg = printf(efmt, ac, v, 'right')
33 call assert_equal(0, ac, emsg)
34 new | only!
35 endfor
36 set ls&vim
37endfunc
38
Bram Moolenaar5d3c9f82020-06-26 20:41:39 +020039" Test for jumping to windows
40func Test_window_jump()
41 new
42 " jumping to a window with a count greater than the max windows
43 exe "normal 4\<C-W>w"
44 call assert_equal(2, winnr())
45 only
46endfunc
47
48func Test_window_cmd_wincmd_gf()
Bram Moolenaar5d2ca042016-06-26 17:11:21 +020049 let fname = 'test_gf.txt'
50 let swp_fname = '.' . fname . '.swp'
51 call writefile([], fname)
52 call writefile([], swp_fname)
53 function s:swap_exists()
54 let v:swapchoice = s:swap_choice
55 endfunc
Bram Moolenaareaa49e42019-07-13 18:08:59 +020056 " Remove the catch-all that runtest.vim adds
57 au! SwapExists
Bram Moolenaar5d2ca042016-06-26 17:11:21 +020058 augroup test_window_cmd_wincmd_gf
59 autocmd!
60 exec "autocmd SwapExists " . fname . " call s:swap_exists()"
61 augroup END
62
63 call setline(1, fname)
64 " (E)dit anyway
65 let s:swap_choice = 'e'
66 wincmd gf
67 call assert_equal(2, tabpagenr())
68 call assert_equal(fname, bufname("%"))
69 quit!
70
71 " (Q)uit
72 let s:swap_choice = 'q'
73 wincmd gf
74 call assert_equal(1, tabpagenr())
75 call assert_notequal(fname, bufname("%"))
76 new | only!
77
78 call delete(fname)
79 call delete(swp_fname)
80 augroup! test_window_cmd_wincmd_gf
81endfunc
82
Bram Moolenaar4520d442017-03-19 16:09:46 +010083func Test_window_quit()
84 e Xa
85 split Xb
Bram Moolenaarf92e58c2019-09-08 21:51:41 +020086 call assert_equal(2, '$'->winnr())
Bram Moolenaar4520d442017-03-19 16:09:46 +010087 call assert_equal('Xb', bufname(winbufnr(1)))
88 call assert_equal('Xa', bufname(winbufnr(2)))
89
90 wincmd q
91 call assert_equal(1, winnr('$'))
92 call assert_equal('Xa', bufname(winbufnr(1)))
93
94 bw Xa Xb
95endfunc
96
97func Test_window_horizontal_split()
98 call assert_equal(1, winnr('$'))
99 3wincmd s
100 call assert_equal(2, winnr('$'))
101 call assert_equal(3, winheight(0))
Bram Moolenaarf92e58c2019-09-08 21:51:41 +0200102 call assert_equal(winwidth(1), 2->winwidth())
Bram Moolenaar4520d442017-03-19 16:09:46 +0100103
104 call assert_fails('botright topleft wincmd s', 'E442:')
105 bw
106endfunc
107
108func Test_window_vertical_split()
109 call assert_equal(1, winnr('$'))
110 3wincmd v
111 call assert_equal(2, winnr('$'))
112 call assert_equal(3, winwidth(0))
113 call assert_equal(winheight(1), winheight(2))
114
115 call assert_fails('botright topleft wincmd v', 'E442:')
116 bw
117endfunc
118
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100119" Test the ":wincmd ^" and "<C-W>^" commands.
Bram Moolenaar4520d442017-03-19 16:09:46 +0100120func Test_window_split_edit_alternate()
Bram Moolenaar4520d442017-03-19 16:09:46 +0100121
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100122 " Test for failure when the alternate buffer/file no longer exists.
123 edit Xfoo | %bw
124 call assert_fails(':wincmd ^', 'E23')
125
126 " Test for the expected behavior when we have two named buffers.
127 edit Xfoo | edit Xbar
Bram Moolenaar4520d442017-03-19 16:09:46 +0100128 wincmd ^
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100129 call assert_equal('Xfoo', bufname(winbufnr(1)))
130 call assert_equal('Xbar', bufname(winbufnr(2)))
131 only
Bram Moolenaar4520d442017-03-19 16:09:46 +0100132
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100133 " Test for the expected behavior when the alternate buffer is not named.
134 enew | let l:nr1 = bufnr('%')
135 edit Xfoo | let l:nr2 = bufnr('%')
136 wincmd ^
137 call assert_equal(l:nr1, winbufnr(1))
138 call assert_equal(l:nr2, winbufnr(2))
139 only
140
Bram Moolenaard42333d2018-11-10 20:28:19 +0100141 " FIXME: this currently fails on AppVeyor, but passes locally
142 if !has('win32')
143 " Test the Normal mode command.
144 call feedkeys("\<C-W>\<C-^>", 'tx')
145 call assert_equal(l:nr2, winbufnr(1))
146 call assert_equal(l:nr1, winbufnr(2))
147 endif
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100148
149 %bw!
150endfunc
151
152" Test the ":[count]wincmd ^" and "[count]<C-W>^" commands.
153func Test_window_split_edit_bufnr()
154
155 %bwipeout
156 let l:nr = bufnr('%') + 1
157 call assert_fails(':execute "normal! ' . l:nr . '\<C-W>\<C-^>"', 'E92')
158 call assert_fails(':' . l:nr . 'wincmd ^', 'E16')
159 call assert_fails(':0wincmd ^', 'E16')
160
161 edit Xfoo | edit Xbar | edit Xbaz
162 let l:foo_nr = bufnr('Xfoo')
163 let l:bar_nr = bufnr('Xbar')
164 let l:baz_nr = bufnr('Xbaz')
165
Bram Moolenaar8617b402018-11-10 20:47:48 +0100166 " FIXME: this currently fails on AppVeyor, but passes locally
167 if !has('win32')
168 call feedkeys(l:foo_nr . "\<C-W>\<C-^>", 'tx')
169 call assert_equal('Xfoo', bufname(winbufnr(1)))
170 call assert_equal('Xbaz', bufname(winbufnr(2)))
171 only
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100172
Bram Moolenaar8617b402018-11-10 20:47:48 +0100173 call feedkeys(l:bar_nr . "\<C-W>\<C-^>", 'tx')
174 call assert_equal('Xbar', bufname(winbufnr(1)))
175 call assert_equal('Xfoo', bufname(winbufnr(2)))
176 only
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100177
Bram Moolenaar8617b402018-11-10 20:47:48 +0100178 execute l:baz_nr . 'wincmd ^'
179 call assert_equal('Xbaz', bufname(winbufnr(1)))
180 call assert_equal('Xbar', bufname(winbufnr(2)))
181 endif
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100182
183 %bw!
Bram Moolenaar4520d442017-03-19 16:09:46 +0100184endfunc
185
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100186func Test_window_split_no_room()
187 " N horizontal windows need >= 2*N + 1 lines:
188 " - 1 line + 1 status line in each window
189 " - 1 Ex command line
190 "
191 " 2*N + 1 <= &lines
192 " N <= (lines - 1)/2
193 "
194 " Beyond that number of windows, E36: Not enough room is expected.
195 let hor_win_count = (&lines - 1)/2
196 let hor_split_count = hor_win_count - 1
197 for s in range(1, hor_split_count) | split | endfor
198 call assert_fails('split', 'E36:')
199
200 " N vertical windows need >= 2*(N - 1) + 1 columns:
201 " - 1 column + 1 separator for each window (except last window)
202 " - 1 column for the last window which does not have separator
203 "
204 " 2*(N - 1) + 1 <= &columns
205 " 2*N - 1 <= &columns
206 " N <= (&columns + 1)/2
207 let ver_win_count = (&columns + 1)/2
208 let ver_split_count = ver_win_count - 1
209 for s in range(1, ver_split_count) | vsplit | endfor
210 call assert_fails('vsplit', 'E36:')
211
212 %bw!
213endfunc
214
Bram Moolenaar4520d442017-03-19 16:09:46 +0100215func Test_window_exchange()
216 e Xa
217
218 " Nothing happens with window exchange when there is 1 window
219 wincmd x
220 call assert_equal(1, winnr('$'))
221
222 split Xb
223 split Xc
224
225 call assert_equal('Xc', bufname(winbufnr(1)))
226 call assert_equal('Xb', bufname(winbufnr(2)))
227 call assert_equal('Xa', bufname(winbufnr(3)))
228
229 " Exchange current window 1 with window 3
230 3wincmd x
231 call assert_equal('Xa', bufname(winbufnr(1)))
232 call assert_equal('Xb', bufname(winbufnr(2)))
233 call assert_equal('Xc', bufname(winbufnr(3)))
234
235 " Exchange window with next when at the top window
236 wincmd x
237 call assert_equal('Xb', bufname(winbufnr(1)))
238 call assert_equal('Xa', bufname(winbufnr(2)))
239 call assert_equal('Xc', bufname(winbufnr(3)))
240
241 " Exchange window with next when at the middle window
242 wincmd j
243 wincmd x
244 call assert_equal('Xb', bufname(winbufnr(1)))
245 call assert_equal('Xc', bufname(winbufnr(2)))
246 call assert_equal('Xa', bufname(winbufnr(3)))
247
248 " Exchange window with next when at the bottom window.
249 " When there is no next window, it exchanges with the previous window.
250 wincmd j
251 wincmd x
252 call assert_equal('Xb', bufname(winbufnr(1)))
253 call assert_equal('Xa', bufname(winbufnr(2)))
254 call assert_equal('Xc', bufname(winbufnr(3)))
255
256 bw Xa Xb Xc
257endfunc
258
259func Test_window_rotate()
260 e Xa
261 split Xb
262 split Xc
263 call assert_equal('Xc', bufname(winbufnr(1)))
264 call assert_equal('Xb', bufname(winbufnr(2)))
265 call assert_equal('Xa', bufname(winbufnr(3)))
266
267 " Rotate downwards
268 wincmd r
269 call assert_equal('Xa', bufname(winbufnr(1)))
270 call assert_equal('Xc', bufname(winbufnr(2)))
271 call assert_equal('Xb', bufname(winbufnr(3)))
272
273 2wincmd r
274 call assert_equal('Xc', bufname(winbufnr(1)))
275 call assert_equal('Xb', bufname(winbufnr(2)))
276 call assert_equal('Xa', bufname(winbufnr(3)))
277
278 " Rotate upwards
279 wincmd R
280 call assert_equal('Xb', bufname(winbufnr(1)))
281 call assert_equal('Xa', bufname(winbufnr(2)))
282 call assert_equal('Xc', bufname(winbufnr(3)))
283
284 2wincmd R
285 call assert_equal('Xc', bufname(winbufnr(1)))
286 call assert_equal('Xb', bufname(winbufnr(2)))
287 call assert_equal('Xa', bufname(winbufnr(3)))
288
289 bot vsplit
290 call assert_fails('wincmd R', 'E443:')
291
292 bw Xa Xb Xc
293endfunc
294
295func Test_window_height()
296 e Xa
297 split Xb
298
299 let [wh1, wh2] = [winheight(1), winheight(2)]
300 " Active window (1) should have the same height or 1 more
301 " than the other window.
302 call assert_inrange(wh2, wh2 + 1, wh1)
303
304 wincmd -
305 call assert_equal(wh1 - 1, winheight(1))
306 call assert_equal(wh2 + 1, winheight(2))
307
308 wincmd +
309 call assert_equal(wh1, winheight(1))
Bram Moolenaarf92e58c2019-09-08 21:51:41 +0200310 call assert_equal(wh2, 2->winheight())
Bram Moolenaar4520d442017-03-19 16:09:46 +0100311
312 2wincmd _
313 call assert_equal(2, winheight(1))
314 call assert_equal(wh1 + wh2 - 2, winheight(2))
315
316 wincmd =
317 call assert_equal(wh1, winheight(1))
318 call assert_equal(wh2, winheight(2))
319
320 2wincmd _
321 set winfixheight
322 split Xc
323 let [wh1, wh2, wh3] = [winheight(1), winheight(2), winheight(3)]
324 call assert_equal(2, winheight(2))
325 call assert_inrange(wh3, wh3 + 1, wh1)
326 3wincmd +
327 call assert_equal(2, winheight(2))
328 call assert_equal(wh1 + 3, winheight(1))
329 call assert_equal(wh3 - 3, winheight(3))
330 wincmd =
331 call assert_equal(2, winheight(2))
332 call assert_equal(wh1, winheight(1))
333 call assert_equal(wh3, winheight(3))
334
335 wincmd j
336 set winfixheight&
337
338 wincmd =
339 let [wh1, wh2, wh3] = [winheight(1), winheight(2), winheight(3)]
340 " Current window (2) should have the same height or 1 more
341 " than the other windows.
342 call assert_inrange(wh1, wh1 + 1, wh2)
343 call assert_inrange(wh3, wh3 + 1, wh2)
344
345 bw Xa Xb Xc
346endfunc
347
348func Test_window_width()
349 e Xa
350 vsplit Xb
351
352 let [ww1, ww2] = [winwidth(1), winwidth(2)]
353 " Active window (1) should have the same width or 1 more
354 " than the other window.
355 call assert_inrange(ww2, ww2 + 1, ww1)
356
357 wincmd <
358 call assert_equal(ww1 - 1, winwidth(1))
359 call assert_equal(ww2 + 1, winwidth(2))
360
361 wincmd >
362 call assert_equal(ww1, winwidth(1))
363 call assert_equal(ww2, winwidth(2))
364
365 2wincmd |
366 call assert_equal(2, winwidth(1))
367 call assert_equal(ww1 + ww2 - 2, winwidth(2))
368
369 wincmd =
370 call assert_equal(ww1, winwidth(1))
371 call assert_equal(ww2, winwidth(2))
372
373 2wincmd |
374 set winfixwidth
375 vsplit Xc
376 let [ww1, ww2, ww3] = [winwidth(1), winwidth(2), winwidth(3)]
Bram Moolenaar38e34832017-03-19 20:22:36 +0100377 call assert_equal(2, winwidth(2))
Bram Moolenaar4520d442017-03-19 16:09:46 +0100378 call assert_inrange(ww3, ww3 + 1, ww1)
379 3wincmd >
Bram Moolenaar38e34832017-03-19 20:22:36 +0100380 call assert_equal(2, winwidth(2))
Bram Moolenaar4520d442017-03-19 16:09:46 +0100381 call assert_equal(ww1 + 3, winwidth(1))
382 call assert_equal(ww3 - 3, winwidth(3))
383 wincmd =
Bram Moolenaar38e34832017-03-19 20:22:36 +0100384 call assert_equal(2, winwidth(2))
Bram Moolenaar4520d442017-03-19 16:09:46 +0100385 call assert_equal(ww1, winwidth(1))
386 call assert_equal(ww3, winwidth(3))
387
388 wincmd l
389 set winfixwidth&
390
391 wincmd =
392 let [ww1, ww2, ww3] = [winwidth(1), winwidth(2), winwidth(3)]
393 " Current window (2) should have the same width or 1 more
394 " than the other windows.
395 call assert_inrange(ww1, ww1 + 1, ww2)
396 call assert_inrange(ww3, ww3 + 1, ww2)
397
398 bw Xa Xb Xc
399endfunc
400
Bram Moolenaar8eeeba82017-06-25 22:45:39 +0200401func Test_equalalways_on_close()
402 set equalalways
403 vsplit
404 windo split
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100405 split
Bram Moolenaar8eeeba82017-06-25 22:45:39 +0200406 wincmd J
407 " now we have a frame top-left with two windows, a frame top-right with two
408 " windows and a frame at the bottom, full-width.
409 let height_1 = winheight(1)
410 let height_2 = winheight(2)
411 let height_3 = winheight(3)
412 let height_4 = winheight(4)
413 " closing the bottom window causes all windows to be resized.
414 close
415 call assert_notequal(height_1, winheight(1))
416 call assert_notequal(height_2, winheight(2))
417 call assert_notequal(height_3, winheight(3))
418 call assert_notequal(height_4, winheight(4))
419 call assert_equal(winheight(1), winheight(3))
420 call assert_equal(winheight(2), winheight(4))
421
422 1wincmd w
423 split
424 4wincmd w
425 resize + 5
426 " left column has three windows, equalized heights.
427 " right column has two windows, top one a bit higher
428 let height_1 = winheight(1)
429 let height_2 = winheight(2)
430 let height_4 = winheight(4)
431 let height_5 = winheight(5)
432 3wincmd w
433 " closing window in left column equalizes heights in left column but not in
434 " the right column
435 close
436 call assert_notequal(height_1, winheight(1))
437 call assert_notequal(height_2, winheight(2))
438 call assert_equal(height_4, winheight(3))
439 call assert_equal(height_5, winheight(4))
440
441 only
442 set equalalways&
443endfunc
444
Bram Moolenaar22044dc2017-12-02 15:43:37 +0100445func Test_win_screenpos()
Bram Moolenaar5a4c3082019-12-01 15:23:11 +0100446 CheckFeature quickfix
447
Bram Moolenaar22044dc2017-12-02 15:43:37 +0100448 call assert_equal(1, winnr('$'))
449 split
450 vsplit
451 10wincmd _
452 30wincmd |
453 call assert_equal([1, 1], win_screenpos(1))
454 call assert_equal([1, 32], win_screenpos(2))
455 call assert_equal([12, 1], win_screenpos(3))
456 call assert_equal([0, 0], win_screenpos(4))
Bram Moolenaar99fa7212020-04-26 15:59:55 +0200457 call assert_fails('let l = win_screenpos([])', 'E745:')
Bram Moolenaar22044dc2017-12-02 15:43:37 +0100458 only
459endfunc
460
Bram Moolenaar4520d442017-03-19 16:09:46 +0100461func Test_window_jump_tag()
Bram Moolenaar5a4c3082019-12-01 15:23:11 +0100462 CheckFeature quickfix
463
Bram Moolenaar4520d442017-03-19 16:09:46 +0100464 help
465 /iccf
466 call assert_match('^|iccf|', getline('.'))
467 call assert_equal(2, winnr('$'))
468 2wincmd }
469 call assert_equal(3, winnr('$'))
470 call assert_match('^|iccf|', getline('.'))
471 wincmd k
472 call assert_match('\*iccf\*', getline('.'))
473 call assert_equal(2, winheight(0))
474
475 wincmd z
476 set previewheight=4
477 help
478 /bugs
479 wincmd }
480 wincmd k
481 call assert_match('\*bugs\*', getline('.'))
482 call assert_equal(4, winheight(0))
483 set previewheight&
484
485 %bw!
486endfunc
487
488func Test_window_newtab()
489 e Xa
490
491 call assert_equal(1, tabpagenr('$'))
492 call assert_equal("\nAlready only one window", execute('wincmd T'))
493
494 split Xb
495 split Xc
496
497 wincmd T
498 call assert_equal(2, tabpagenr('$'))
499 call assert_equal(['Xb', 'Xa'], map(tabpagebuflist(1), 'bufname(v:val)'))
Bram Moolenaarce90e362019-09-08 18:58:44 +0200500 call assert_equal(['Xc' ], map(2->tabpagebuflist(), 'bufname(v:val)'))
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100501 call assert_equal(['Xc' ], map(tabpagebuflist(), 'bufname(v:val)'))
Bram Moolenaar4520d442017-03-19 16:09:46 +0100502
503 %bw!
504endfunc
505
Bram Moolenaarf79225e2017-03-18 23:11:04 +0100506func Test_next_split_all()
507 " This was causing an illegal memory access.
508 n x
509 norm axxx
510 split
511 split
512 s/x
513 s/x
514 all
515 bwipe!
516endfunc
517
Bram Moolenaar75373f32017-08-07 22:02:30 +0200518" Tests for adjusting window and contents
519func GetScreenStr(row)
520 let str = ""
521 for c in range(1,3)
522 let str .= nr2char(screenchar(a:row, c))
523 endfor
524 return str
525endfunc
526
527func Test_window_contents()
528 enew! | only | new
529 call setline(1, range(1,256))
530
531 exe "norm! \<C-W>t\<C-W>=1Gzt\<C-W>w\<C-W>+"
532 redraw
Bram Moolenaar72cf47a2018-05-10 18:23:29 +0200533 let s3 = GetScreenStr(1)
Bram Moolenaar75373f32017-08-07 22:02:30 +0200534 wincmd p
535 call assert_equal(1, line("w0"))
536 call assert_equal('1 ', s3)
537
538 exe "norm! \<C-W>t\<C-W>=50Gzt\<C-W>w\<C-W>+"
539 redraw
Bram Moolenaar72cf47a2018-05-10 18:23:29 +0200540 let s3 = GetScreenStr(1)
Bram Moolenaar75373f32017-08-07 22:02:30 +0200541 wincmd p
542 call assert_equal(50, line("w0"))
543 call assert_equal('50 ', s3)
544
545 exe "norm! \<C-W>t\<C-W>=59Gzt\<C-W>w\<C-W>+"
546 redraw
Bram Moolenaar72cf47a2018-05-10 18:23:29 +0200547 let s3 = GetScreenStr(1)
Bram Moolenaar75373f32017-08-07 22:02:30 +0200548 wincmd p
549 call assert_equal(59, line("w0"))
550 call assert_equal('59 ', s3)
551
Bram Moolenaar8b633132020-03-20 18:20:51 +0100552 %d
553 call setline(1, ['one', 'two', 'three'])
554 call assert_equal(1, line('w0'))
555 call assert_equal(3, line('w$'))
556
Bram Moolenaar75373f32017-08-07 22:02:30 +0200557 bwipeout!
558 call test_garbagecollect_now()
559endfunc
560
Bram Moolenaar2efb3232017-12-19 12:27:23 +0100561func Test_window_colon_command()
562 " This was reading invalid memory.
563 exe "norm! v\<C-W>:\<C-U>echo v:version"
564endfunc
565
Bram Moolenaar6f361c92018-01-31 19:06:50 +0100566func Test_access_freed_mem()
Bram Moolenaar1417c762019-07-27 17:31:36 +0200567 call assert_equal(&columns, winwidth(0))
Bram Moolenaar6f361c92018-01-31 19:06:50 +0100568 " This was accessing freed memory
569 au * 0 vs xxx
570 arg 0
571 argadd
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +0200572 call assert_fails("all", "E242:")
Bram Moolenaar6f361c92018-01-31 19:06:50 +0100573 au!
574 bwipe xxx
Bram Moolenaar1417c762019-07-27 17:31:36 +0200575 call assert_equal(&columns, winwidth(0))
Bram Moolenaar6f361c92018-01-31 19:06:50 +0100576endfunc
577
Bram Moolenaara27e1dc2019-10-07 22:27:36 +0200578func Test_insert_cleared_on_switch_to_term()
579 CheckFeature terminal
580
581 set showmode
582 terminal
583 wincmd p
584
585 call feedkeys("i\<C-O>", 'ntx')
586 redraw
587
588 " The "-- (insert) --" indicator should be visible.
589 let chars = map(range(1, &columns), 'nr2char(screenchar(&lines, v:val))')
590 let str = trim(join(chars, ''))
591 call assert_equal('-- (insert) --', str)
592
593 call feedkeys("\<C-W>p", 'ntx')
594 redraw
595
596 " The "-- (insert) --" indicator should have been cleared.
597 let chars = map(range(1, &columns), 'nr2char(screenchar(&lines, v:val))')
598 let str = trim(join(chars, ''))
599 call assert_equal('', str)
600
601 set showmode&
602 %bw!
603endfunc
604
Bram Moolenaar5bab5552018-04-13 20:41:29 +0200605func Test_visual_cleared_after_window_split()
606 new | only!
607 let smd_save = &showmode
608 set showmode
609 let ls_save = &laststatus
610 set laststatus=1
611 call setline(1, ['a', 'b', 'c', 'd', ''])
612 norm! G
613 exe "norm! kkvk"
614 redraw
615 exe "norm! \<C-W>v"
616 redraw
617 " check if '-- VISUAL --' disappeared from command line
618 let columns = range(1, &columns)
619 let cmdlinechars = map(columns, 'nr2char(screenchar(&lines, v:val))')
620 let cmdline = join(cmdlinechars, '')
621 let cmdline_ltrim = substitute(cmdline, '^\s*', "", "")
622 let mode_shown = substitute(cmdline_ltrim, '\s*$', "", "")
623 call assert_equal('', mode_shown)
624 let &showmode = smd_save
625 let &laststatus = ls_save
626 bwipe!
627endfunc
628
Bram Moolenaar72cf47a2018-05-10 18:23:29 +0200629func Test_winrestcmd()
630 2split
631 3vsplit
632 let a = winrestcmd()
633 call assert_equal(2, winheight(0))
634 call assert_equal(3, winwidth(0))
635 wincmd =
636 call assert_notequal(2, winheight(0))
637 call assert_notequal(3, winwidth(0))
638 exe a
639 call assert_equal(2, winheight(0))
640 call assert_equal(3, winwidth(0))
641 only
642endfunc
643
Bram Moolenaar1e115362019-01-09 23:01:02 +0100644func Fun_RenewFile()
Bram Moolenaar026587b2019-08-17 15:08:00 +0200645 " Need to wait a bit for the timestamp to be older.
Bram Moolenaarce90e362019-09-08 18:58:44 +0200646 let old_ftime = getftime("tmp.txt")
647 while getftime("tmp.txt") == old_ftime
648 sleep 100m
649 silent execute '!echo "1" > tmp.txt'
650 endwhile
Bram Moolenaara42df592018-12-24 00:22:39 +0100651 sp
652 wincmd p
653 edit! tmp.txt
Bram Moolenaar1e115362019-01-09 23:01:02 +0100654endfunc
Bram Moolenaara42df592018-12-24 00:22:39 +0100655
656func Test_window_prevwin()
657 " Can we make this work on MS-Windows?
658 if !has('unix')
659 return
660 endif
661
662 set hidden autoread
663 call writefile(['2'], 'tmp.txt')
664 new tmp.txt
665 q
Bram Moolenaara42df592018-12-24 00:22:39 +0100666 call Fun_RenewFile()
667 call assert_equal(2, winnr())
668 wincmd p
669 call assert_equal(1, winnr())
670 wincmd p
671 q
672 call Fun_RenewFile()
673 call assert_equal(2, winnr())
674 wincmd p
675 call assert_equal(1, winnr())
676 wincmd p
677 " reset
678 q
679 call delete('tmp.txt')
680 set hidden&vim autoread&vim
681 delfunc Fun_RenewFile
682endfunc
683
Bram Moolenaar8fcb60f2019-03-04 13:18:30 +0100684func Test_relative_cursor_position_in_one_line_window()
685 new
686 only
687 call setline(1, range(1, 10000))
688 normal 50%
689 let lnum = getcurpos()[1]
690 split
691 split
692 " make third window take as many lines as possible, other windows will
693 " become one line
694 3wincmd w
695 for i in range(1, &lines - 6)
696 wincmd +
697 redraw!
698 endfor
699
700 " first and second window should show cursor line
701 let wininfo = getwininfo()
702 call assert_equal(lnum, wininfo[0].topline)
703 call assert_equal(lnum, wininfo[1].topline)
704
705 only!
706 bwipe!
Bram Moolenaar99fa7212020-04-26 15:59:55 +0200707 call assert_fails('call winrestview(test_null_dict())', 'E474:')
Bram Moolenaar8fcb60f2019-03-04 13:18:30 +0100708endfunc
709
710func Test_relative_cursor_position_after_move_and_resize()
711 let so_save = &so
712 set so=0
713 enew
714 call setline(1, range(1, 10000))
715 normal 50%
716 split
717 1wincmd w
718 " Move cursor to first line in window
719 normal H
720 redraw!
721 " Reduce window height to two lines
722 let height = winheight(0)
723 while winheight(0) > 2
724 wincmd -
725 redraw!
726 endwhile
727 " move cursor to second/last line in window
728 normal j
729 " restore previous height
730 while winheight(0) < height
731 wincmd +
732 redraw!
733 endwhile
734 " make window two lines again
735 while winheight(0) > 2
736 wincmd -
737 redraw!
738 endwhile
739
740 " cursor should be at bottom line
741 let info = getwininfo(win_getid())[0]
742 call assert_equal(info.topline + 1, getcurpos()[1])
743
744 only!
745 bwipe!
746 let &so = so_save
747endfunc
748
749func Test_relative_cursor_position_after_resize()
750 let so_save = &so
751 set so=0
752 enew
753 call setline(1, range(1, 10000))
754 normal 50%
755 split
756 1wincmd w
757 let winid1 = win_getid()
758 let info = getwininfo(winid1)[0]
759 " Move cursor to second line in window
760 exe "normal " . (info.topline + 1) . "G"
761 redraw!
762 let lnum = getcurpos()[1]
763
764 " Make the window only two lines high, cursor should end up in top line
765 2wincmd w
766 exe (info.height - 2) . "wincmd +"
767 redraw!
768 let info = getwininfo(winid1)[0]
769 call assert_equal(lnum, info.topline)
770
771 only!
772 bwipe!
773 let &so = so_save
774endfunc
775
776func Test_relative_cursor_second_line_after_resize()
777 let so_save = &so
778 set so=0
779 enew
780 call setline(1, range(1, 10000))
781 normal 50%
782 split
783 1wincmd w
784 let winid1 = win_getid()
785 let info = getwininfo(winid1)[0]
786
787 " Make the window only two lines high
788 2wincmd _
789
790 " Move cursor to second line in window
791 normal H
792 normal j
793
794 " Make window size bigger, then back to 2 lines
795 for i in range(1, 10)
796 wincmd +
797 redraw!
798 endfor
799 for i in range(1, 10)
800 wincmd -
801 redraw!
802 endfor
803
804 " cursor should end up in bottom line
805 let info = getwininfo(winid1)[0]
806 call assert_equal(info.topline + 1, getcurpos()[1])
807
808 only!
809 bwipe!
810 let &so = so_save
811endfunc
812
Bram Moolenaara9b25352019-05-12 14:25:30 +0200813func Test_split_noscroll()
814 let so_save = &so
Bram Moolenaarbd2d68c2019-05-18 15:36:11 +0200815 enew
816 call setline(1, range(1, 8))
Bram Moolenaara9b25352019-05-12 14:25:30 +0200817 normal 100%
818 split
819
820 1wincmd w
821 let winid1 = win_getid()
822 let info1 = getwininfo(winid1)[0]
823
824 2wincmd w
825 let winid2 = win_getid()
826 let info2 = getwininfo(winid2)[0]
827
828 call assert_equal(1, info1.topline)
829 call assert_equal(1, info2.topline)
830
Bram Moolenaarbd2d68c2019-05-18 15:36:11 +0200831 " window that fits all lines by itself, but not when split: closing other
832 " window should restore fraction.
Bram Moolenaara9b25352019-05-12 14:25:30 +0200833 only!
Bram Moolenaarbd2d68c2019-05-18 15:36:11 +0200834 call setline(1, range(1, &lines - 10))
835 exe &lines / 4
836 let winid1 = win_getid()
837 let info1 = getwininfo(winid1)[0]
838 call assert_equal(1, info1.topline)
839 new
840 redraw
841 close
842 let info1 = getwininfo(winid1)[0]
843 call assert_equal(1, info1.topline)
844
Bram Moolenaara9b25352019-05-12 14:25:30 +0200845 bwipe!
846 let &so = so_save
847endfunc
848
Bram Moolenaar46ad2882019-04-08 20:01:47 +0200849" Tests for the winnr() function
850func Test_winnr()
851 only | tabonly
852 call assert_equal(1, winnr('j'))
853 call assert_equal(1, winnr('k'))
854 call assert_equal(1, winnr('h'))
855 call assert_equal(1, winnr('l'))
856
857 " create a set of horizontally and vertically split windows
858 leftabove new | wincmd p
859 leftabove new | wincmd p
860 rightbelow new | wincmd p
861 rightbelow new | wincmd p
862 leftabove vnew | wincmd p
863 leftabove vnew | wincmd p
864 rightbelow vnew | wincmd p
865 rightbelow vnew | wincmd p
866
867 call assert_equal(8, winnr('j'))
868 call assert_equal(2, winnr('k'))
869 call assert_equal(4, winnr('h'))
870 call assert_equal(6, winnr('l'))
871 call assert_equal(9, winnr('2j'))
872 call assert_equal(1, winnr('2k'))
873 call assert_equal(3, winnr('2h'))
874 call assert_equal(7, winnr('2l'))
875
876 " Error cases
877 call assert_fails("echo winnr('0.2k')", 'E15:')
878 call assert_equal(2, winnr('-2k'))
879 call assert_fails("echo winnr('-2xj')", 'E15:')
880 call assert_fails("echo winnr('j2j')", 'E15:')
881 call assert_fails("echo winnr('ll')", 'E15:')
882 call assert_fails("echo winnr('5')", 'E15:')
883 call assert_equal(4, winnr('0h'))
Bram Moolenaar99fa7212020-04-26 15:59:55 +0200884 call assert_fails("let w = winnr([])", 'E730:')
885 call assert_equal('unknown', win_gettype(-1))
886 call assert_equal(-1, winheight(-1))
887 call assert_equal(-1, winwidth(-1))
Bram Moolenaar46ad2882019-04-08 20:01:47 +0200888
889 tabnew
890 call assert_equal(8, tabpagewinnr(1, 'j'))
Bram Moolenaarce90e362019-09-08 18:58:44 +0200891 call assert_equal(2, 1->tabpagewinnr('k'))
Bram Moolenaar46ad2882019-04-08 20:01:47 +0200892 call assert_equal(4, tabpagewinnr(1, 'h'))
893 call assert_equal(6, tabpagewinnr(1, 'l'))
894
895 only | tabonly
896endfunc
897
Bram Moolenaarf92e58c2019-09-08 21:51:41 +0200898func Test_winrestview()
899 split runtest.vim
900 normal 50%
901 let view = winsaveview()
902 close
903 split runtest.vim
904 eval view->winrestview()
905 call assert_equal(view, winsaveview())
906
907 bwipe!
Bram Moolenaar99fa7212020-04-26 15:59:55 +0200908 call assert_fails('call winrestview(test_null_dict())', 'E474:')
Bram Moolenaarf92e58c2019-09-08 21:51:41 +0200909endfunc
910
Bram Moolenaard20dcb32019-09-10 21:22:58 +0200911func Test_win_splitmove()
Bram Moolenaar5a4c3082019-12-01 15:23:11 +0100912 CheckFeature quickfix
913
Bram Moolenaard20dcb32019-09-10 21:22:58 +0200914 edit a
915 leftabove split b
916 leftabove vsplit c
917 leftabove split d
918 call assert_equal(0, win_splitmove(winnr(), winnr('l')))
919 call assert_equal(bufname(winbufnr(1)), 'c')
920 call assert_equal(bufname(winbufnr(2)), 'd')
921 call assert_equal(bufname(winbufnr(3)), 'b')
922 call assert_equal(bufname(winbufnr(4)), 'a')
923 call assert_equal(0, win_splitmove(winnr(), winnr('j'), {'vertical': 1}))
924 call assert_equal(0, win_splitmove(winnr(), winnr('j'), {'vertical': 1}))
925 call assert_equal(bufname(winbufnr(1)), 'c')
926 call assert_equal(bufname(winbufnr(2)), 'b')
927 call assert_equal(bufname(winbufnr(3)), 'd')
928 call assert_equal(bufname(winbufnr(4)), 'a')
929 call assert_equal(0, win_splitmove(winnr(), winnr('k'), {'vertical': 1}))
930 call assert_equal(bufname(winbufnr(1)), 'd')
931 call assert_equal(bufname(winbufnr(2)), 'c')
932 call assert_equal(bufname(winbufnr(3)), 'b')
933 call assert_equal(bufname(winbufnr(4)), 'a')
934 call assert_equal(0, win_splitmove(winnr(), winnr('j'), {'rightbelow': v:true}))
935 call assert_equal(bufname(winbufnr(1)), 'c')
936 call assert_equal(bufname(winbufnr(2)), 'b')
937 call assert_equal(bufname(winbufnr(3)), 'a')
938 call assert_equal(bufname(winbufnr(4)), 'd')
Bram Moolenaar99fa7212020-04-26 15:59:55 +0200939 call assert_fails('call win_splitmove(winnr(), winnr("k"), test_null_dict())', 'E474:')
Bram Moolenaard20dcb32019-09-10 21:22:58 +0200940 only | bd
941
942 call assert_fails('call win_splitmove(winnr(), 123)', 'E957:')
943 call assert_fails('call win_splitmove(123, winnr())', 'E957:')
944 call assert_fails('call win_splitmove(winnr(), winnr())', 'E957:')
Bram Moolenaar7b94e772020-01-06 21:03:24 +0100945
946 tabnew
947 call assert_fails('call win_splitmove(1, win_getid(1, 1))', 'E957:')
948 tabclose
Bram Moolenaard20dcb32019-09-10 21:22:58 +0200949endfunc
950
Bram Moolenaare20b9ec2020-02-03 21:40:04 +0100951" Test for the :only command
952func Test_window_only()
953 new
954 set modified
955 new
956 call assert_fails('only', 'E445:')
957 only!
Bram Moolenaarbc2b71d2020-02-17 21:33:30 +0100958 " Test for :only with a count
959 let wid = win_getid()
960 new
961 new
962 3only
963 call assert_equal(1, winnr('$'))
964 call assert_equal(wid, win_getid())
965 call assert_fails('close', 'E444:')
966 call assert_fails('%close', 'E16:')
Bram Moolenaare20b9ec2020-02-03 21:40:04 +0100967endfunc
968
Bram Moolenaar9f6277b2020-02-11 22:04:02 +0100969" Test for errors with :wincmd
970func Test_wincmd_errors()
971 call assert_fails('wincmd g', 'E474:')
972 call assert_fails('wincmd ab', 'E474:')
973endfunc
974
975" Test for errors with :winpos
976func Test_winpos_errors()
977 if !has("gui_running") && !has('win32')
978 call assert_fails('winpos', 'E188:')
979 endif
980 call assert_fails('winpos 10', 'E466:')
981endfunc
982
Bram Moolenaar406cd902020-02-18 21:54:41 +0100983" Test for +cmd in a :split command
984func Test_split_cmd()
985 split +set\ readonly
986 call assert_equal(1, &readonly)
987 call assert_equal(2, winnr('$'))
988 close
989endfunc
990
Bram Moolenaar5080b0a2020-03-22 21:23:47 +0100991" Create maximum number of horizontally or vertically split windows and then
992" run commands that create a new horizontally/vertically split window
993func Run_noroom_for_newwindow_test(dir_arg)
994 let dir = (a:dir_arg == 'v') ? 'vert ' : ''
995
996 " Open as many windows as possible
Bram Moolenaarab505b12020-03-23 19:28:44 +0100997 while v:true
Bram Moolenaar5080b0a2020-03-22 21:23:47 +0100998 try
999 exe dir . 'new'
1000 catch /E36:/
1001 break
1002 endtry
Bram Moolenaarab505b12020-03-23 19:28:44 +01001003 endwhile
Bram Moolenaar5080b0a2020-03-22 21:23:47 +01001004
1005 call writefile(['first', 'second', 'third'], 'Xfile1')
1006 call writefile([], 'Xfile2')
1007 call writefile([], 'Xfile3')
1008
1009 " Argument list related commands
1010 args Xfile1 Xfile2 Xfile3
1011 next
1012 for cmd in ['sargument 2', 'snext', 'sprevious', 'sNext', 'srewind',
1013 \ 'sfirst', 'slast']
1014 call assert_fails(dir .. cmd, 'E36:')
1015 endfor
1016 %argdelete
1017
1018 " Buffer related commands
1019 set modified
1020 hide enew
1021 for cmd in ['sbuffer Xfile1', 'sbnext', 'sbprevious', 'sbNext', 'sbrewind',
1022 \ 'sbfirst', 'sblast', 'sball', 'sbmodified', 'sunhide']
1023 call assert_fails(dir .. cmd, 'E36:')
1024 endfor
1025
1026 " Window related commands
1027 for cmd in ['split', 'split Xfile2', 'new', 'new Xfile3', 'sview Xfile1',
1028 \ 'sfind runtest.vim']
1029 call assert_fails(dir .. cmd, 'E36:')
1030 endfor
1031
1032 " Help
1033 call assert_fails(dir .. 'help', 'E36:')
1034 call assert_fails(dir .. 'helpgrep window', 'E36:')
1035
1036 " Command-line window
1037 if a:dir_arg == 'h'
1038 " Cmd-line window is always a horizontally split window
1039 call assert_beeps('call feedkeys("q:\<CR>", "xt")')
1040 endif
1041
1042 " Quickfix and location list window
1043 if has('quickfix')
1044 cexpr ''
1045 call assert_fails(dir .. 'copen', 'E36:')
1046 lexpr ''
1047 call assert_fails(dir .. 'lopen', 'E36:')
1048
1049 " Preview window
1050 call assert_fails(dir .. 'pedit Xfile2', 'E36:')
1051 call setline(1, 'abc')
1052 call assert_fails(dir .. 'psearch abc', 'E36:')
1053 endif
1054
1055 " Window commands (CTRL-W ^ and CTRL-W f)
1056 if a:dir_arg == 'h'
1057 call assert_fails('call feedkeys("\<C-W>^", "xt")', 'E36:')
1058 call setline(1, 'Xfile1')
1059 call assert_fails('call feedkeys("gg\<C-W>f", "xt")', 'E36:')
1060 endif
1061 enew!
1062
1063 " Tag commands (:stag, :stselect and :stjump)
1064 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//",
1065 \ "second\tXfile1\t2",
1066 \ "third\tXfile1\t3",],
1067 \ 'Xtags')
1068 set tags=Xtags
1069 call assert_fails(dir .. 'stag second', 'E36:')
1070 call assert_fails('call feedkeys(":" .. dir .. "stselect second\n1\n", "xt")', 'E36:')
1071 call assert_fails(dir .. 'stjump second', 'E36:')
1072 call assert_fails(dir .. 'ptag second', 'E36:')
1073 set tags&
1074 call delete('Xtags')
1075
1076 " :isplit and :dsplit
1077 call setline(1, ['#define FOO 1', 'FOO'])
1078 normal 2G
1079 call assert_fails(dir .. 'isplit FOO', 'E36:')
1080 call assert_fails(dir .. 'dsplit FOO', 'E36:')
1081
1082 " terminal
1083 if has('terminal')
1084 call assert_fails(dir .. 'terminal', 'E36:')
1085 endif
1086
1087 %bwipe!
1088 call delete('Xfile1')
1089 call delete('Xfile2')
1090 call delete('Xfile3')
1091 only
1092endfunc
1093
1094func Test_split_cmds_with_no_room()
1095 call Run_noroom_for_newwindow_test('h')
1096 call Run_noroom_for_newwindow_test('v')
1097endfunc
1098
Bram Moolenaarad48e6c2020-04-21 22:19:45 +02001099" Test for various wincmd failures
1100func Test_wincmd_fails()
1101 only!
1102 call assert_beeps("normal \<C-W>w")
1103 call assert_beeps("normal \<C-W>p")
1104 call assert_beeps("normal \<C-W>gk")
1105 call assert_beeps("normal \<C-W>r")
1106 call assert_beeps("normal \<C-W>K")
1107 call assert_beeps("normal \<C-W>H")
1108 call assert_beeps("normal \<C-W>2gt")
1109endfunc
1110
Bram Moolenaar5d3c9f82020-06-26 20:41:39 +02001111" Test for adjusting the window width when a window is closed with some
1112" windows using 'winfixwidth'
1113func Test_window_width_adjust()
1114 only
1115 " Three vertical windows. Windows 1 and 2 have 'winfixwidth' set and close
1116 " window 2.
1117 wincmd v
1118 vert resize 10
1119 set winfixwidth
1120 wincmd v
1121 set winfixwidth
1122 wincmd c
1123 call assert_inrange(10, 12, winwidth(1))
1124 " Three vertical windows. Windows 2 and 3 have 'winfixwidth' set and close
1125 " window 3.
1126 only
1127 set winfixwidth
1128 wincmd v
1129 vert resize 10
1130 set winfixwidth
1131 wincmd v
1132 set nowinfixwidth
1133 wincmd b
1134 wincmd c
1135 call assert_inrange(10, 12, winwidth(2))
1136
1137 new | only
1138endfunc
1139
1140" Test for jumping to a vertical/horizontal neighbor window based on the
1141" current cursor position
1142func Test_window_goto_neightbor()
1143 %bw!
1144
1145 " Vertical window movement
1146
1147 " create the following window layout:
1148 " +--+--+
1149 " |w1|w3|
1150 " +--+ |
1151 " |w2| |
1152 " +--+--+
1153 " |w4 |
1154 " +-----+
1155 new
1156 vsplit
1157 split
1158 " vertically jump from w4
1159 wincmd b
1160 call setline(1, repeat(' ', &columns))
1161 call cursor(1, 1)
1162 wincmd k
1163 call assert_equal(2, winnr())
1164 wincmd b
1165 call cursor(1, &columns)
1166 redraw!
1167 wincmd k
1168 call assert_equal(3, winnr())
1169 %bw!
1170
1171 " create the following window layout:
1172 " +--+--+--+
1173 " |w1|w2|w3|
1174 " +--+--+--+
1175 " |w4 |
1176 " +--------+
1177 new
1178 vsplit
1179 vsplit
1180 wincmd b
1181 call setline(1, repeat(' ', &columns))
1182 call cursor(1, 1)
1183 wincmd k
1184 call assert_equal(1, winnr())
1185 wincmd b
1186 call cursor(1, &columns / 2)
1187 redraw!
1188 wincmd k
1189 call assert_equal(2, winnr())
1190 wincmd b
1191 call cursor(1, &columns)
1192 redraw!
1193 wincmd k
1194 call assert_equal(3, winnr())
1195 %bw!
1196
1197 " Horizontal window movement
1198
1199 " create the following window layout:
1200 " +--+--+--+
1201 " |w1|w2|w4|
1202 " +--+--+ |
1203 " |w3 | |
1204 " +-----+--+
1205 vsplit
1206 split
1207 vsplit
1208 4wincmd l
1209 call setline(1, repeat([' '], &lines))
1210 call cursor(1, 1)
1211 redraw!
1212 wincmd h
1213 call assert_equal(2, winnr())
1214 4wincmd l
1215 call cursor(&lines, 1)
1216 redraw!
1217 wincmd h
1218 call assert_equal(3, winnr())
1219 %bw!
1220
1221 " create the following window layout:
1222 " +--+--+
1223 " |w1|w4|
1224 " +--+ +
1225 " |w2| |
1226 " +--+ +
1227 " |w3| |
1228 " +--+--+
1229 vsplit
1230 split
1231 split
1232 wincmd l
1233 call setline(1, repeat([' '], &lines))
1234 call cursor(1, 1)
1235 redraw!
1236 wincmd h
1237 call assert_equal(1, winnr())
1238 wincmd l
1239 call cursor(&lines / 2, 1)
1240 redraw!
1241 wincmd h
1242 call assert_equal(2, winnr())
1243 wincmd l
1244 call cursor(&lines, 1)
1245 redraw!
1246 wincmd h
1247 call assert_equal(3, winnr())
1248 %bw!
1249endfunc
1250
1251" Test for an autocmd closing the destination window when jumping from one
1252" window to another.
1253func Test_close_dest_window()
1254 split
1255 edit Xfile
1256
1257 " Test for BufLeave
1258 augroup T1
1259 au!
1260 au BufLeave Xfile $wincmd c
1261 augroup END
1262 wincmd b
1263 call assert_equal(1, winnr('$'))
1264 call assert_equal('Xfile', @%)
1265 augroup T1
1266 au!
1267 augroup END
1268
1269 " Test for WinLeave
1270 new
1271 wincmd p
1272 augroup T1
1273 au!
1274 au WinLeave * 1wincmd c
1275 augroup END
1276 wincmd t
1277 call assert_equal(1, winnr('$'))
1278 call assert_equal('Xfile', @%)
1279 augroup T1
1280 au!
1281 augroup END
1282 augroup! T1
1283 %bw!
1284endfunc
1285
Bram Moolenaar9e4d8212016-08-18 23:04:48 +02001286" vim: shiftwidth=2 sts=2 expandtab