comparison src/testdir/test_tabpage.vim @ 10739:380e706814da v8.0.0259

patch 8.0.0259: tab commands do not handle count correctly commit https://github.com/vim/vim/commit/2f72c70657129c16e6b0e413752a775c804f02f8 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jan 29 14:48:10 2017 +0100 patch 8.0.0259: tab commands do not handle count correctly Problem: Tab commands do not handle count correctly. (Ken Hamada) Solution: Add ADDR_TABS_RELATIVE. (Hirohito Higashi)
author Christian Brabandt <cb@256bit.org>
date Sun, 29 Jan 2017 15:00:05 +0100
parents 262f5bc3d38e
children 70bc7b107610
comparison
equal deleted inserted replaced
10738:e0a99b268f88 10739:380e706814da
92 call assert_equal(3, tabpagenr()) 92 call assert_equal(3, tabpagenr())
93 tabmove +4 93 tabmove +4
94 call assert_equal(7, tabpagenr()) 94 call assert_equal(7, tabpagenr())
95 tabmove 95 tabmove
96 call assert_equal(10, tabpagenr()) 96 call assert_equal(10, tabpagenr())
97 tabmove -20
98 call assert_equal(1, tabpagenr())
99 tabmove +20
100 call assert_equal(10, tabpagenr())
101 0tabmove 97 0tabmove
102 call assert_equal(1, tabpagenr()) 98 call assert_equal(1, tabpagenr())
103 $tabmove 99 $tabmove
104 call assert_equal(10, tabpagenr()) 100 call assert_equal(10, tabpagenr())
105 tabmove 0 101 tabmove 0
108 call assert_equal(10, tabpagenr()) 104 call assert_equal(10, tabpagenr())
109 3tabmove 105 3tabmove
110 call assert_equal(4, tabpagenr()) 106 call assert_equal(4, tabpagenr())
111 7tabmove 5 107 7tabmove 5
112 call assert_equal(5, tabpagenr()) 108 call assert_equal(5, tabpagenr())
109 call assert_fails("99tabmove", 'E16:')
110 call assert_fails("+99tabmove", 'E16:')
111 call assert_fails("-99tabmove", 'E16:')
113 call assert_fails("tabmove foo", 'E474:') 112 call assert_fails("tabmove foo", 'E474:')
113 call assert_fails("tabmove 99", 'E474:')
114 call assert_fails("tabmove +99", 'E474:')
115 call assert_fails("tabmove -99", 'E474:')
116 call assert_fails("tabmove -3+", 'E474:')
117 call assert_fails("tabmove $3", 'E474:')
118 1tabonly!
114 endfunc 119 endfunc
115 120
116 " Test autocommands 121 " Test autocommands
117 function Test_tabpage_with_autocmd() 122 function Test_tabpage_with_autocmd()
118 if !has('autocmd') 123 if !has('autocmd')
119 return 124 return
120 endif 125 endif
121 tabonly!
122 command -nargs=1 -bar C :call add(s:li, '=== ' . <q-args> . ' ===')|<args> 126 command -nargs=1 -bar C :call add(s:li, '=== ' . <q-args> . ' ===')|<args>
123 augroup TestTabpageGroup 127 augroup TestTabpageGroup
124 au! 128 au!
125 autocmd TabEnter * call add(s:li, 'TabEnter') 129 autocmd TabEnter * call add(s:li, 'TabEnter')
126 autocmd WinEnter * call add(s:li, 'WinEnter') 130 autocmd WinEnter * call add(s:li, 'WinEnter')
181 C tabnext 1 185 C tabnext 1
182 call assert_equal(['=== tabnext 1 ===', 'BufLeave', 'WinLeave', 'TabLeave', 'WinEnter', 'TabEnter', 'BufEnter'], s:li) 186 call assert_equal(['=== tabnext 1 ===', 'BufLeave', 'WinLeave', 'TabLeave', 'WinEnter', 'TabEnter', 'BufEnter'], s:li)
183 187
184 autocmd TabDestructive TabEnter * nested :C tabnext 2 | C tabclose 3 188 autocmd TabDestructive TabEnter * nested :C tabnext 2 | C tabclose 3
185 let s:li = [] 189 let s:li = []
186 C tabnext 3 190 call assert_equal(3, tabpagenr('$'))
187 call assert_equal(['=== tabnext 3 ===', 'BufLeave', 'WinLeave', 'TabLeave', 'WinEnter', 'TabEnter', '=== tabnext 2 ===', 'BufLeave', 'WinLeave', 'TabLeave', 'WinEnter', 'TabEnter', '=== tabnext 2 ===', '=== tabclose 3 ===', 'BufEnter', '=== tabclose 3 ==='], s:li) 191 C tabnext 2
192 call assert_equal(2, tabpagenr('$'))
193 call assert_equal(['=== tabnext 2 ===', 'WinLeave', 'TabLeave', 'WinEnter', 'TabEnter', '=== tabnext 2 ===', '=== tabclose 3 ==='], s:li)
188 call assert_equal(['2/2'], [tabpagenr().'/'.tabpagenr('$')]) 194 call assert_equal(['2/2'], [tabpagenr().'/'.tabpagenr('$')])
189 195
190 delcommand C 196 delcommand C
191 autocmd! TabDestructive 197 autocmd! TabDestructive
192 augroup! TabDestructive 198 augroup! TabDestructive
193 autocmd! TestTabpageGroup 199 autocmd! TestTabpageGroup
194 augroup! TestTabpageGroup 200 augroup! TestTabpageGroup
195 tabonly! 201 1tabonly!
196 bw!
197 endfunction 202 endfunction
198 203
199 function Test_tabpage_with_tab_modifier() 204 function Test_tabpage_with_tab_modifier()
200 for n in range(4) 205 for n in range(4)
201 tabedit 206 tabedit
222 call assert_fails('99tab help', 'E16:') 227 call assert_fails('99tab help', 'E16:')
223 call assert_fails('+99tab help', 'E16:') 228 call assert_fails('+99tab help', 'E16:')
224 call assert_fails('-99tab help', 'E16:') 229 call assert_fails('-99tab help', 'E16:')
225 230
226 delfunction s:check_tab 231 delfunction s:check_tab
227 tabonly! 232 1tabonly!
228 bw! 233 endfunction
234
235 function Check_tab_count(pre_nr, cmd, post_nr)
236 exec 'tabnext' a:pre_nr
237 normal! G
238 exec a:cmd
239 call assert_equal(a:post_nr, tabpagenr(), a:cmd)
240 endfunc
241
242 " Test for [count] of tabnext
243 function Test_tabpage_with_tabnext()
244 for n in range(4)
245 tabedit
246 call setline(1, ['', '', '3'])
247 endfor
248
249 call Check_tab_count(1, 'tabnext', 2)
250 call Check_tab_count(1, '3tabnext', 3)
251 call Check_tab_count(1, '.tabnext', 1)
252 call Check_tab_count(1, '.+1tabnext', 2)
253 call Check_tab_count(2, '+tabnext', 3)
254 call Check_tab_count(2, '+2tabnext', 4)
255 call Check_tab_count(4, '-tabnext', 3)
256 call Check_tab_count(4, '-2tabnext', 2)
257 call Check_tab_count(3, '$tabnext', 5)
258 call assert_fails('0tabnext', 'E16:')
259 call assert_fails('99tabnext', 'E16:')
260 call assert_fails('+99tabnext', 'E16:')
261 call assert_fails('-99tabnext', 'E16:')
262 call Check_tab_count(1, 'tabnext 3', 3)
263 call Check_tab_count(2, 'tabnext +', 3)
264 call Check_tab_count(2, 'tabnext +2', 4)
265 call Check_tab_count(4, 'tabnext -', 3)
266 call Check_tab_count(4, 'tabnext -2', 2)
267 call Check_tab_count(3, 'tabnext $', 5)
268 call assert_fails('tabnext 0', 'E474:')
269 call assert_fails('tabnext .', 'E474:')
270 call assert_fails('tabnext -+', 'E474:')
271 call assert_fails('tabnext +2-', 'E474:')
272 call assert_fails('tabnext $3', 'E474:')
273 call assert_fails('tabnext 99', 'E474:')
274 call assert_fails('tabnext +99', 'E474:')
275 call assert_fails('tabnext -99', 'E474:')
276
277 1tabonly!
278 endfunction
279
280 " Test for [count] of tabprevious
281 function Test_tabpage_with_tabprevious()
282 for n in range(5)
283 tabedit
284 call setline(1, ['', '', '3'])
285 endfor
286
287 for cmd in ['tabNext', 'tabprevious']
288 call Check_tab_count(6, cmd, 5)
289 call Check_tab_count(6, '3' . cmd, 3)
290 call Check_tab_count(6, '8' . cmd, 4)
291 call Check_tab_count(6, cmd . ' 3', 3)
292 call Check_tab_count(6, cmd . ' 8', 4)
293 for n in range(2)
294 for c in ['0', '.+3', '+', '+2' , '-', '-2' , '$', '+99', '-99']
295 if n == 0 " pre count
296 let entire_cmd = c . cmd
297 let err_code = 'E16:'
298 else
299 let entire_cmd = cmd . ' ' . c
300 let err_code = 'E474:'
301 endif
302 call assert_fails(entire_cmd, err_code)
303 endfor
304 endfor
305 endfor
306
307 1tabonly!
308 endfunction
309
310 function s:reconstruct_tabpage_for_test(nr)
311 let n = (a:nr > 2) ? a:nr - 2 : 1
312 1tabonly!
313 0tabedit n0
314 for n in range(1, n)
315 exec '$tabedit n' . n
316 if n == 1
317 call setline(1, ['', '', '3'])
318 endif
319 endfor
320 endfunc
321
322 " Test for [count] of tabclose
323 function Test_tabpage_with_tabclose()
324
325 " pre count
326 call s:reconstruct_tabpage_for_test(6)
327 call Check_tab_count(3, 'tabclose!', 3)
328 call Check_tab_count(1, '3tabclose', 1)
329 call Check_tab_count(4, '4tabclose', 3)
330 call Check_tab_count(3, '1tabclose', 2)
331 call Check_tab_count(2, 'tabclose', 1)
332 call assert_equal(1, tabpagenr('$'))
333 call assert_equal('', bufname(''))
334
335 call s:reconstruct_tabpage_for_test(6)
336 call Check_tab_count(2, '$tabclose', 2)
337 call Check_tab_count(4, '.tabclose', 4)
338 call Check_tab_count(3, '.+tabclose', 3)
339 call Check_tab_count(3, '.-2tabclose', 2)
340 call Check_tab_count(1, '.+1tabclose!', 1)
341 call assert_equal(1, tabpagenr('$'))
342 call assert_equal('', bufname(''))
343
344 " post count
345 call s:reconstruct_tabpage_for_test(6)
346 call Check_tab_count(3, 'tabclose!', 3)
347 call Check_tab_count(1, 'tabclose 3', 1)
348 call Check_tab_count(4, 'tabclose 4', 3)
349 call Check_tab_count(3, 'tabclose 1', 2)
350 call Check_tab_count(2, 'tabclose', 1)
351 call assert_equal(1, tabpagenr('$'))
352 call assert_equal('', bufname(''))
353
354 call s:reconstruct_tabpage_for_test(6)
355 call Check_tab_count(2, 'tabclose $', 2)
356 call Check_tab_count(4, 'tabclose', 4)
357 call Check_tab_count(3, 'tabclose +', 3)
358 call Check_tab_count(3, 'tabclose -2', 2)
359 call Check_tab_count(1, 'tabclose! +1', 1)
360 call assert_equal(1, tabpagenr('$'))
361 call assert_equal('', bufname(''))
362
363 call s:reconstruct_tabpage_for_test(6)
364 for n in range(2)
365 for c in ['0', '$3', '99', '+99', '-99']
366 if n == 0 " pre count
367 let entire_cmd = c . 'tabclose'
368 let err_code = 'E16:'
369 else
370 let entire_cmd = 'tabclose ' . c
371 let err_code = 'E474:'
372 endif
373 call assert_fails(entire_cmd, err_code)
374 call assert_equal(6, tabpagenr('$'))
375 endfor
376 endfor
377
378 call assert_fails('3tabclose', 'E37:')
379 call assert_fails('tabclose 3', 'E37:')
380 call assert_fails('tabclose -+', 'E474:')
381 call assert_fails('tabclose +2-', 'E474:')
382 call assert_equal(6, tabpagenr('$'))
383
384 1tabonly!
385 endfunction
386
387 " Test for [count] of tabonly
388 function Test_tabpage_with_tabonly()
389
390 " Test for the normal behavior (pre count only)
391 let tc = [ [4, '.', '!'], [2, '.+', ''], [3, '.-2', '!'], [1, '.+1', '!'] ]
392 for c in tc
393 call s:reconstruct_tabpage_for_test(6)
394 let entire_cmd = c[1] . 'tabonly' . c[2]
395 call Check_tab_count(c[0], entire_cmd, 1)
396 call assert_equal(1, tabpagenr('$'))
397 endfor
398
399 " Test for the normal behavior
400 let tc2 = [ [3, '', ''], [1, '3', ''], [4, '4', '!'], [3, '1', '!'],
401 \ [2, '', '!'],
402 \ [2, '$', '!'], [3, '+', '!'], [3, '-2', '!'], [3, '+1', '!']
403 \ ]
404 for n in range(2)
405 for c in tc2
406 call s:reconstruct_tabpage_for_test(6)
407 if n == 0 " pre count
408 let entire_cmd = c[1] . 'tabonly' . c[2]
409 else
410 let entire_cmd = 'tabonly' . c[2] . ' ' . c[1]
411 endif
412 call Check_tab_count(c[0], entire_cmd, 1)
413 call assert_equal(1, tabpagenr('$'))
414 endfor
415 endfor
416
417 " Test for the error behavior
418 for n in range(2)
419 for c in ['0', '$3', '99', '+99', '-99']
420 call s:reconstruct_tabpage_for_test(6)
421 if n == 0 " pre count
422 let entire_cmd = c . 'tabonly'
423 let err_code = 'E16:'
424 else
425 let entire_cmd = 'tabonly ' . c
426 let err_code = 'E474:'
427 endif
428 call assert_fails(entire_cmd, err_code)
429 call assert_equal(6, tabpagenr('$'))
430 endfor
431 endfor
432
433 " Test for the error behavior (post count only)
434 for c in tc
435 call s:reconstruct_tabpage_for_test(6)
436 let entire_cmd = 'tabonly' . c[2] . ' ' . c[1]
437 let err_code = 'E474:'
438 call assert_fails(entire_cmd, err_code)
439 call assert_equal(6, tabpagenr('$'))
440 endfor
441
442 call assert_fails('tabonly -+', 'E474:')
443 call assert_fails('tabonly +2-', 'E474:')
444 call assert_equal(6, tabpagenr('$'))
445
446 1tabonly!
447 new
448 only!
229 endfunction 449 endfunction
230 450
231 func Test_tabnext_on_buf_unload1() 451 func Test_tabnext_on_buf_unload1()
232 " This once caused a crash 452 " This once caused a crash
233 new 453 new