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