blob: 58d13901627aaa0d6bd614b2769ed8eaec4d15a4 [file] [log] [blame]
Bram Moolenaar991dea32016-05-24 11:31:32 +02001" Tests for window cmd (:wincmd, :split, :vsplit, :resize and etc...)
2
3func Test_window_cmd_ls0_with_split()
4 set ls=0
5 set splitbelow
6 split
7 quit
8 call assert_equal(0, &lines - &cmdheight - winheight(0))
9 new | only!
10 "
11 set splitbelow&vim
12 botright split
13 quit
14 call assert_equal(0, &lines - &cmdheight - winheight(0))
15 new | only!
16 set ls&vim
17endfunc
18
19func Test_window_cmd_cmdwin_with_vsp()
20 let efmt='Expected 0 but got %d (in ls=%d, %s window)'
21 for v in range(0, 2)
22 exec "set ls=" . v
23 vsplit
24 call feedkeys("q:\<CR>")
25 let ac = &lines - (&cmdheight + winheight(0) + !!v)
26 let emsg = printf(efmt, ac, v, 'left')
27 call assert_equal(0, ac, emsg)
28 wincmd w
29 let ac = &lines - (&cmdheight + winheight(0) + !!v)
30 let emsg = printf(efmt, ac, v, 'right')
31 call assert_equal(0, ac, emsg)
32 new | only!
33 endfor
34 set ls&vim
35endfunc
36
Bram Moolenaar5d2ca042016-06-26 17:11:21 +020037function Test_window_cmd_wincmd_gf()
38 let fname = 'test_gf.txt'
39 let swp_fname = '.' . fname . '.swp'
40 call writefile([], fname)
41 call writefile([], swp_fname)
42 function s:swap_exists()
43 let v:swapchoice = s:swap_choice
44 endfunc
45 augroup test_window_cmd_wincmd_gf
46 autocmd!
47 exec "autocmd SwapExists " . fname . " call s:swap_exists()"
48 augroup END
49
50 call setline(1, fname)
51 " (E)dit anyway
52 let s:swap_choice = 'e'
53 wincmd gf
54 call assert_equal(2, tabpagenr())
55 call assert_equal(fname, bufname("%"))
56 quit!
57
58 " (Q)uit
59 let s:swap_choice = 'q'
60 wincmd gf
61 call assert_equal(1, tabpagenr())
62 call assert_notequal(fname, bufname("%"))
63 new | only!
64
65 call delete(fname)
66 call delete(swp_fname)
67 augroup! test_window_cmd_wincmd_gf
68endfunc
69
Bram Moolenaar4520d442017-03-19 16:09:46 +010070func 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
82endfunc
83
84func 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
93endfunc
94
95func 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
104endfunc
105
106func 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
115endfunc
116
117func 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:')
133endfunc
134
135func 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
177endfunc
178
179func 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
213endfunc
214
215func 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
266endfunc
267
268func 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
325endfunc
326
327func 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!
350endfunc
351
352func 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!
367endfunc
368
Bram Moolenaarf79225e2017-03-18 23:11:04 +0100369func Test_next_split_all()
370 " This was causing an illegal memory access.
371 n x
372 norm axxx
373 split
374 split
375 s/x
376 s/x
377 all
378 bwipe!
379endfunc
380
Bram Moolenaar9e4d8212016-08-18 23:04:48 +0200381" vim: shiftwidth=2 sts=2 expandtab