" Tests for tabpage
source screendump.vim
source check.vim
function Test_tabpage()
CheckFeature quickfix
bw!
" Simple test for opening and closing a tab page
tabnew
call assert_equal(2, tabpagenr())
quit
" Open three tab pages and use ":tabdo"
0tabnew
1tabnew
$tabnew
%del
tabdo call append(line('$'), tabpagenr())
tabclose! 2
tabrewind
let line1 = getline('$')
undo
q
tablast
let line2 = getline('$')
q!
call append(line('$'), line1)
call append(line('$'), line2)
unlet line1 line2
call assert_equal(['', '3', '1', '4'], getline(1, '$'))
"
" Test for settabvar() and gettabvar() functions. Open a new tab page and
" set 3 variables to a number, string and a list. Verify that the variables
" are correctly set.
tabnew
tabfirst
call settabvar(2, 'val_num', 100)
eval 'SetTabVar test'->settabvar(2, 'val_str')
call settabvar(2, 'val_list', ['red', 'blue', 'green'])
"
call assert_true(gettabvar(2, 'val_num') == 100 && gettabvar(2, 'val_str') == 'SetTabVar test' && gettabvar(2, 'val_list') == ['red', 'blue', 'green'])
tabnext 2
call assert_true(t:val_num == 100 && t:val_str == 'SetTabVar test' && t:val_list == ['red', 'blue', 'green'])
tabclose
" Test for ":tab drop exist-file" to keep current window.
sp test1
tab drop test1
call assert_true(tabpagenr('$') == 1 && winnr('$') == 2 && winnr() == 1)
close
"
"
" Test for ":tab drop new-file" to keep current window of tabpage 1.
split
tab drop newfile
call assert_true(tabpagenr('$') == 2 && tabpagewinnr(1, '$') == 2 && tabpagewinnr(1) == 1)
tabclose
q
"
"
" Test for ":tab drop multi-opened-file" to keep current tabpage and window.
new test1
tabnew
new test1
tab drop test1
call assert_true(tabpagenr() == 2 && tabpagewinnr(2, '$') == 2 && tabpagewinnr(2) == 1)
tabclose
q
"
"
" Test for ":tab drop vertical-split-window" to jump test1 buffer
tabedit test1
vnew
tabfirst
tab drop test1
call assert_equal([2, 2, 2, 2], [tabpagenr('$'), tabpagenr(), tabpagewinnr(2, '$'), tabpagewinnr(2)])
1tabonly
"
"
for i in range(9) | tabnew | endfor
normal! 1gt
call assert_equal(1, tabpagenr())
tabmove 5
call assert_equal(5, tabpagenr())
.tabmove
call assert_equal(5, tabpagenr())
tabmove -
call assert_equal(4, tabpagenr())
tabmove +
call assert_equal(5, tabpagenr())
tabmove -2
call assert_equal(3, tabpagenr())
tabmove +4
call assert_equal(7, tabpagenr())
tabmove
call assert_equal(10, tabpagenr())
0tabmove
call assert_equal(1, tabpagenr())
$tabmove
call assert_equal(10, tabpagenr())
tabmove 0
call assert_equal(1, tabpagenr())
tabmove $
call assert_equal(10, tabpagenr())
3tabmove
call assert_equal(4, tabpagenr())
7tabmove 5
call assert_equal(5, tabpagenr())
-tabmove
call assert_equal(4, tabpagenr())
+tabmove
call assert_equal(5, tabpagenr())
-2tabmove
call assert_equal(3, tabpagenr())
+3tabmove
call assert_equal(6, tabpagenr())
silent -tabmove
call assert_equal(5, tabpagenr())
silent -2 tabmove
call assert_equal(3, tabpagenr())
silent -2 tabmove
call assert_equal(1, tabpagenr())
norm! 2gt
call assert_equal(2, tabpagenr())
" The following are a no-op
tabmove 2
call assert_equal(2, tabpagenr())
2tabmove
call assert_equal(2, tabpagenr())
tabmove 1
call assert_equal(2, tabpagenr())
1tabmove
call assert_equal(2, tabpagenr())
call assert_fails('let t = tabpagenr("@")', 'E15:')
call assert_equal(0, tabpagewinnr(-1))
call assert_fails("99tabmove", 'E16:')
call assert_fails("+99tabmove", 'E16:')
call assert_fails("-99tabmove", 'E16:')
call assert_fails("tabmove foo", 'E475:')
call assert_fails("tabmove 99", 'E475:')
call assert_fails("tabmove +99", 'E475:')
call assert_fails("tabmove -99", 'E475:')
call assert_fails("tabmove -3+", 'E475:')
call assert_fails("tabmove $3", 'E475:')
call assert_fails("%tabonly", 'E16:')
1tabonly!
tabmove 1
call assert_equal(1, tabpagenr())
tabnew
call assert_fails("-2tabmove", 'E16:')
tabonly!
endfunc
func Test_tabpage_drop()
edit f1
tab split f2
tab split f3
normal! gt
call assert_equal(1, tabpagenr())
tab drop f4
call assert_equal(1, tabpagenr('#'))
tab drop f3
call assert_equal(4, tabpagenr())
call assert_equal(2, tabpagenr('#'))
bwipe!
bwipe!
bwipe!
bwipe!
call assert_equal(1, tabpagenr('$'))
call assert_equal(1, winnr('$'))
call assert_equal('', bufname(''))
call writefile(['L1', 'L2'], 'Xdropfile', 'D')
" Test for ':tab drop single-file': reuse current buffer
let expected_nr = bufnr()
tab drop Xdropfile
call assert_equal(1, tabpagenr('$'))
call assert_equal(expected_nr, bufnr())
call assert_equal('L2', getline(2))
bwipe!
" Test for ':tab drop single-file': not reuse modified buffer
set modified
let expected_nr = bufnr() + 1
tab drop Xdropfile
call assert_equal(2, tabpagenr())
call assert_equal(2, tabpagenr('$'))
call assert_equal(expected_nr, bufnr())
call assert_equal('L2', getline(2))
bwipe!
" Test for ':tab drop single-file': multiple tabs already exist
tab split f2
tab split f3
let expected_nr = bufnr() + 1
tab drop Xdropfile
call assert_equal(4, tabpagenr())
call assert_equal(4