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()) |
zeertzjq | 076faac | 2024-03-25 16:41:06 +0100 | [diff] [blame] | 120 | silent -tabmove |
| 121 | call assert_equal(5, tabpagenr()) |
| 122 | silent -2 tabmove |
| 123 | call assert_equal(3, tabpagenr()) |
| 124 | silent -2 tabmove |
| 125 | call assert_equal(1, tabpagenr()) |
Bram Moolenaar | 7cc5965 | 2018-08-07 13:14:46 +0200 | [diff] [blame] | 126 | |
Bram Moolenaar | 7cc5965 | 2018-08-07 13:14:46 +0200 | [diff] [blame] | 127 | norm! 2gt |
| 128 | call assert_equal(2, tabpagenr()) |
zeertzjq | 076faac | 2024-03-25 16:41:06 +0100 | [diff] [blame] | 129 | " The following are a no-op |
Bram Moolenaar | 7cc5965 | 2018-08-07 13:14:46 +0200 | [diff] [blame] | 130 | tabmove 2 |
| 131 | call assert_equal(2, tabpagenr()) |
| 132 | 2tabmove |
| 133 | call assert_equal(2, tabpagenr()) |
| 134 | tabmove 1 |
| 135 | call assert_equal(2, tabpagenr()) |
| 136 | 1tabmove |
| 137 | call assert_equal(2, tabpagenr()) |
| 138 | |
Bram Moolenaar | 62a2325 | 2020-08-09 14:04:42 +0200 | [diff] [blame] | 139 | call assert_fails('let t = tabpagenr("@")', 'E15:') |
Bram Moolenaar | 92b83cc | 2020-04-25 15:24:44 +0200 | [diff] [blame] | 140 | call assert_equal(0, tabpagewinnr(-1)) |
Bram Moolenaar | 2f72c70 | 2017-01-29 14:48:10 +0100 | [diff] [blame] | 141 | call assert_fails("99tabmove", 'E16:') |
| 142 | call assert_fails("+99tabmove", 'E16:') |
| 143 | call assert_fails("-99tabmove", 'E16:') |
Bram Moolenaar | 8930caa | 2020-07-23 16:37:03 +0200 | [diff] [blame] | 144 | call assert_fails("tabmove foo", 'E475:') |
| 145 | call assert_fails("tabmove 99", 'E475:') |
| 146 | call assert_fails("tabmove +99", 'E475:') |
| 147 | call assert_fails("tabmove -99", 'E475:') |
| 148 | call assert_fails("tabmove -3+", 'E475:') |
| 149 | call assert_fails("tabmove $3", 'E475:') |
Bram Moolenaar | bc2b71d | 2020-02-17 21:33:30 +0100 | [diff] [blame] | 150 | call assert_fails("%tabonly", 'E16:') |
Bram Moolenaar | 2f72c70 | 2017-01-29 14:48:10 +0100 | [diff] [blame] | 151 | 1tabonly! |
Bram Moolenaar | 5d3c9f8 | 2020-06-26 20:41:39 +0200 | [diff] [blame] | 152 | tabmove 1 |
| 153 | call assert_equal(1, tabpagenr()) |
Bram Moolenaar | bc2b71d | 2020-02-17 21:33:30 +0100 | [diff] [blame] | 154 | tabnew |
Bram Moolenaar | 8930caa | 2020-07-23 16:37:03 +0200 | [diff] [blame] | 155 | call assert_fails("-2tabmove", 'E16:') |
Bram Moolenaar | bc2b71d | 2020-02-17 21:33:30 +0100 | [diff] [blame] | 156 | tabonly! |
Bram Moolenaar | 1381d79 | 2016-08-18 22:11:42 +0200 | [diff] [blame] | 157 | endfunc |
| 158 | |
Bram Moolenaar | 8281a16 | 2023-04-20 18:07:57 +0100 | [diff] [blame] | 159 | func Test_tabpage_drop() |
| 160 | edit f1 |
| 161 | tab split f2 |
| 162 | tab split f3 |
| 163 | normal! gt |
| 164 | call assert_equal(1, tabpagenr()) |
glepnir | 2975a54 | 2024-02-09 19:30:26 +0100 | [diff] [blame] | 165 | tab drop f4 |
| 166 | call assert_equal(1, tabpagenr('#')) |
Bram Moolenaar | 8281a16 | 2023-04-20 18:07:57 +0100 | [diff] [blame] | 167 | |
| 168 | tab drop f3 |
glepnir | 2975a54 | 2024-02-09 19:30:26 +0100 | [diff] [blame] | 169 | call assert_equal(4, tabpagenr()) |
| 170 | call assert_equal(2, tabpagenr('#')) |
| 171 | bwipe! |
Bram Moolenaar | 8281a16 | 2023-04-20 18:07:57 +0100 | [diff] [blame] | 172 | bwipe! |
| 173 | bwipe! |
| 174 | bwipe! |
| 175 | call assert_equal(1, tabpagenr('$')) |
Rocco Mao | f96dc8d | 2024-01-23 21:27:19 +0100 | [diff] [blame] | 176 | |
| 177 | call assert_equal(1, winnr('$')) |
| 178 | call assert_equal('', bufname('')) |
| 179 | call writefile(['L1', 'L2'], 'Xdropfile', 'D') |
| 180 | |
| 181 | " Test for ':tab drop single-file': reuse current buffer |
| 182 | let expected_nr = bufnr() |
| 183 | tab drop Xdropfile |
| 184 | call assert_equal(1, tabpagenr('$')) |
| 185 | call assert_equal(expected_nr, bufnr()) |
| 186 | call assert_equal('L2', getline(2)) |
| 187 | bwipe! |
| 188 | |
| 189 | " Test for ':tab drop single-file': not reuse modified buffer |
| 190 | set modified |
| 191 | let expected_nr = bufnr() + 1 |
| 192 | tab drop Xdropfile |
| 193 | call assert_equal(2, tabpagenr()) |
| 194 | call assert_equal(2, tabpagenr('$')) |
| 195 | call assert_equal(expected_nr, bufnr()) |
| 196 | call assert_equal('L2', getline(2)) |
| 197 | bwipe! |
| 198 | |
| 199 | " Test for ':tab drop single-file': multiple tabs already exist |
| 200 | tab split f2 |
| 201 | tab split f3 |
| 202 | let expected_nr = bufnr() + 1 |
| 203 | tab drop Xdropfile |
| 204 | call assert_equal(4, tabpagenr()) |
| 205 | call assert_equal(4, tabpagenr('$')) |
| 206 | call assert_equal(expected_nr, bufnr()) |
| 207 | call assert_equal('L2', getline(2)) |
| 208 | %bwipe! |
| 209 | |
| 210 | " Test for ':tab drop multi-files': reuse current buffer |
| 211 | let expected_nr = bufnr() |
| 212 | tab drop Xdropfile f1 f2 f3 |
| 213 | call assert_equal(1, tabpagenr()) |
| 214 | call assert_equal(4, tabpagenr('$')) |
| 215 | call assert_equal(expected_nr, bufnr()) |
| 216 | call assert_equal('L2', getline(2)) |
| 217 | %bwipe! |
| 218 | |
| 219 | " Test for ':tab drop multi-files': not reuse modified buffer |
| 220 | set modified |
| 221 | let expected_nr = bufnr() + 1 |
| 222 | tab drop Xdropfile f1 f2 f3 |
| 223 | call assert_equal(2, tabpagenr()) |
| 224 | call assert_equal(5, tabpagenr('$')) |
| 225 | call assert_equal(expected_nr, bufnr()) |
| 226 | call assert_equal('L2', getline(2)) |
| 227 | %bwipe! |
| 228 | |
| 229 | " Test for ':tab drop multi-files': multiple tabs already exist |
| 230 | tab split f2 |
| 231 | tab split f3 |
| 232 | let expected_nr = bufnr() + 1 |
| 233 | tab drop a b c |
| 234 | call assert_equal(4, tabpagenr()) |
| 235 | call assert_equal(6, tabpagenr('$')) |
| 236 | call assert_equal(expected_nr, bufnr()) |
| 237 | let expected_nr = bufnr() + 3 |
| 238 | tab drop Xdropfile f1 f2 f3 |
| 239 | call assert_equal(5, tabpagenr()) |
| 240 | call assert_equal(8, tabpagenr('$')) |
| 241 | call assert_equal(expected_nr, bufnr()) |
| 242 | call assert_equal('L2', getline(2)) |
| 243 | %bwipe! |
Bram Moolenaar | 8281a16 | 2023-04-20 18:07:57 +0100 | [diff] [blame] | 244 | endfunc |
| 245 | |
Bram Moolenaar | 1381d79 | 2016-08-18 22:11:42 +0200 | [diff] [blame] | 246 | " Test autocommands |
| 247 | function Test_tabpage_with_autocmd() |
Bram Moolenaar | 1381d79 | 2016-08-18 22:11:42 +0200 | [diff] [blame] | 248 | command -nargs=1 -bar C :call add(s:li, '=== ' . <q-args> . ' ===')|<args> |
| 249 | augroup TestTabpageGroup |
| 250 | au! |
| 251 | autocmd TabEnter * call add(s:li, 'TabEnter') |
| 252 | autocmd WinEnter * call add(s:li, 'WinEnter') |
| 253 | autocmd BufEnter * call add(s:li, 'BufEnter') |
| 254 | autocmd TabLeave * call add(s:li, 'TabLeave') |
| 255 | autocmd WinLeave * call add(s:li, 'WinLeave') |
| 256 | autocmd BufLeave * call add(s:li, 'BufLeave') |
| 257 | augroup END |
| 258 | |
| 259 | let s:li = [] |
| 260 | let t:a='a' |
| 261 | C tab split |
| 262 | call assert_equal(['=== tab split ===', 'WinLeave', 'TabLeave', 'WinEnter', 'TabEnter'], s:li) |
| 263 | let s:li = [] |
| 264 | let t:a='b' |
| 265 | C tabnew |
| 266 | call assert_equal(['=== tabnew ===', 'WinLeave', 'TabLeave', 'WinEnter', 'TabEnter', 'BufLeave', 'BufEnter'], s:li) |
| 267 | let t:a='c' |
| 268 | let s:li = split(join(map(range(1, tabpagenr('$')), 'gettabvar(v:val, "a")')) , '\s\+') |
| 269 | call assert_equal(['a', 'b', 'c'], s:li) |
| 270 | |
| 271 | let s:li = [] |
| 272 | C call map(range(1, tabpagenr('$')), 'settabvar(v:val, ''a'', v:val*2)') |
| 273 | call assert_equal(["=== call map(range(1, tabpagenr('$')), 'settabvar(v:val, ''a'', v:val*2)') ==="], s:li) |
| 274 | let s:li = split(join(map(range(1, tabpagenr('$')), 'gettabvar(v:val, "a")')) , '\s\+') |
| 275 | call assert_equal(['2', '4', '6'], s:li) |
| 276 | |
| 277 | let s:li = [] |
| 278 | let w:a='a' |
| 279 | C vsplit |
| 280 | call assert_equal(['=== vsplit ===', 'WinLeave', 'WinEnter'], s:li) |
| 281 | let s:li = [] |
| 282 | let w:a='a' |
| 283 | let tabn=tabpagenr() |
| 284 | let winr=range(1, winnr('$')) |
| 285 | C tabnext 1 |
| 286 | call assert_equal(['=== tabnext 1 ===', 'BufLeave', 'WinLeave', 'TabLeave', 'WinEnter', 'TabEnter', 'BufEnter'], s:li) |
| 287 | let s:li = split(join(map(copy(winr), 'gettabwinvar('.tabn.', v:val, "a")')), '\s\+') |
| 288 | call assert_equal(['a', 'a'], s:li) |
| 289 | let s:li = [] |
Bram Moolenaar | aad222c | 2019-09-06 22:46:09 +0200 | [diff] [blame] | 290 | 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] | 291 | let s:li = split(join(map(copy(winr), 'gettabwinvar('.tabn.', v:val, "a")')), '\s\+') |
| 292 | call assert_equal(['2', '4'], s:li) |
| 293 | |
| 294 | augroup TabDestructive |
| 295 | autocmd TabEnter * :C tabnext 2 | C tabclose 3 |
| 296 | augroup END |
| 297 | let s:li = [] |
| 298 | C tabnext 3 |
| 299 | call assert_equal(['=== tabnext 3 ===', 'BufLeave', 'WinLeave', 'TabLeave', 'WinEnter', 'TabEnter', '=== tabnext 2 ===', '=== tabclose 3 ==='], s:li) |
| 300 | call assert_equal(['2/2'], [tabpagenr().'/'.tabpagenr('$')]) |
| 301 | |
| 302 | autocmd! TabDestructive TabEnter |
| 303 | let s:li = [] |
| 304 | C tabnew |
| 305 | call assert_equal(['=== tabnew ===', 'WinLeave', 'TabLeave', 'WinEnter', 'TabEnter', 'BufLeave', 'BufEnter'], s:li) |
| 306 | let s:li = [] |
| 307 | C tabnext 1 |
| 308 | call assert_equal(['=== tabnext 1 ===', 'BufLeave', 'WinLeave', 'TabLeave', 'WinEnter', 'TabEnter', 'BufEnter'], s:li) |
| 309 | |
| 310 | autocmd TabDestructive TabEnter * nested :C tabnext 2 | C tabclose 3 |
| 311 | let s:li = [] |
Bram Moolenaar | 2f72c70 | 2017-01-29 14:48:10 +0100 | [diff] [blame] | 312 | call assert_equal(3, tabpagenr('$')) |
| 313 | C tabnext 2 |
| 314 | call assert_equal(2, tabpagenr('$')) |
| 315 | 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] | 316 | call assert_equal(['2/2'], [tabpagenr().'/'.tabpagenr('$')]) |
| 317 | |
| 318 | delcommand C |
| 319 | autocmd! TabDestructive |
| 320 | augroup! TabDestructive |
| 321 | autocmd! TestTabpageGroup |
| 322 | augroup! TestTabpageGroup |
Bram Moolenaar | 2f72c70 | 2017-01-29 14:48:10 +0100 | [diff] [blame] | 323 | 1tabonly! |
Bram Moolenaar | 1381d79 | 2016-08-18 22:11:42 +0200 | [diff] [blame] | 324 | endfunction |
| 325 | |
Bram Moolenaar | c10b521 | 2020-01-13 20:54:51 +0100 | [diff] [blame] | 326 | " Test autocommands on tab drop |
| 327 | function Test_tabpage_with_autocmd_tab_drop() |
| 328 | augroup TestTabpageGroup |
| 329 | au! |
| 330 | autocmd TabEnter * call add(s:li, 'TabEnter') |
| 331 | autocmd WinEnter * call add(s:li, 'WinEnter') |
| 332 | autocmd BufEnter * call add(s:li, 'BufEnter') |
| 333 | autocmd TabLeave * call add(s:li, 'TabLeave') |
| 334 | autocmd WinLeave * call add(s:li, 'WinLeave') |
| 335 | autocmd BufLeave * call add(s:li, 'BufLeave') |
| 336 | augroup END |
| 337 | |
| 338 | let s:li = [] |
| 339 | tab drop test1 |
Rocco Mao | f96dc8d | 2024-01-23 21:27:19 +0100 | [diff] [blame] | 340 | call assert_equal(['BufEnter'], s:li) |
Bram Moolenaar | c10b521 | 2020-01-13 20:54:51 +0100 | [diff] [blame] | 341 | |
| 342 | let s:li = [] |
| 343 | tab drop test2 test3 |
| 344 | call assert_equal([ |
| 345 | \ 'TabLeave', 'TabEnter', 'TabLeave', 'TabEnter', |
| 346 | \ 'TabLeave', 'WinEnter', 'TabEnter', 'BufEnter', |
Rocco Mao | f96dc8d | 2024-01-23 21:27:19 +0100 | [diff] [blame] | 347 | \ 'TabLeave', 'WinEnter', 'TabEnter', 'BufEnter', 'BufEnter'], s:li) |
Bram Moolenaar | c10b521 | 2020-01-13 20:54:51 +0100 | [diff] [blame] | 348 | |
| 349 | autocmd! TestTabpageGroup |
| 350 | augroup! TestTabpageGroup |
| 351 | 1tabonly! |
| 352 | endfunction |
| 353 | |
Bram Moolenaar | 9b7f8ce | 2016-08-21 19:07:17 +0200 | [diff] [blame] | 354 | function Test_tabpage_with_tab_modifier() |
Bram Moolenaar | 5a4c308 | 2019-12-01 15:23:11 +0100 | [diff] [blame] | 355 | CheckFeature quickfix |
| 356 | |
Bram Moolenaar | 9b7f8ce | 2016-08-21 19:07:17 +0200 | [diff] [blame] | 357 | for n in range(4) |
| 358 | tabedit |
| 359 | endfor |
| 360 | |
| 361 | function s:check_tab(pre_nr, cmd, post_nr) |
| 362 | exec 'tabnext ' . a:pre_nr |
| 363 | exec a:cmd |
| 364 | call assert_equal(a:post_nr, tabpagenr()) |
Bram Moolenaar | 100f5c9 | 2016-09-06 21:33:52 +0200 | [diff] [blame] | 365 | call assert_equal('help', &buftype) |
Bram Moolenaar | 9b7f8ce | 2016-08-21 19:07:17 +0200 | [diff] [blame] | 366 | helpclose |
| 367 | endfunc |
| 368 | |
| 369 | call s:check_tab(1, 'tab help', 2) |
| 370 | call s:check_tab(1, '3tab help', 4) |
| 371 | call s:check_tab(1, '.tab help', 2) |
| 372 | call s:check_tab(1, '.+1tab help', 3) |
| 373 | call s:check_tab(1, '0tab help', 1) |
| 374 | call s:check_tab(2, '+tab help', 4) |
| 375 | call s:check_tab(2, '+2tab help', 5) |
| 376 | call s:check_tab(4, '-tab help', 4) |
| 377 | call s:check_tab(4, '-2tab help', 3) |
| 378 | call s:check_tab(3, '$tab help', 6) |
| 379 | call assert_fails('99tab help', 'E16:') |
| 380 | call assert_fails('+99tab help', 'E16:') |
| 381 | call assert_fails('-99tab help', 'E16:') |
| 382 | |
| 383 | delfunction s:check_tab |
Bram Moolenaar | 2f72c70 | 2017-01-29 14:48:10 +0100 | [diff] [blame] | 384 | 1tabonly! |
| 385 | endfunction |
| 386 | |
| 387 | function Check_tab_count(pre_nr, cmd, post_nr) |
| 388 | exec 'tabnext' a:pre_nr |
| 389 | normal! G |
| 390 | exec a:cmd |
| 391 | call assert_equal(a:post_nr, tabpagenr(), a:cmd) |
| 392 | endfunc |
| 393 | |
| 394 | " Test for [count] of tabnext |
| 395 | function Test_tabpage_with_tabnext() |
| 396 | for n in range(4) |
| 397 | tabedit |
| 398 | call setline(1, ['', '', '3']) |
| 399 | endfor |
| 400 | |
| 401 | call Check_tab_count(1, 'tabnext', 2) |
| 402 | call Check_tab_count(1, '3tabnext', 3) |
| 403 | call Check_tab_count(1, '.tabnext', 1) |
| 404 | call Check_tab_count(1, '.+1tabnext', 2) |
| 405 | call Check_tab_count(2, '+tabnext', 3) |
| 406 | call Check_tab_count(2, '+2tabnext', 4) |
| 407 | call Check_tab_count(4, '-tabnext', 3) |
| 408 | call Check_tab_count(4, '-2tabnext', 2) |
| 409 | call Check_tab_count(3, '$tabnext', 5) |
| 410 | call assert_fails('0tabnext', 'E16:') |
| 411 | call assert_fails('99tabnext', 'E16:') |
| 412 | call assert_fails('+99tabnext', 'E16:') |
| 413 | call assert_fails('-99tabnext', 'E16:') |
| 414 | call Check_tab_count(1, 'tabnext 3', 3) |
| 415 | call Check_tab_count(2, 'tabnext +', 3) |
| 416 | call Check_tab_count(2, 'tabnext +2', 4) |
| 417 | call Check_tab_count(4, 'tabnext -', 3) |
| 418 | call Check_tab_count(4, 'tabnext -2', 2) |
| 419 | call Check_tab_count(3, 'tabnext $', 5) |
Bram Moolenaar | 8930caa | 2020-07-23 16:37:03 +0200 | [diff] [blame] | 420 | call assert_fails('tabnext 0', 'E475:') |
| 421 | call assert_fails('tabnext .', 'E475:') |
| 422 | call assert_fails('tabnext -+', 'E475:') |
| 423 | call assert_fails('tabnext +2-', 'E475:') |
| 424 | call assert_fails('tabnext $3', 'E475:') |
| 425 | call assert_fails('tabnext 99', 'E475:') |
| 426 | call assert_fails('tabnext +99', 'E475:') |
| 427 | call assert_fails('tabnext -99', 'E475:') |
Bram Moolenaar | 2f72c70 | 2017-01-29 14:48:10 +0100 | [diff] [blame] | 428 | |
| 429 | 1tabonly! |
| 430 | endfunction |
| 431 | |
| 432 | " Test for [count] of tabprevious |
| 433 | function Test_tabpage_with_tabprevious() |
| 434 | for n in range(5) |
| 435 | tabedit |
| 436 | call setline(1, ['', '', '3']) |
| 437 | endfor |
| 438 | |
| 439 | for cmd in ['tabNext', 'tabprevious'] |
| 440 | call Check_tab_count(6, cmd, 5) |
| 441 | call Check_tab_count(6, '3' . cmd, 3) |
| 442 | call Check_tab_count(6, '8' . cmd, 4) |
| 443 | call Check_tab_count(6, cmd . ' 3', 3) |
| 444 | call Check_tab_count(6, cmd . ' 8', 4) |
| 445 | for n in range(2) |
Bram Moolenaar | 9d48956 | 2020-07-30 20:08:50 +0200 | [diff] [blame] | 446 | for c in ['0', '.+3', '+', '+2', '-', '-2', '$', '+99', '-99'] |
Bram Moolenaar | 2f72c70 | 2017-01-29 14:48:10 +0100 | [diff] [blame] | 447 | if n == 0 " pre count |
| 448 | let entire_cmd = c . cmd |
| 449 | let err_code = 'E16:' |
| 450 | else |
| 451 | let entire_cmd = cmd . ' ' . c |
Bram Moolenaar | 8930caa | 2020-07-23 16:37:03 +0200 | [diff] [blame] | 452 | let err_code = 'E475:' |
Bram Moolenaar | 2f72c70 | 2017-01-29 14:48:10 +0100 | [diff] [blame] | 453 | endif |
| 454 | call assert_fails(entire_cmd, err_code) |
| 455 | endfor |
| 456 | endfor |
| 457 | endfor |
| 458 | |
| 459 | 1tabonly! |
| 460 | endfunction |
| 461 | |
| 462 | function s:reconstruct_tabpage_for_test(nr) |
| 463 | let n = (a:nr > 2) ? a:nr - 2 : 1 |
| 464 | 1tabonly! |
| 465 | 0tabedit n0 |
| 466 | for n in range(1, n) |
| 467 | exec '$tabedit n' . n |
| 468 | if n == 1 |
| 469 | call setline(1, ['', '', '3']) |
| 470 | endif |
| 471 | endfor |
| 472 | endfunc |
| 473 | |
Bram Moolenaar | dbe8869 | 2018-05-20 14:57:22 +0200 | [diff] [blame] | 474 | func Test_tabpage_ctrl_pgup_pgdown() |
| 475 | enew! |
| 476 | tabnew tab1 |
| 477 | tabnew tab2 |
| 478 | |
| 479 | call assert_equal(3, tabpagenr()) |
| 480 | exe "norm! \<C-PageUp>" |
| 481 | call assert_equal(2, tabpagenr()) |
| 482 | exe "norm! \<C-PageDown>" |
| 483 | call assert_equal(3, tabpagenr()) |
| 484 | |
| 485 | " Check wrapping at last or first page. |
| 486 | exe "norm! \<C-PageDown>" |
| 487 | call assert_equal(1, tabpagenr()) |
| 488 | exe "norm! \<C-PageUp>" |
| 489 | call assert_equal(3, tabpagenr()) |
| 490 | |
| 491 | " With a count, <C-PageUp> and <C-PageDown> are not symmetrical somehow: |
| 492 | " - {count}<C-PageUp> goes {count} pages downward (relative count) |
| 493 | " - {count}<C-PageDown> goes to page number {count} (absolute count) |
| 494 | exe "norm! 2\<C-PageUp>" |
| 495 | call assert_equal(1, tabpagenr()) |
| 496 | exe "norm! 2\<C-PageDown>" |
| 497 | call assert_equal(2, tabpagenr()) |
| 498 | |
| 499 | 1tabonly! |
| 500 | endfunc |
| 501 | |
Bram Moolenaar | 2f72c70 | 2017-01-29 14:48:10 +0100 | [diff] [blame] | 502 | " Test for [count] of tabclose |
| 503 | function Test_tabpage_with_tabclose() |
| 504 | |
| 505 | " pre count |
| 506 | call s:reconstruct_tabpage_for_test(6) |
| 507 | call Check_tab_count(3, 'tabclose!', 3) |
| 508 | call Check_tab_count(1, '3tabclose', 1) |
| 509 | call Check_tab_count(4, '4tabclose', 3) |
| 510 | call Check_tab_count(3, '1tabclose', 2) |
| 511 | call Check_tab_count(2, 'tabclose', 1) |
| 512 | call assert_equal(1, tabpagenr('$')) |
| 513 | call assert_equal('', bufname('')) |
| 514 | |
| 515 | call s:reconstruct_tabpage_for_test(6) |
| 516 | call Check_tab_count(2, '$tabclose', 2) |
| 517 | call Check_tab_count(4, '.tabclose', 4) |
| 518 | call Check_tab_count(3, '.+tabclose', 3) |
| 519 | call Check_tab_count(3, '.-2tabclose', 2) |
| 520 | call Check_tab_count(1, '.+1tabclose!', 1) |
| 521 | call assert_equal(1, tabpagenr('$')) |
| 522 | call assert_equal('', bufname('')) |
| 523 | |
| 524 | " post count |
| 525 | call s:reconstruct_tabpage_for_test(6) |
| 526 | call Check_tab_count(3, 'tabclose!', 3) |
| 527 | call Check_tab_count(1, 'tabclose 3', 1) |
| 528 | call Check_tab_count(4, 'tabclose 4', 3) |
| 529 | call Check_tab_count(3, 'tabclose 1', 2) |
| 530 | call Check_tab_count(2, 'tabclose', 1) |
| 531 | call assert_equal(1, tabpagenr('$')) |
| 532 | call assert_equal('', bufname('')) |
| 533 | |
| 534 | call s:reconstruct_tabpage_for_test(6) |
| 535 | call Check_tab_count(2, 'tabclose $', 2) |
| 536 | call Check_tab_count(4, 'tabclose', 4) |
| 537 | call Check_tab_count(3, 'tabclose +', 3) |
| 538 | call Check_tab_count(3, 'tabclose -2', 2) |
| 539 | call Check_tab_count(1, 'tabclose! +1', 1) |
| 540 | call assert_equal(1, tabpagenr('$')) |
| 541 | call assert_equal('', bufname('')) |
| 542 | |
| 543 | call s:reconstruct_tabpage_for_test(6) |
| 544 | for n in range(2) |
| 545 | for c in ['0', '$3', '99', '+99', '-99'] |
| 546 | if n == 0 " pre count |
| 547 | let entire_cmd = c . 'tabclose' |
| 548 | let err_code = 'E16:' |
| 549 | else |
| 550 | let entire_cmd = 'tabclose ' . c |
Bram Moolenaar | 8930caa | 2020-07-23 16:37:03 +0200 | [diff] [blame] | 551 | let err_code = 'E475:' |
Bram Moolenaar | 2f72c70 | 2017-01-29 14:48:10 +0100 | [diff] [blame] | 552 | endif |
| 553 | call assert_fails(entire_cmd, err_code) |
| 554 | call assert_equal(6, tabpagenr('$')) |
| 555 | endfor |
| 556 | endfor |
| 557 | |
| 558 | call assert_fails('3tabclose', 'E37:') |
| 559 | call assert_fails('tabclose 3', 'E37:') |
Bram Moolenaar | 8930caa | 2020-07-23 16:37:03 +0200 | [diff] [blame] | 560 | call assert_fails('tabclose -+', 'E475:') |
| 561 | call assert_fails('tabclose +2-', 'E475:') |
Bram Moolenaar | 2f72c70 | 2017-01-29 14:48:10 +0100 | [diff] [blame] | 562 | call assert_equal(6, tabpagenr('$')) |
| 563 | |
| 564 | 1tabonly! |
| 565 | endfunction |
| 566 | |
| 567 | " Test for [count] of tabonly |
| 568 | function Test_tabpage_with_tabonly() |
| 569 | |
| 570 | " Test for the normal behavior (pre count only) |
| 571 | let tc = [ [4, '.', '!'], [2, '.+', ''], [3, '.-2', '!'], [1, '.+1', '!'] ] |
| 572 | for c in tc |
| 573 | call s:reconstruct_tabpage_for_test(6) |
| 574 | let entire_cmd = c[1] . 'tabonly' . c[2] |
| 575 | call Check_tab_count(c[0], entire_cmd, 1) |
| 576 | call assert_equal(1, tabpagenr('$')) |
| 577 | endfor |
| 578 | |
| 579 | " Test for the normal behavior |
| 580 | let tc2 = [ [3, '', ''], [1, '3', ''], [4, '4', '!'], [3, '1', '!'], |
| 581 | \ [2, '', '!'], |
| 582 | \ [2, '$', '!'], [3, '+', '!'], [3, '-2', '!'], [3, '+1', '!'] |
| 583 | \ ] |
| 584 | for n in range(2) |
| 585 | for c in tc2 |
| 586 | call s:reconstruct_tabpage_for_test(6) |
| 587 | if n == 0 " pre count |
| 588 | let entire_cmd = c[1] . 'tabonly' . c[2] |
| 589 | else |
| 590 | let entire_cmd = 'tabonly' . c[2] . ' ' . c[1] |
| 591 | endif |
| 592 | call Check_tab_count(c[0], entire_cmd, 1) |
| 593 | call assert_equal(1, tabpagenr('$')) |
| 594 | endfor |
| 595 | endfor |
| 596 | |
| 597 | " Test for the error behavior |
| 598 | for n in range(2) |
| 599 | for c in ['0', '$3', '99', '+99', '-99'] |
| 600 | call s:reconstruct_tabpage_for_test(6) |
| 601 | if n == 0 " pre count |
| 602 | let entire_cmd = c . 'tabonly' |
| 603 | let err_code = 'E16:' |
| 604 | else |
| 605 | let entire_cmd = 'tabonly ' . c |
Bram Moolenaar | 8930caa | 2020-07-23 16:37:03 +0200 | [diff] [blame] | 606 | let err_code = 'E475:' |
Bram Moolenaar | 2f72c70 | 2017-01-29 14:48:10 +0100 | [diff] [blame] | 607 | endif |
| 608 | call assert_fails(entire_cmd, err_code) |
| 609 | call assert_equal(6, tabpagenr('$')) |
| 610 | endfor |
| 611 | endfor |
| 612 | |
| 613 | " Test for the error behavior (post count only) |
| 614 | for c in tc |
| 615 | call s:reconstruct_tabpage_for_test(6) |
| 616 | let entire_cmd = 'tabonly' . c[2] . ' ' . c[1] |
Bram Moolenaar | 8930caa | 2020-07-23 16:37:03 +0200 | [diff] [blame] | 617 | let err_code = 'E475:' |
Bram Moolenaar | 2f72c70 | 2017-01-29 14:48:10 +0100 | [diff] [blame] | 618 | call assert_fails(entire_cmd, err_code) |
| 619 | call assert_equal(6, tabpagenr('$')) |
| 620 | endfor |
| 621 | |
Bram Moolenaar | 8930caa | 2020-07-23 16:37:03 +0200 | [diff] [blame] | 622 | call assert_fails('tabonly -+', 'E475:') |
| 623 | call assert_fails('tabonly +2-', 'E475:') |
Bram Moolenaar | 2f72c70 | 2017-01-29 14:48:10 +0100 | [diff] [blame] | 624 | call assert_equal(6, tabpagenr('$')) |
| 625 | |
| 626 | 1tabonly! |
| 627 | new |
| 628 | only! |
Bram Moolenaar | 9b7f8ce | 2016-08-21 19:07:17 +0200 | [diff] [blame] | 629 | endfunction |
| 630 | |
Bram Moolenaar | 5a49789 | 2016-09-03 16:29:04 +0200 | [diff] [blame] | 631 | func Test_tabnext_on_buf_unload1() |
Bram Moolenaar | 11fbc28 | 2016-09-02 21:48:32 +0200 | [diff] [blame] | 632 | " This once caused a crash |
| 633 | new |
| 634 | tabedit |
| 635 | tabfirst |
| 636 | au BufUnload <buffer> tabnext |
| 637 | q |
| 638 | |
| 639 | while tabpagenr('$') > 1 |
Bram Moolenaar | 5a49789 | 2016-09-03 16:29:04 +0200 | [diff] [blame] | 640 | bwipe! |
| 641 | endwhile |
| 642 | endfunc |
| 643 | |
| 644 | func Test_tabnext_on_buf_unload2() |
| 645 | " This once caused a crash |
| 646 | tabedit |
| 647 | autocmd BufUnload <buffer> tabnext |
| 648 | file x |
| 649 | edit y |
| 650 | |
| 651 | while tabpagenr('$') > 1 |
| 652 | bwipe! |
Bram Moolenaar | 11fbc28 | 2016-09-02 21:48:32 +0200 | [diff] [blame] | 653 | endwhile |
| 654 | endfunc |
| 655 | |
Bram Moolenaar | 0ea5070 | 2017-07-08 14:44:50 +0200 | [diff] [blame] | 656 | func Test_close_on_quitpre() |
| 657 | " This once caused a crash |
Bram Moolenaar | ce11de8 | 2017-10-26 22:00:00 +0200 | [diff] [blame] | 658 | edit Xtest |
Bram Moolenaar | 0ea5070 | 2017-07-08 14:44:50 +0200 | [diff] [blame] | 659 | new |
| 660 | only |
| 661 | set bufhidden=delete |
| 662 | au QuitPre <buffer> close |
| 663 | tabnew tab1 |
| 664 | tabnew tab2 |
| 665 | 1tabn |
| 666 | q! |
| 667 | call assert_equal(1, tabpagenr()) |
| 668 | call assert_equal(2, tabpagenr('$')) |
| 669 | " clean up |
| 670 | while tabpagenr('$') > 1 |
| 671 | bwipe! |
| 672 | endwhile |
Bram Moolenaar | ce11de8 | 2017-10-26 22:00:00 +0200 | [diff] [blame] | 673 | buf Xtest |
Bram Moolenaar | 0ea5070 | 2017-07-08 14:44:50 +0200 | [diff] [blame] | 674 | endfunc |
Bram Moolenaar | 11fbc28 | 2016-09-02 21:48:32 +0200 | [diff] [blame] | 675 | |
Bram Moolenaar | dbe8869 | 2018-05-20 14:57:22 +0200 | [diff] [blame] | 676 | func Test_tabs() |
| 677 | enew! |
| 678 | tabnew tab1 |
| 679 | norm ixxx |
| 680 | let a=split(execute(':tabs'), "\n") |
| 681 | call assert_equal(['Tab page 1', |
| 682 | \ ' [No Name]', |
| 683 | \ 'Tab page 2', |
| 684 | \ '> + tab1'], a) |
| 685 | |
| 686 | 1tabonly! |
| 687 | bw! |
| 688 | endfunc |
| 689 | |
Bram Moolenaar | 0fef0ae | 2019-05-01 20:30:40 +0200 | [diff] [blame] | 690 | func Test_tabpage_cmdheight() |
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 |