comparison src/testdir/test_window_cmd.vim @ 11197:7f355d8cd634 v8.0.0485

patch 8.0.0485: not all windows commands are tested commit https://github.com/vim/vim/commit/4520d440c59034452d1450b27fcd56825c090687 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Mar 19 16:09:46 2017 +0100 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.
author Christian Brabandt <cb@256bit.org>
date Sun, 19 Mar 2017 16:15:04 +0100
parents 75ccc8a15a51
children e6140f3d2be7
comparison
equal deleted inserted replaced
11196:38c23a67011d 11197:7f355d8cd634
65 call delete(fname) 65 call delete(fname)
66 call delete(swp_fname) 66 call delete(swp_fname)
67 augroup! test_window_cmd_wincmd_gf 67 augroup! test_window_cmd_wincmd_gf
68 endfunc 68 endfunc
69 69
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
70 func Test_next_split_all() 369 func Test_next_split_all()
71 " This was causing an illegal memory access. 370 " This was causing an illegal memory access.
72 n x 371 n x
73 norm axxx 372 norm axxx
74 split 373 split