Skip to content

Commit 4520d44

Browse files
committed
patch 8.0.0485: not all windows commands are tested
Problem: Not all windows commands are tested. Solution: Add more tests for windows commands. (Dominique Pelle, closes #1575) Run test_autocmd separately, it interferes with other tests. Fix tests that depended on side effects.
1 parent ee85df3 commit 4520d44

File tree

8 files changed

+317
-4
lines changed

8 files changed

+317
-4
lines changed

src/testdir/Make_all.mak

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ NEW_TESTS = test_arabic.res \
137137
test_arglist.res \
138138
test_assert.res \
139139
test_autochdir.res \
140+
test_autocmd.res \
140141
test_backspace_opt.res \
141142
test_breakindent.res \
142143
test_bufwintabinfo.res \

src/testdir/test_alot.vim

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
set belloff=all
55
source test_assign.vim
6-
source test_autocmd.vim
76
source test_changedtick.vim
87
source test_cursor_func.vim
98
source test_delete.vim

src/testdir/test_autocmd.vim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
" Tests for autocommands
22

3+
set belloff=all
4+
35
function! s:cleanup_buffers() abort
46
for bnr in range(1, bufnr('$'))
57
if bufloaded(bnr) && bufnr('%') != bnr
@@ -318,6 +320,8 @@ func Test_three_windows()
318320
call assert_equal('Xanother', expand('%'))
319321

320322
au!
323+
enew
324+
bwipe! Xtestje1
321325
call delete('Xtestje1')
322326
call delete('Xtestje2')
323327
call delete('Xtestje3')

src/testdir/test_delete.vim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ func Test_file_delete()
88
call assert_equal(0, delete('Xfile'))
99
call assert_fails('call readfile("Xfile")', 'E484:')
1010
call assert_equal(-1, delete('Xfile'))
11+
bwipe Xfile
1112
endfunc
1213

1314
func Test_dir_delete()
@@ -35,6 +36,8 @@ func Test_recursive_delete()
3536
call assert_equal(0, delete('Xdir1', 'rf'))
3637
call assert_false(isdirectory('Xdir1'))
3738
call assert_equal(-1, delete('Xdir1', 'd'))
39+
bwipe Xdir1/Xfile
40+
bwipe Xdir1/subdir/Xfile
3841
endfunc
3942

4043
func Test_symlink_delete()
@@ -49,6 +52,7 @@ func Test_symlink_delete()
4952
call assert_equal(0, delete('Xlink'))
5053
call assert_equal(-1, delete('Xlink'))
5154
call assert_equal(0, delete('Xfile'))
55+
bwipe Xfile
5256
endfunc
5357

5458
func Test_symlink_dir_delete()
@@ -96,4 +100,8 @@ func Test_symlink_recursive_delete()
96100
call assert_equal(['a', 'b'], readfile('Xdir4/Xfile'))
97101
call assert_equal(0, delete('Xdir4/Xfile'))
98102
call assert_equal(0, delete('Xdir4', 'd'))
103+
104+
bwipe Xdir3/Xfile
105+
bwipe Xdir3/subdir/Xfile
106+
bwipe Xdir4/Xfile
99107
endfunc

src/testdir/test_fnamemodify.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ func Test_fnamemodify()
3333
call assert_equal('''abc"%"def''', fnamemodify('abc"%"def', ':S'))
3434
call assert_equal('''abc''\'''' ''\''''def''', fnamemodify('abc'' ''def', ':S'))
3535
call assert_equal('''abc''\''''%''\''''def''', fnamemodify('abc''%''def', ':S'))
36-
call assert_equal(expand('%:r:S'), shellescape(expand('%:r')))
3736
sp test_alot.vim
37+
call assert_equal(expand('%:r:S'), shellescape(expand('%:r')))
3838
call assert_equal('test_alot,''test_alot'',test_alot.vim', join([expand('%:r'), expand('%:r:S'), expand('%')], ','))
3939
quit
4040

src/testdir/test_functions.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,8 +460,8 @@ func Test_getbufvar()
460460
let bd = getbufvar(bnr, '',def_num)
461461
call assert_equal(1, len(bd))
462462

463-
call assert_equal('', getbufvar(9, ''))
464-
call assert_equal(def_num, getbufvar(9, '', def_num))
463+
call assert_equal('', getbufvar(9999, ''))
464+
call assert_equal(def_num, getbufvar(9999, '', def_num))
465465
unlet def_num
466466

467467
call assert_equal(0, getbufvar(bnr, '&autoindent'))

src/testdir/test_window_cmd.vim

Lines changed: 299 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,305 @@ function Test_window_cmd_wincmd_gf()
6767
augroup! test_window_cmd_wincmd_gf
6868
endfunc
6969

70+
func Test_window_quit()
71+
e Xa
72+
split Xb
73+
call assert_equal(2, winnr('$'))
74+
call assert_equal('Xb', bufname(winbufnr(1)))
75+
call assert_equal('Xa', bufname(winbufnr(2)))
76+
77+
wincmd q
78+
call assert_equal(1, winnr('$'))
79+
call assert_equal('Xa', bufname(winbufnr(1)))
80+
81+
bw Xa Xb
82+
endfunc
83+
84+
func Test_window_horizontal_split()
85+
call assert_equal(1, winnr('$'))
86+
3wincmd s
87+
call assert_equal(2, winnr('$'))
88+
call assert_equal(3, winheight(0))
89+
call assert_equal(winwidth(1), winwidth(2))
90+
91+
call assert_fails('botright topleft wincmd s', 'E442:')
92+
bw
93+
endfunc
94+
95+
func Test_window_vertical_split()
96+
call assert_equal(1, winnr('$'))
97+
3wincmd v
98+
call assert_equal(2, winnr('$'))
99+
call assert_equal(3, winwidth(0))
100+
call assert_equal(winheight(1), winheight(2))
101+
102+
call assert_fails('botright topleft wincmd v', 'E442:')
103+
bw
104+
endfunc
105+
106+
func Test_window_split_edit_alternate()
107+
e Xa
108+
e Xb
109+
110+
wincmd ^
111+
call assert_equal('Xa', bufname(winbufnr(1)))
112+
call assert_equal('Xb', bufname(winbufnr(2)))
113+
114+
bw Xa Xb
115+
endfunc
116+
117+
func Test_window_preview()
118+
" Open a preview window
119+
pedit Xa
120+
call assert_equal(2, winnr('$'))
121+
call assert_equal(0, &previewwindow)
122+
123+
" Go to the preview window
124+
wincmd P
125+
call assert_equal(1, &previewwindow)
126+
127+
" Close preview window
128+
wincmd z
129+
call assert_equal(1, winnr('$'))
130+
call assert_equal(0, &previewwindow)
131+
132+
call assert_fails('wincmd P', 'E441:')
133+
endfunc
134+
135+
func Test_window_exchange()
136+
e Xa
137+
138+
" Nothing happens with window exchange when there is 1 window
139+
wincmd x
140+
call assert_equal(1, winnr('$'))
141+
142+
split Xb
143+
split Xc
144+
145+
call assert_equal('Xc', bufname(winbufnr(1)))
146+
call assert_equal('Xb', bufname(winbufnr(2)))
147+
call assert_equal('Xa', bufname(winbufnr(3)))
148+
149+
" Exchange current window 1 with window 3
150+
3wincmd x
151+
call assert_equal('Xa', bufname(winbufnr(1)))
152+
call assert_equal('Xb', bufname(winbufnr(2)))
153+
call assert_equal('Xc', bufname(winbufnr(3)))
154+
155+
" Exchange window with next when at the top window
156+
wincmd x
157+
call assert_equal('Xb', bufname(winbufnr(1)))
158+
call assert_equal('Xa', bufname(winbufnr(2)))
159+
call assert_equal('Xc', bufname(winbufnr(3)))
160+
161+
" Exchange window with next when at the middle window
162+
wincmd j
163+
wincmd x
164+
call assert_equal('Xb', bufname(winbufnr(1)))
165+
call assert_equal('Xc', bufname(winbufnr(2)))
166+
call assert_equal('Xa', bufname(winbufnr(3)))
167+
168+
" Exchange window with next when at the bottom window.
169+
" When there is no next window, it exchanges with the previous window.
170+
wincmd j
171+
wincmd x
172+
call assert_equal('Xb', bufname(winbufnr(1)))
173+
call assert_equal('Xa', bufname(winbufnr(2)))
174+
call assert_equal('Xc', bufname(winbufnr(3)))
175+
176+
bw Xa Xb Xc
177+
endfunc
178+
179+
func Test_window_rotate()
180+
e Xa
181+
split Xb
182+
split Xc
183+
call assert_equal('Xc', bufname(winbufnr(1)))
184+
call assert_equal('Xb', bufname(winbufnr(2)))
185+
call assert_equal('Xa', bufname(winbufnr(3)))
186+
187+
" Rotate downwards
188+
wincmd r
189+
call assert_equal('Xa', bufname(winbufnr(1)))
190+
call assert_equal('Xc', bufname(winbufnr(2)))
191+
call assert_equal('Xb', bufname(winbufnr(3)))
192+
193+
2wincmd r
194+
call assert_equal('Xc', bufname(winbufnr(1)))
195+
call assert_equal('Xb', bufname(winbufnr(2)))
196+
call assert_equal('Xa', bufname(winbufnr(3)))
197+
198+
" Rotate upwards
199+
wincmd R
200+
call assert_equal('Xb', bufname(winbufnr(1)))
201+
call assert_equal('Xa', bufname(winbufnr(2)))
202+
call assert_equal('Xc', bufname(winbufnr(3)))
203+
204+
2wincmd R
205+
call assert_equal('Xc', bufname(winbufnr(1)))
206+
call assert_equal('Xb', bufname(winbufnr(2)))
207+
call assert_equal('Xa', bufname(winbufnr(3)))
208+
209+
bot vsplit
210+
call assert_fails('wincmd R', 'E443:')
211+
212+
bw Xa Xb Xc
213+
endfunc
214+
215+
func Test_window_height()
216+
e Xa
217+
split Xb
218+
219+
let [wh1, wh2] = [winheight(1), winheight(2)]
220+
" Active window (1) should have the same height or 1 more
221+
" than the other window.
222+
call assert_inrange(wh2, wh2 + 1, wh1)
223+
224+
wincmd -
225+
call assert_equal(wh1 - 1, winheight(1))
226+
call assert_equal(wh2 + 1, winheight(2))
227+
228+
wincmd +
229+
call assert_equal(wh1, winheight(1))
230+
call assert_equal(wh2, winheight(2))
231+
232+
2wincmd _
233+
call assert_equal(2, winheight(1))
234+
call assert_equal(wh1 + wh2 - 2, winheight(2))
235+
236+
wincmd =
237+
call assert_equal(wh1, winheight(1))
238+
call assert_equal(wh2, winheight(2))
239+
240+
2wincmd _
241+
set winfixheight
242+
split Xc
243+
let [wh1, wh2, wh3] = [winheight(1), winheight(2), winheight(3)]
244+
call assert_equal(2, winheight(2))
245+
call assert_inrange(wh3, wh3 + 1, wh1)
246+
3wincmd +
247+
call assert_equal(2, winheight(2))
248+
call assert_equal(wh1 + 3, winheight(1))
249+
call assert_equal(wh3 - 3, winheight(3))
250+
wincmd =
251+
call assert_equal(2, winheight(2))
252+
call assert_equal(wh1, winheight(1))
253+
call assert_equal(wh3, winheight(3))
254+
255+
wincmd j
256+
set winfixheight&
257+
258+
wincmd =
259+
let [wh1, wh2, wh3] = [winheight(1), winheight(2), winheight(3)]
260+
" Current window (2) should have the same height or 1 more
261+
" than the other windows.
262+
call assert_inrange(wh1, wh1 + 1, wh2)
263+
call assert_inrange(wh3, wh3 + 1, wh2)
264+
265+
bw Xa Xb Xc
266+
endfunc
267+
268+
func Test_window_width()
269+
e Xa
270+
vsplit Xb
271+
272+
let [ww1, ww2] = [winwidth(1), winwidth(2)]
273+
" Active window (1) should have the same width or 1 more
274+
" than the other window.
275+
call assert_inrange(ww2, ww2 + 1, ww1)
276+
277+
wincmd <
278+
call assert_equal(ww1 - 1, winwidth(1))
279+
call assert_equal(ww2 + 1, winwidth(2))
280+
281+
wincmd >
282+
call assert_equal(ww1, winwidth(1))
283+
call assert_equal(ww2, winwidth(2))
284+
285+
2wincmd |
286+
call assert_equal(2, winwidth(1))
287+
call assert_equal(ww1 + ww2 - 2, winwidth(2))
288+
289+
wincmd =
290+
call assert_equal(ww1, winwidth(1))
291+
call assert_equal(ww2, winwidth(2))
292+
293+
2wincmd |
294+
set winfixwidth
295+
vsplit Xc
296+
let [ww1, ww2, ww3] = [winwidth(1), winwidth(2), winwidth(3)]
297+
" FIXME: commented out: I would expect the width of 2nd window to
298+
" remain 2 but it's actually 1?!
299+
"call assert_equal(2, winwidth(2))
300+
call assert_inrange(ww3, ww3 + 1, ww1)
301+
3wincmd >
302+
" FIXME: commented out: I would expect the width of 2nd window to
303+
" remain 2 but it's actually 1?!
304+
"call assert_equal(2, winwidth(2))
305+
call assert_equal(ww1 + 3, winwidth(1))
306+
call assert_equal(ww3 - 3, winwidth(3))
307+
wincmd =
308+
" FIXME: commented out: I would expect the width of 2nd window to
309+
" remain 2 but it's actually 1?!
310+
"call assert_equal(2, winwidth(2))
311+
call assert_equal(ww1, winwidth(1))
312+
call assert_equal(ww3, winwidth(3))
313+
314+
wincmd l
315+
set winfixwidth&
316+
317+
wincmd =
318+
let [ww1, ww2, ww3] = [winwidth(1), winwidth(2), winwidth(3)]
319+
" Current window (2) should have the same width or 1 more
320+
" than the other windows.
321+
call assert_inrange(ww1, ww1 + 1, ww2)
322+
call assert_inrange(ww3, ww3 + 1, ww2)
323+
324+
bw Xa Xb Xc
325+
endfunc
326+
327+
func Test_window_jump_tag()
328+
help
329+
/iccf
330+
call assert_match('^|iccf|', getline('.'))
331+
call assert_equal(2, winnr('$'))
332+
2wincmd }
333+
call assert_equal(3, winnr('$'))
334+
call assert_match('^|iccf|', getline('.'))
335+
wincmd k
336+
call assert_match('\*iccf\*', getline('.'))
337+
call assert_equal(2, winheight(0))
338+
339+
wincmd z
340+
set previewheight=4
341+
help
342+
/bugs
343+
wincmd }
344+
wincmd k
345+
call assert_match('\*bugs\*', getline('.'))
346+
call assert_equal(4, winheight(0))
347+
set previewheight&
348+
349+
%bw!
350+
endfunc
351+
352+
func Test_window_newtab()
353+
e Xa
354+
355+
call assert_equal(1, tabpagenr('$'))
356+
call assert_equal("\nAlready only one window", execute('wincmd T'))
357+
358+
split Xb
359+
split Xc
360+
361+
wincmd T
362+
call assert_equal(2, tabpagenr('$'))
363+
call assert_equal(['Xb', 'Xa'], map(tabpagebuflist(1), 'bufname(v:val)'))
364+
call assert_equal(['Xc' ], map(tabpagebuflist(2), 'bufname(v:val)'))
365+
366+
%bw!
367+
endfunc
368+
70369
func Test_next_split_all()
71370
" This was causing an illegal memory access.
72371
n x

0 commit comments

Comments
 (0)