robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
5d5b8e3e7d
master
1" Tests for tabpage 2 3source screendump.vim 4source check.vim 5 6function Test_tabpage () 7CheckFeature quickfix 8 9bw ! 10" Simple test for opening and closing a tab page 11tabnew 12call assert_equal ( 2 , tabpagenr ()) 13quit 14 15" Open three tab pages and use ":tabdo" 160 tabnew 171 tabnew 18$ tabnew 19 %del 20tabdo call append(line('$'), tabpagenr()) 21tabclose ! 2 22tabrewind 23let line1 = getline ( '$' ) 24undo 25q 26tablast 27let line2 = getline ( '$' ) 28q ! 29call append ( line ( '$' ), line1 ) 30call append ( line ( '$' ), line2 ) 31unlet line1 line2 32call assert_equal ([ '' , '3' , '1' , '4' ], getline ( 1 , '$' )) 33" 34" Test for settabvar() and gettabvar() functions. Open a new tab page and 35" set 3 variables to a number, string and a list. Verify that the variables 36" are correctly set. 37tabnew 38tabfirst 39call settabvar ( 2 , 'val_num' , 100 ) 40eval 'SetTabVar test' ->settabvar ( 2 , 'val_str' ) 41call settabvar ( 2 , 'val_list' , [ 'red' , 'blue' , 'green' ]) 42" 43call assert_true ( gettabvar ( 2 , 'val_num' ) == 100 && gettabvar ( 2 , 'val_str' ) == 'SetTabVar test' && gettabvar ( 2 , 'val_list' ) == [ 'red' , 'blue' , 'green' ]) 44 45tabnext 2 46call assert_true ( t: val_num == 100 && t: val_str == 'SetTabVar test' && t: val_list == [ 'red' , 'blue' , 'green' ]) 47tabclose 48 49" Test for ":tab drop exist-file" to keep current window. 50sp test1 51tab drop test1 52call assert_true ( tabpagenr ( '$' ) == 1 && winnr ( '$' ) == 2 && winnr () == 1 ) 53close 54" 55" 56" Test for ":tab drop new-file" to keep current window of tabpage 1. 57split 58tab drop newfile 59call assert_true ( tabpagenr ( '$' ) == 2 && tabpagewinnr ( 1 , '$' ) == 2 && tabpagewinnr ( 1 ) == 1 ) 60tabclose 61q 62" 63" 64" Test for ":tab drop multi-opened-file" to keep current tabpage and window. 65new test1 66tabnew 67new test1 68tab drop test1 69call assert_true ( tabpagenr () == 2 && tabpagewinnr ( 2 , '$' ) == 2 && tabpagewinnr ( 2 ) == 1 ) 70tabclose 71q 72" 73" 74" Test for ":tab drop vertical-split-window" to jump test1 buffer 75tabedit test1 76vnew 77tabfirst 78tab drop test1 79call assert_equal ([ 2 , 2 , 2 , 2 ], [ tabpagenr ( '$' ), tabpagenr (), tabpagewinnr ( 2 , '$' ), tabpagewinnr ( 2 )]) 801 tabonly 81" 82" 83for i in range ( 9 ) |tabnew |endfor 84normal ! 1gt 85call assert_equal ( 1 , tabpagenr ()) 86tabmove 5 87call assert_equal ( 5 , tabpagenr ()) 88 .tabmove 89call assert_equal ( 5 , tabpagenr ()) 90tabmove - 91call assert_equal ( 4 , tabpagenr ()) 92tabmove + 93call assert_equal ( 5 , tabpagenr ()) 94tabmove -2 95call assert_equal ( 3 , tabpagenr ()) 96tabmove +4 97call assert_equal ( 7 , tabpagenr ()) 98tabmove 99call assert_equal ( 10 , tabpagenr ()) 1000 tabmove 101call assert_equal ( 1 , tabpagenr ()) 102$ tabmove 103call assert_equal ( 10 , tabpagenr ()) 104tabmove 0 105call assert_equal ( 1 , tabpagenr ()) 106tabmove $ 107call assert_equal ( 10 , tabpagenr ()) 1083 tabmove 109call assert_equal ( 4 , tabpagenr ()) 1107 tabmove 5 111call assert_equal ( 5 , tabpagenr ()) 112 -tabmove 113call assert_equal ( 4 , tabpagenr ()) 114+ tabmove 115call assert_equal ( 5 , tabpagenr ()) 116-2 tabmove 117call assert_equal ( 3 , tabpagenr ()) 118+3 tabmove 119call assert_equal ( 6 , tabpagenr ()) 120silent -tabmove 121call assert_equal ( 5 , tabpagenr ()) 122silent -2 tabmove 123call assert_equal ( 3 , tabpagenr ()) 124silent -2 tabmove 125call assert_equal ( 1 , tabpagenr ()) 126 127norm ! 2gt 128call assert_equal ( 2 , tabpagenr ()) 129" The following are a no-op 130tabmove 2 131call assert_equal ( 2 , tabpagenr ()) 1322 tabmove 133call assert_equal ( 2 , tabpagenr ()) 134tabmove 1 135call assert_equal ( 2 , tabpagenr ()) 1361 tabmove 137call assert_equal ( 2 , tabpagenr ()) 138 139call assert_fails ( 'let t = tabpagenr("@")' , 'E15:' ) 140call assert_equal ( 0 , tabpagewinnr ( -1 )) 141call assert_fails ( "99tabmove" , 'E16:' ) 142call assert_fails ( "+99tabmove" , 'E16:' ) 143call assert_fails ( "-99tabmove" , 'E16:' ) 144call assert_fails ( "tabmove foo" , 'E475:' ) 145call assert_fails ( "tabmove 99" , 'E475:' ) 146call assert_fails ( "tabmove +99" , 'E475:' ) 147call assert_fails ( "tabmove -99" , 'E475:' ) 148call assert_fails ( "tabmove -3+" , 'E475:' ) 149call assert_fails ( "tabmove $3" , 'E475:' ) 150call assert_fails ( "%tabonly" , 'E16:' ) 1511 tabonly ! 152tabmove 1 153call assert_equal ( 1 , tabpagenr ()) 154tabnew 155call assert_fails ( "-2tabmove" , 'E16:' ) 156tabonly ! 157endfunc 158 159func Test_tabpage_drop () 160edit f1 161tab split f2 162tab split f3 163normal ! gt 164call assert_equal ( 1 , tabpagenr ()) 165tab drop f4 166call assert_equal ( 1 , tabpagenr ( '#' )) 167 168tab drop f3 169call assert_equal ( 4 , tabpagenr ()) 170call assert_equal ( 2 , tabpagenr ( '#' )) 171bwipe ! 172bwipe ! 173bwipe ! 174bwipe ! 175call assert_equal ( 1 , tabpagenr ( '$' )) 176 177call assert_equal ( 1 , winnr ( '$' )) 178call assert_equal ( '' , bufname ( '' )) 179call writefile ([ 'L1' , 'L2' ], 'Xdropfile' , 'D' ) 180 181" Test for ':tab drop single-file': reuse current buffer 182let expected_nr = bufnr () 183tab drop Xdropfile 184call assert_equal ( 1 , tabpagenr ( '$' )) 185call assert_equal ( expected_nr , bufnr ()) 186call assert_equal ( 'L2' , getline ( 2 )) 187bwipe ! 188 189" Test for ':tab drop single-file': not reuse modified buffer 190set modified 191let expected_nr = bufnr () + 1 192tab drop Xdropfile 193call assert_equal ( 2 , tabpagenr ()) 194call assert_equal ( 2 , tabpagenr ( '$' )) 195call assert_equal ( expected_nr , bufnr ()) 196call assert_equal ( 'L2' , getline ( 2 )) 197bwipe ! 198 199" Test for ':tab drop single-file': multiple tabs already exist 200tab split f2 201tab split f3 202let expected_nr = bufnr () + 1 203tab drop Xdropfile 204call assert_equal ( 4 , tabpagenr ()) 205call assert_equal ( 4 , tabpagenr ( '$' )) 206call assert_equal ( expected_nr , bufnr ()) 207call assert_equal ( 'L2' , getline ( 2 )) 208 %bwipe ! 209 210" Test for ':tab drop multi-files': reuse current buffer 211let expected_nr = bufnr () 212tab drop Xdropfile f1 f2 f3 213call assert_equal ( 1 , tabpagenr ()) 214call assert_equal ( 4 , tabpagenr ( '$' )) 215call assert_equal ( expected_nr , bufnr ()) 216call assert_equal ( 'L2' , getline ( 2 )) 217 %bwipe ! 218 219" Test for ':tab drop multi-files': not reuse modified buffer 220set modified 221let expected_nr = bufnr () + 1 222tab drop Xdropfile f1 f2 f3 223call assert_equal ( 2 , tabpagenr ()) 224call assert_equal ( 5 , tabpagenr ( '$' )) 225call assert_equal ( expected_nr , bufnr ()) 226call assert_equal ( 'L2' , getline ( 2 )) 227 %bwipe ! 228 229" Test for ':tab drop multi-files': multiple tabs already exist 230tab split f2 231tab split f3 232let expected_nr = bufnr () + 1 233tab drop a b c 234call assert_equal ( 4 , tabpagenr ()) 235call assert_equal ( 6 , tabpagenr ( '$' )) 236call assert_equal ( expected_nr , bufnr ()) 237let expected_nr = bufnr () + 3 238tab drop Xdropfile f1 f2 f3 239call assert_equal ( 5 , tabpagenr ()) 240call assert_equal ( 8 , tabpagenr ( '$' )) 241call assert_equal ( expected_nr , bufnr ()) 242call assert_equal ( 'L2' , getline ( 2 )) 243 %bwipe ! 244endfunc 245 246" Test autocommands 247function Test_tabpage_with_autocmd () 248command -nargs = 1 -bar C :call add(s:li, '=== ' . <q-args> . ' ===')|<args> 249augroup TestTabpageGroup 250au ! 251autocmd TabEnter * call add ( s: li , 'TabEnter' ) 252autocmd WinEnter * call add ( s: li , 'WinEnter' ) 253autocmd BufEnter * call add ( s: li , 'BufEnter' ) 254autocmd TabLeave * call add ( s: li , 'TabLeave' ) 255autocmd WinLeave * call add ( s: li , 'WinLeave' ) 256autocmd BufLeave * call add ( s: li , 'BufLeave' ) 257augroup END 258 259let s: li = [] 260let t: a = 'a' 261C tab split 262call assert_equal ([ '=== tab split ===' , 'WinLeave' , 'TabLeave' , 'WinEnter' , 'TabEnter' ], s: li ) 263let s: li = [] 264let t: a = 'b' 265C tabnew 266call assert_equal ([ '=== tabnew ===' , 'WinLeave' , 'TabLeave' , 'WinEnter' , 'TabEnter' , 'BufLeave' , 'BufEnter' ], s: li ) 267let t: a = 'c' 268let s: li = split ( join ( map ( range ( 1 , tabpagenr ( '$' )), 'gettabvar(v:val, "a")' )) , '\s\+' ) 269call assert_equal ([ 'a' , 'b' , 'c' ], s: li ) 270 271let s: li = [] 272C call map(range(1, tabpagenr('$')),'settabvar(v:val, ''a'', v:val*2)' ) 273call assert_equal ([ "=== call map(range(1, tabpagenr('$')), 'settabvar(v:val, ''a'', v:val*2)') ===" ], s: li ) 274let s: li = split ( join ( map ( range ( 1 , tabpagenr ( '$' )), 'gettabvar(v:val, "a")' )) , '\s\+' ) 275call assert_equal ([ '2' , '4' , '6' ], s: li ) 276 277let s: li = [] 278let w: a = 'a' 279C vsplit 280call assert_equal ([ '=== vsplit ===' , 'WinLeave' , 'WinEnter' ], s: li ) 281let s: li = [] 282let w: a = 'a' 283let tabn = tabpagenr () 284let winr = range ( 1 , winnr ( '$' )) 285C tabnext 1 286call assert_equal ([ '=== tabnext 1 ===' , 'BufLeave' , 'WinLeave' , 'TabLeave' , 'WinEnter' , 'TabEnter' , 'BufEnter' ], s: li ) 287let s: li = split ( join ( map ( copy ( winr ), 'gettabwinvar(' . tabn . ', v:val, "a")' )), '\s\+' ) 288call assert_equal ([ 'a' , 'a' ], s: li ) 289let s: li = [] 290C call map(copy(winr),'(v:val*2)->settabwinvar(' .. tabn ..', v:val, ''a'')' ) 291let s: li = split ( join ( map ( copy ( winr ), 'gettabwinvar(' . tabn . ', v:val, "a")' )), '\s\+' ) 292call assert_equal ([ '2' , '4' ], s: li ) 293 294augroup TabDestructive 295autocmd TabEnter * : C tabnext 2 |C tabclose 3 296augroup END 297let s: li = [] 298C tabnext 3 299call assert_equal ([ '=== tabnext 3 ===' , 'BufLeave' , 'WinLeave' , 'TabLeave' , 'WinEnter' , 'TabEnter' , '=== tabnext 2 ===' , '=== tabclose 3 ===' ], s: li ) 300call assert_equal ([ '2/2' ], [ tabpagenr () . '/' . tabpagenr ( '$' )]) 301 302autocmd ! TabDestructive TabEnter 303let s: li = [] 304C tabnew 305call assert_equal ([ '=== tabnew ===' , 'WinLeave' , 'TabLeave' , 'WinEnter' , 'TabEnter' , 'BufLeave' , 'BufEnter' ], s: li ) 306let s: li = [] 307C tabnext 1 308call assert_equal ([ '=== tabnext 1 ===' , 'BufLeave' , 'WinLeave' , 'TabLeave' , 'WinEnter' , 'TabEnter' , 'BufEnter' ], s: li ) 309 310autocmd TabDestructive TabEnter * nested :C tabnext 2 |C tabclose 3 311let s: li = [] 312call assert_equal ( 3 , tabpagenr ( '$' )) 313C tabnext 2 314call assert_equal ( 2 , tabpagenr ( '$' )) 315call assert_equal ([ '=== tabnext 2 ===' , 'WinLeave' , 'TabLeave' , 'WinEnter' , 'TabEnter' , '=== tabnext 2 ===' , '=== tabclose 3 ===' ], s: li ) 316call assert_equal ([ '2/2' ], [ tabpagenr () . '/' . tabpagenr ( '$' )]) 317 318delcommand C 319autocmd ! TabDestructive 320augroup ! TabDestructive 321autocmd ! TestTabpageGroup 322augroup ! TestTabpageGroup 3231 tabonly ! 324endfunction 325 326" Test autocommands on tab drop 327function Test_tabpage_with_autocmd_tab_drop () 328augroup TestTabpageGroup 329au ! 330autocmd TabEnter * call add ( s: li , 'TabEnter' ) 331autocmd WinEnter * call add ( s: li , 'WinEnter' ) 332autocmd BufEnter * call add ( s: li , 'BufEnter' ) 333autocmd TabLeave * call add ( s: li , 'TabLeave' ) 334autocmd WinLeave * call add ( s: li , 'WinLeave' ) 335autocmd BufLeave * call add ( s: li , 'BufLeave' ) 336augroup END 337 338let s: li = [] 339tab drop test1 340call assert_equal ([ 'BufEnter' ], s: li ) 341 342let s: li = [] 343tab drop test2 test3 344call assert_equal ([ 345 \'TabLeave' , 'TabEnter' , 'TabLeave' , 'TabEnter' , 346 \'TabLeave' , 'WinEnter' , 'TabEnter' , 'BufEnter' , 347 \'TabLeave' , 'WinEnter' , 'TabEnter' , 'BufEnter' , 'BufEnter' ], s: li ) 348 349autocmd ! TestTabpageGroup 350augroup ! TestTabpageGroup 3511 tabonly ! 352endfunction 353 354function Test_tabpage_with_tab_modifier () 355CheckFeature quickfix 356 357for n in range ( 4 ) 358tabedit 359endfor 360 361function s: check_tab ( pre_nr , cmd , post_nr ) 362exec 'tabnext ' . a: pre_nr 363exec a: cmd 364call assert_equal ( a: post_nr , tabpagenr ()) 365call assert_equal ( 'help' , & buftype ) 366helpclose 367endfunc 368 369call s: check_tab ( 1 , 'tab help' , 2 ) 370call s: check_tab ( 1 , '3tab help' , 4 ) 371call s: check_tab ( 1 , '.tab help' , 2 ) 372call s: check_tab ( 1 , '.+1tab help' , 3 ) 373call s: check_tab ( 1 , '0tab help' , 1 ) 374call s: check_tab ( 2 , '+tab help' , 4 ) 375call s: check_tab ( 2 , '+2tab help' , 5 ) 376call s: check_tab ( 4 , '-tab help' , 4 ) 377call s: check_tab ( 4 , '-2tab help' , 3 ) 378call s: check_tab ( 3 , '$tab help' , 6 ) 379call assert_fails ( '99tab help' , 'E16:' ) 380call assert_fails ( '+99tab help' , 'E16:' ) 381call assert_fails ( '-99tab help' , 'E16:' ) 382 383delfunction s:check_tab 3841 tabonly ! 385endfunction 386 387function Check_tab_count ( pre_nr , cmd , post_nr ) 388exec 'tabnext' a: pre_nr 389normal ! G 390exec a: cmd 391call assert_equal ( a: post_nr , tabpagenr (), a: cmd ) 392endfunc 393 394" Test for [count] of tabnext 395function Test_tabpage_with_tabnext () 396for n in range ( 4 ) 397tabedit 398call setline ( 1 , [ '' , '' , '3' ]) 399endfor 400 401call Check_tab_count ( 1 , 'tabnext' , 2 ) 402call Check_tab_count ( 1 , '3tabnext' , 3 ) 403call Check_tab_count ( 1 , '.tabnext' , 1 ) 404call Check_tab_count ( 1 , '.+1tabnext' , 2 ) 405call Check_tab_count ( 2 , '+tabnext' , 3 ) 406call Check_tab_count ( 2 , '+2tabnext' , 4 ) 407call Check_tab_count ( 4 , '-tabnext' , 3 ) 408call Check_tab_count ( 4 , '-2tabnext' , 2 ) 409call Check_tab_count ( 3 , '$tabnext' , 5 ) 410call assert_fails ( '0tabnext' , 'E16:' ) 411call assert_fails ( '99tabnext' , 'E16:' ) 412call assert_fails ( '+99tabnext' , 'E16:' ) 413call assert_fails ( '-99tabnext' , 'E16:' ) 414call Check_tab_count ( 1 , 'tabnext 3' , 3 ) 415call Check_tab_count ( 2 , 'tabnext +' , 3 ) 416call Check_tab_count ( 2 , 'tabnext +2' , 4 ) 417call Check_tab_count ( 4 , 'tabnext -' , 3 ) 418call Check_tab_count ( 4 , 'tabnext -2' , 2 ) 419call Check_tab_count ( 3 , 'tabnext $' , 5 ) 420call assert_fails ( 'tabnext 0' , 'E475:' ) 421call assert_fails ( 'tabnext .' , 'E475:' ) 422call assert_fails ( 'tabnext -+' , 'E475:' ) 423call assert_fails ( 'tabnext +2-' , 'E475:' ) 424call assert_fails ( 'tabnext $3' , 'E475:' ) 425call assert_fails ( 'tabnext 99' , 'E475:' ) 426call assert_fails ( 'tabnext +99' , 'E475:' ) 427call assert_fails ( 'tabnext -99' , 'E475:' ) 428 4291 tabonly ! 430endfunction 431 432" Test for [count] of tabprevious 433function Test_tabpage_with_tabprevious () 434for n in range ( 5 ) 435tabedit 436call setline ( 1 , [ '' , '' , '3' ]) 437endfor 438 439for cmd in [ 'tabNext' , 'tabprevious' ] 440call Check_tab_count ( 6 , cmd , 5 ) 441call Check_tab_count ( 6 , '3' . cmd , 3 ) 442call Check_tab_count ( 6 , '8' . cmd , 4 ) 443call Check_tab_count ( 6 , cmd . ' 3' , 3 ) 444call Check_tab_count ( 6 , cmd . ' 8' , 4 ) 445for n in range ( 2 ) 446for c in [ '0' , '.+3' , '+' , '+2' , '-' , '-2' , '$' , '+99' , '-99' ] 447if n == 0 " pre count 448let entire_cmd = c . cmd 449let err_code = 'E16:' 450else 451let entire_cmd = cmd . ' ' . c 452let err_code = 'E475:' 453endif 454call assert_fails ( entire_cmd , err_code ) 455endfor 456endfor 457endfor 458 4591 tabonly ! 460endfunction 461 462function s: reconstruct_tabpage_for_test ( nr ) 463let n = ( a: nr > 2 ) ? a: nr - 2 : 1 4641 tabonly ! 4650 tabedit n0 466for n in range ( 1 , n ) 467exec '$tabedit n' . n 468if n == 1 469call setline ( 1 , [ '' , '' , '3' ]) 470endif 471endfor 472endfunc 473 474func Test_tabpage_ctrl_pgup_pgdown () 475enew ! 476tabnew tab1 477tabnew tab2 478 479call assert_equal ( 3 , tabpagenr ()) 480exe "norm! \<C-PageUp>" 481call assert_equal ( 2 , tabpagenr ()) 482exe "norm! \<C-PageDown>" 483call assert_equal ( 3 , tabpagenr ()) 484 485" Check wrapping at last or first page. 486exe "norm! \<C-PageDown>" 487call assert_equal ( 1 , tabpagenr ()) 488exe "norm! \<C-PageUp>" 489call assert_equal ( 3 , tabpagenr ()) 490 491" With a count, <C-PageUp> and <C-PageDown> are not symmetrical somehow: 492" - {count}<C-PageUp> goes {count} pages downward (relative count) 493" - {count}<C-PageDown> goes to page number {count} (absolute count) 494exe "norm! 2\<C-PageUp>" 495call assert_equal ( 1 , tabpagenr ()) 496exe "norm! 2\<C-PageDown>" 497call assert_equal ( 2 , tabpagenr ()) 498 4991 tabonly ! 500endfunc 501 502" Test for [count] of tabclose 503function Test_tabpage_with_tabclose () 504 505" pre count 506call s: reconstruct_tabpage_for_test ( 6 ) 507call Check_tab_count ( 3 , 'tabclose!' , 3 ) 508call Check_tab_count ( 1 , '3tabclose' , 1 ) 509call Check_tab_count ( 4 , '4tabclose' , 3 ) 510call Check_tab_count ( 3 , '1tabclose' , 2 ) 511call Check_tab_count ( 2 , 'tabclose' , 1 ) 512call assert_equal ( 1 , tabpagenr ( '$' )) 513call assert_equal ( '' , bufname ( '' )) 514 515call s: reconstruct_tabpage_for_test ( 6 ) 516call Check_tab_count ( 2 , '$tabclose' , 2 ) 517call Check_tab_count ( 4 , '.tabclose' , 4 ) 518call Check_tab_count ( 3 , '.+tabclose' , 3 ) 519call Check_tab_count ( 3 , '.-2tabclose' , 2 ) 520call Check_tab_count ( 1 , '.+1tabclose!' , 1 ) 521call assert_equal ( 1 , tabpagenr ( '$' )) 522call assert_equal ( '' , bufname ( '' )) 523 524" post count 525call s: reconstruct_tabpage_for_test ( 6 ) 526call Check_tab_count ( 3 , 'tabclose!' , 3 ) 527call Check_tab_count ( 1 , 'tabclose 3' , 1 ) 528call Check_tab_count ( 4 , 'tabclose 4' , 3 ) 529call Check_tab_count ( 3 , 'tabclose 1' , 2 ) 530call Check_tab_count ( 2 , 'tabclose' , 1 ) 531call assert_equal ( 1 , tabpagenr ( '$' )) 532call assert_equal ( '' , bufname ( '' )) 533 534call s: reconstruct_tabpage_for_test ( 6 ) 535call Check_tab_count ( 2 , 'tabclose $' , 2 ) 536call Check_tab_count ( 4 , 'tabclose' , 4 ) 537call Check_tab_count ( 3 , 'tabclose +' , 3 ) 538call Check_tab_count ( 3 , 'tabclose -2' , 2 ) 539call Check_tab_count ( 1 , 'tabclose! +1' , 1 ) 540call assert_equal ( 1 , tabpagenr ( '$' )) 541call assert_equal ( '' , bufname ( '' )) 542 543call s: reconstruct_tabpage_for_test ( 6 ) 544for n in range ( 2 ) 545for c in [ '0' , '$3' , '99' , '+99' , '-99' ] 546if n == 0 " pre count 547let entire_cmd = c . 'tabclose' 548let err_code = 'E16:' 549else 550let entire_cmd = 'tabclose ' . c 551let err_code = 'E475:' 552endif 553call assert_fails ( entire_cmd , err_code ) 554call assert_equal ( 6 , tabpagenr ( '$' )) 555endfor 556endfor 557 558call assert_fails ( '3tabclose' , 'E37:' ) 559call assert_fails ( 'tabclose 3' , 'E37:' ) 560call assert_fails ( 'tabclose -+' , 'E475:' ) 561call assert_fails ( 'tabclose +2-' , 'E475:' ) 562call assert_equal ( 6 , tabpagenr ( '$' )) 563 5641 tabonly ! 565endfunction 566 567" Test for [count] of tabonly 568function Test_tabpage_with_tabonly () 569 570" Test for the normal behavior (pre count only) 571let tc = [ [ 4 , '.' , '!' ], [ 2 , '.+' , '' ], [ 3 , '.-2' , '!' ], [ 1 , '.+1' , '!' ] ] 572for c in tc 573call s: reconstruct_tabpage_for_test ( 6 ) 574let entire_cmd = c [ 1 ] . 'tabonly' . c [ 2 ] 575call Check_tab_count ( c [ 0 ], entire_cmd , 1 ) 576call assert_equal ( 1 , tabpagenr ( '$' )) 577endfor 578 579" Test for the normal behavior 580let tc2 = [ [ 3 , '' , '' ], [ 1 , '3' , '' ], [ 4 , '4' , '!' ], [ 3 , '1' , '!' ], 581 \[ 2 , '' , '!' ], 582 \[ 2 , '$' , '!' ], [ 3 , '+' , '!' ], [ 3 , '-2' , '!' ], [ 3 , '+1' , '!' ] 583 \] 584for n in range ( 2 ) 585for c in tc2 586call s: reconstruct_tabpage_for_test ( 6 ) 587if n == 0 " pre count 588let entire_cmd = c [ 1 ] . 'tabonly' . c [ 2 ] 589else 590let entire_cmd = 'tabonly' . c [ 2 ] . ' ' . c [ 1 ] 591endif 592call Check_tab_count ( c [ 0 ], entire_cmd , 1 ) 593call assert_equal ( 1 , tabpagenr ( '$' )) 594endfor 595endfor 596 597" Test for the error behavior 598for n in range ( 2 ) 599for c in [ '0' , '$3' , '99' , '+99' , '-99' ] 600call s: reconstruct_tabpage_for_test ( 6 ) 601if n == 0 " pre count 602let entire_cmd = c . 'tabonly' 603let err_code = 'E16:' 604else 605let entire_cmd = 'tabonly ' . c 606let err_code = 'E475:' 607endif 608call assert_fails ( entire_cmd , err_code ) 609call assert_equal ( 6 , tabpagenr ( '$' )) 610endfor 611endfor 612 613" Test for the error behavior (post count only) 614for c in tc 615call s: reconstruct_tabpage_for_test ( 6 ) 616let entire_cmd = 'tabonly' . c [ 2 ] . ' ' . c [ 1 ] 617let err_code = 'E475:' 618call assert_fails ( entire_cmd , err_code ) 619call assert_equal ( 6 , tabpagenr ( '$' )) 620endfor 621 622call assert_fails ( 'tabonly -+' , 'E475:' ) 623call assert_fails ( 'tabonly +2-' , 'E475:' ) 624call assert_equal ( 6 , tabpagenr ( '$' )) 625 6261 tabonly ! 627new 628only ! 629endfunction 630 631func Test_tabnext_on_buf_unload1 () 632" This once caused a crash 633new 634tabedit 635tabfirst 636au BufUnload <buffer> tabnext 637q 638 639while tabpagenr ( '$' ) > 1 640bwipe ! 641endwhile 642endfunc 643 644func Test_tabnext_on_buf_unload2 () 645" This once caused a crash 646tabedit 647autocmd BufUnload <buffer> tabnext 648file x 649edit y 650 651while tabpagenr ( '$' ) > 1 652bwipe ! 653endwhile 654endfunc 655 656func Test_close_on_quitpre () 657" This once caused a crash 658edit Xtest 659new 660only 661set bufhidden = delete 662au QuitPre <buffer> close 663tabnew tab1 664tabnew tab2 6651 tabn 666q ! 667call assert_equal ( 1 , tabpagenr ()) 668call assert_equal ( 2 , tabpagenr ( '$' )) 669" clean up 670while tabpagenr ( '$' ) > 1 671bwipe ! 672endwhile 673buf Xtest 674endfunc 675 676func Test_tabs () 677enew ! 678tabnew tab1 679norm ixxx 680let a = split ( execute ( ':tabs' ), "\n" ) 681call assert_equal ([ 'Tab page 1' , 682 \'# [No Name]' , 683 \'Tab page 2' , 684 \'> + tab1' ], a ) 685 6861 tabonly ! 687bw ! 688endfunc 689 690func Test_tabpage_cmdheight () 691CheckScreendump 692CheckRunVimInTerminal 693call writefile ([ 694 \'set laststatus=2' , 695 \'set cmdheight=2' , 696 \'tabnew' , 697 \'set cmdheight=3' , 698 \'tabnext' , 699 \'redraw!' , 700 \'echo "hello\nthere"' , 701 \'tabnext' , 702 \'redraw' , 703 \], 'XTest_tabpage_cmdheight' ) 704" Check that cursor line is concealed 705let buf = RunVimInTerminal ( '-S XTest_tabpage_cmdheight' , { 'statusoff' : 3 }) 706call VerifyScreenDump ( buf , 'Test_tabpage_cmdheight' , {}) 707 708call StopVimInTerminal ( buf ) 709call delete ( 'XTest_tabpage_cmdheight' ) 710endfunc 711 712" Test for closing the tab page from a command window 713func Test_tabpage_close_cmdwin () 714throw 'Skipped: Nvim supports cmdwin freedom #40312' 715tabnew 716call feedkeys ( "q/:tabclose\<CR>\<Esc>" , 'xt' ) 717call assert_equal ( 2 , tabpagenr ( '$' )) 718call feedkeys ( "q/:tabonly\<CR>\<Esc>" , 'xt' ) 719call assert_equal ( 2 , tabpagenr ( '$' )) 720tabonly 721endfunc 722 723" Pressing <C-PageUp> in insert mode should go to the previous tab page 724" and <C-PageDown> should go to the next tab page 725func Test_tabpage_Ctrl_Pageup () 726tabnew 727call feedkeys ( "i\<C-PageUp>" , 'xt' ) 728call assert_equal ( 1 , tabpagenr ()) 729call feedkeys ( "i\<C-PageDown>" , 'xt' ) 730call assert_equal ( 2 , tabpagenr ()) 731 %bw ! 732endfunc 733 734" Return the terminal key code for selecting a tab page from the tabline. This 735" sequence contains the following codes: a CSI (0x9b), KS_TABLINE (0xf0), 736" KS_FILLER (0x58) and then the tab page number. 737func TabLineSelectPageCode ( tabnr ) 738return "\x9b\xf0\x58" .. nr2char ( a: tabnr ) 739endfunc 740 741" Return the terminal key code for opening a new tabpage from the tabpage 742" menu. This sequence consists of the following codes: a CSI (0x9b), 743" KS_TABMENU (0xef), KS_FILLER (0x58), the tab page number and 744" TABLINE_MENU_NEW (2). 745func TabMenuNewItemCode ( tabnr ) 746return "\x9b\xef\x58" .. nr2char ( a: tabnr ) .. nr2char ( 2 ) 747endfunc 748 749" Return the terminal key code for closing a tabpage from the tabpage menu. 750" This sequence consists of the following codes: a CSI (0x9b), KS_TABMENU 751" (0xef), KS_FILLER (0x58), the tab page number and TABLINE_MENU_CLOSE (1). 752func TabMenuCloseItemCode ( tabnr ) 753return "\x9b\xef\x58" .. nr2char ( a: tabnr ) .. nr2char ( 1 ) 754endfunc 755 756" Test for using the tabpage menu from the insert and normal modes 757func Test_tabline_tabmenu () 758" only works in GUI 759CheckGui 760 761 %bw ! 762tabnew 763tabnew 764call assert_equal ( 3 , tabpagenr ()) 765 766" go to tab page 2 in normal mode 767call feedkeys ( TabLineSelectPageCode ( 2 ), "Lx!" ) 768call assert_equal ( 2 , tabpagenr ()) 769 770" close tab page 3 in normal mode 771call feedkeys ( TabMenuCloseItemCode ( 3 ), "Lx!" ) 772call assert_equal ( 2 , tabpagenr ( '$' )) 773call assert_equal ( 2 , tabpagenr ()) 774 775" open new tab page before tab page 1 in normal mode 776call feedkeys ( TabMenuNewItemCode ( 1 ), "Lx!" ) 777call assert_equal ( 1 , tabpagenr ()) 778call assert_equal ( 3 , tabpagenr ( '$' )) 779 780" go to tab page 2 in operator-pending mode (should beep) 781call assert_beeps ( 'call feedkeys("c" .. TabLineSelectPageCode(2), "Lx!")' ) 782call assert_equal ( 2 , tabpagenr ()) 783call assert_equal ( 3 , tabpagenr ( '$' )) 784 785" open new tab page before tab page 1 in operator-pending mode (should beep) 786call assert_beeps ( 'call feedkeys("c" .. TabMenuNewItemCode(1), "Lx!")' ) 787call assert_equal ( 1 , tabpagenr ()) 788call assert_equal ( 4 , tabpagenr ( '$' )) 789 790" open new tab page after tab page 3 in normal mode 791call feedkeys ( TabMenuNewItemCode ( 4 ), "Lx!" ) 792call assert_equal ( 4 , tabpagenr ()) 793call assert_equal ( 5 , tabpagenr ( '$' )) 794 795" go to tab page 2 in insert mode 796call feedkeys ( "i" .. TabLineSelectPageCode ( 2 ) .. "\<C-C>" , "Lx!" ) 797call assert_equal ( 2 , tabpagenr ()) 798 799" close tab page 2 in insert mode 800call feedkeys ( "i" .. TabMenuCloseItemCode ( 2 ) .. "\<C-C>" , "Lx!" ) 801call assert_equal ( 4 , tabpagenr ( '$' )) 802 803" open new tab page before tab page 3 in insert mode 804call feedkeys ( "i" .. TabMenuNewItemCode ( 3 ) .. "\<C-C>" , "Lx!" ) 805call assert_equal ( 3 , tabpagenr ()) 806call assert_equal ( 5 , tabpagenr ( '$' )) 807 808" open new tab page after tab page 4 in insert mode 809call feedkeys ( "i" .. TabMenuNewItemCode ( 5 ) .. "\<C-C>" , "Lx!" ) 810call assert_equal ( 5 , tabpagenr ()) 811call assert_equal ( 6 , tabpagenr ( '$' )) 812 813 %bw ! 814endfunc 815 816" Test for changing the current tab page from an autocmd when closing a tab 817" page. 818func Test_tabpage_switchtab_on_close () 819only 820tabnew 821tabnew 822" Test for BufLeave 823augroup T1 824au ! 825au BufLeave * tabfirst 826augroup END 827tabclose 828call assert_equal ( 1 , tabpagenr ()) 829augroup T1 830au ! 831augroup END 832 833" Test for WinLeave 834$ tabnew 835augroup T1 836au ! 837au WinLeave * tabfirst 838augroup END 839tabclose 840call assert_equal ( 1 , tabpagenr ()) 841augroup T1 842au ! 843augroup END 844 845" Test for TabLeave 846$ tabnew 847augroup T1 848au ! 849au TabLeave * tabfirst 850augroup END 851tabclose 852call assert_equal ( 1 , tabpagenr ()) 853augroup T1 854au ! 855augroup END 856augroup ! T1 857tabonly 858endfunc 859 860" Test for closing the destination tabpage when jumping from one to another. 861func Test_tabpage_close_on_switch () 862tabnew 863tabnew 864edit Xfile 865augroup T2 866au ! 867au BufLeave Xfile 1 tabclose 868augroup END 869tabfirst 870call assert_equal ( 2 , tabpagenr ()) 871call assert_equal ( 'Xfile' , @%) 872augroup T2 873au ! 874augroup END 875augroup ! T2 876 %bw ! 877endfunc 878 879" Test for jumping to last accessed tabpage 880func Test_lastused_tabpage () 881tabonly ! 882call assert_equal ( 0 , tabpagenr ( '#' )) 883call assert_beeps ( 'call feedkeys("g\<Tab>", "xt")' ) 884call assert_beeps ( 'call feedkeys("\<C-Tab>", "xt")' ) 885call assert_beeps ( 'call feedkeys("\<C-W>g\<Tab>", "xt")' ) 886call assert_fails ( 'tabnext #' , 'E475:' ) 887 888" open four tab pages 889tabnew 890tabnew 891tabnew 892 8932 tabnext 894 895" Test for g<Tab> 896call assert_equal ( 4 , tabpagenr ( '#' )) 897call feedkeys ( "g\<Tab>" , "xt" ) 898call assert_equal ( 4 , tabpagenr ()) 899call assert_equal ( 2 , tabpagenr ( '#' )) 900 901" Test for <C-Tab> 902call feedkeys ( "\<C-Tab>" , "xt" ) 903call assert_equal ( 2 , tabpagenr ()) 904call assert_equal ( 4 , tabpagenr ( '#' )) 905 906" Test for <C-W>g<Tab> 907call feedkeys ( "\<C-W>g\<Tab>" , "xt" ) 908call assert_equal ( 4 , tabpagenr ()) 909call assert_equal ( 2 , tabpagenr ( '#' )) 910 911" Test for :tabnext # 912tabnext # 913call assert_equal ( 2 , tabpagenr ()) 914call assert_equal ( 4 , tabpagenr ( '#' )) 915 916" Try to jump to a closed tab page 917tabclose # 918call assert_equal ( 0 , tabpagenr ( '#' )) 919call feedkeys ( "g\<Tab>" , "xt" ) 920call assert_equal ( 2 , tabpagenr ()) 921call feedkeys ( "\<C-Tab>" , "xt" ) 922call assert_equal ( 2 , tabpagenr ()) 923call feedkeys ( "\<C-W>g\<Tab>" , "xt" ) 924call assert_equal ( 2 , tabpagenr ()) 925call assert_fails ( 'tabnext #' , 'E475:' ) 926call assert_equal ( 2 , tabpagenr ()) 927 928" Test for :tabonly # 929let wnum = win_getid () 930$ tabnew 931tabonly # 932call assert_equal ( wnum , win_getid ()) 933call assert_equal ( 1 , tabpagenr ( '$' )) 934 935" Test for :tabmove # 936tabnew 937let wnum = win_getid () 938tabnew 939tabnew 940tabnext 2 941tabmove # 942call assert_equal ( 4 , tabpagenr ()) 943call assert_equal ( wnum , win_getid ()) 944 945tabonly ! 946endfunc 947 948" Closing a tab page must keep the last used tab page when it is another one. 949func Test_lastused_tabpage_close () 950tabonly ! 951tabnew 952tabnew 953tabfirst 954tablast 955call assert_equal ( 1 , tabpagenr ( '#' )) 956 957tabclose 958call assert_equal ( 1 , tabpagenr ( '#' )) 959call feedkeys ( "g\<Tab>" , "xt" ) 960call assert_equal ( 1 , tabpagenr ()) 961 962tabonly ! 963endfunc 964 965" Test for tabpage allocation failure 966func Test_tabpage_alloc_failure () 967CheckFunction test_alloc_fail 968call test_alloc_fail ( GetAllocId ( 'newtabpage_tvars' ), 0 , 0 ) 969call assert_fails ( 'tabnew' , 'E342:' ) 970 971call test_alloc_fail ( GetAllocId ( 'newtabpage_tvars' ), 0 , 0 ) 972edit Xfile1 973call assert_fails ( 'tabedit Xfile2' , 'E342:' ) 974call assert_equal ( 1 , winnr ( '$' )) 975call assert_equal ( 1 , tabpagenr ( '$' )) 976call assert_equal ( 'Xfile1' , @%) 977 978new 979call test_alloc_fail ( GetAllocId ( 'newtabpage_tvars' ), 0 , 0 ) 980call assert_fails ( 'wincmd T' , 'E342:' ) 981bw ! 982 983call test_alloc_fail ( GetAllocId ( 'newtabpage_tvars' ), 0 , 0 ) 984call assert_fails ( 'tab split' , 'E342:' ) 985call assert_equal ( 2 , winnr ( '$' )) 986call assert_equal ( 1 , tabpagenr ( '$' )) 987endfunc 988 989func Test_tabpage_tabclose () 990" Default behaviour, move to the right. 991call s: reconstruct_tabpage_for_test ( 6 ) 992norm ! 4gt 993setl tcl = 994tabclose 995call assert_equal ( "n3" , bufname ()) 996 997" Move to the left. 998call s: reconstruct_tabpage_for_test ( 6 ) 999norm ! 4gt 1000setl tcl = left 1001tabclose 1002call assert_equal ( "n1" , bufname ()) 1003 1004" Move to the last used tab page. 1005call s: reconstruct_tabpage_for_test ( 6 ) 1006norm ! 5gt 1007norm ! 2gt 1008setl tcl = uselast 1009tabclose 1010call assert_equal ( "n3" , bufname ()) 1011 1012" Same, but the last used tab page is invalid. Move to the right. 1013call s: reconstruct_tabpage_for_test ( 6 ) 1014norm ! 5gt 1015norm ! 3gt 1016setl tcl = uselast 1017tabclose 5 1018tabclose ! 1019call assert_equal ( "n2" , bufname ()) 1020 1021" Same, but the last used tab page is invalid. Move to the left. 1022call s: reconstruct_tabpage_for_test ( 6 ) 1023norm ! 5gt 1024norm ! 3gt 1025setl tcl = uselast,left 1026tabclose 5 1027tabclose ! 1028call assert_equal ( "n0" , bufname ()) 1029 1030" Move left when moving right is not possible. 1031call s: reconstruct_tabpage_for_test ( 6 ) 1032setl tcl = 1033norm ! 6gt 1034tabclose 1035call assert_equal ( "n3" , bufname ()) 1036 1037" Move right when moving left is not possible. 1038call s: reconstruct_tabpage_for_test ( 6 ) 1039setl tcl = left 1040norm ! 1gt 1041tabclose 1042call assert_equal ( "n0" , bufname ()) 1043 1044setl tcl & 1045endfunc 1046 1047" this was giving ml_get errors 1048func Test_tabpage_last_line () 1049enew 1050call setline ( 1 , repeat ([ 'a' ], & lines + 5 )) 1051$ 1052tabnew 1053call setline ( 1 , repeat ([ 'b' ], & lines + 20 )) 1054$ 1055tabNext 1056call assert_equal ( 'a' , getline ( '.' )) 1057 1058bwipe ! 1059bwipe ! 1060endfunc 1061 1062" this was causing an endless loop 1063func Test_tabpage_drop_tabmove () 1064augroup TestTabpageTabmove 1065au ! 1066autocmd ! TabEnter * : if tabpagenr () > 1 |tabmove - |endif 1067augroup end 1068$ tab drop XTab_99.log 1069$ tab drop XTab_98.log 1070$ tab drop XTab_97.log 1071 1072autocmd ! TestTabpageTabmove 1073augroup ! TestTabpageTabmove 1074 1075" clean up 1076bwipe ! 1077bwipe ! 1078bwipe ! 1079endfunc 1080 1081" Test that settabvar() shouldn't change the last accessed tabpage. 1082func Test_lastused_tabpage_settabvar () 1083tabonly ! 1084tabnew 1085tabnew 1086tabnew 1087call assert_equal ( 3 , tabpagenr ( '#' )) 1088 1089call settabvar ( 2 , 'myvar' , 'tabval' ) 1090call assert_equal ( 'tabval' , gettabvar ( 2 , 'myvar' )) 1091call assert_equal ( 3 , tabpagenr ( '#' )) 1092 1093bwipe ! 1094bwipe ! 1095bwipe ! 1096endfunc 1097 1098" vim: shiftwidth=2 sts=2 expandtab