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