Bram Moolenaar | 991dea3 | 2016-05-24 11:31:32 +0200 | [diff] [blame] | 1 | " Tests for window cmd (:wincmd, :split, :vsplit, :resize and etc...) |
| 2 | |
Bram Moolenaar | a27e1dc | 2019-10-07 22:27:36 +0200 | [diff] [blame] | 3 | so check.vim |
| 4 | |
Bram Moolenaar | 991dea3 | 2016-05-24 11:31:32 +0200 | [diff] [blame] | 5 | func Test_window_cmd_ls0_with_split() |
| 6 | set ls=0 |
| 7 | set splitbelow |
| 8 | split |
| 9 | quit |
| 10 | call assert_equal(0, &lines - &cmdheight - winheight(0)) |
| 11 | new | only! |
| 12 | " |
| 13 | set splitbelow&vim |
| 14 | botright split |
| 15 | quit |
| 16 | call assert_equal(0, &lines - &cmdheight - winheight(0)) |
| 17 | new | only! |
| 18 | set ls&vim |
| 19 | endfunc |
| 20 | |
| 21 | func Test_window_cmd_cmdwin_with_vsp() |
Bram Moolenaar | 72cf47a | 2018-05-10 18:23:29 +0200 | [diff] [blame] | 22 | let efmt = 'Expected 0 but got %d (in ls=%d, %s window)' |
Bram Moolenaar | 991dea3 | 2016-05-24 11:31:32 +0200 | [diff] [blame] | 23 | for v in range(0, 2) |
| 24 | exec "set ls=" . v |
| 25 | vsplit |
| 26 | call feedkeys("q:\<CR>") |
| 27 | let ac = &lines - (&cmdheight + winheight(0) + !!v) |
| 28 | let emsg = printf(efmt, ac, v, 'left') |
| 29 | call assert_equal(0, ac, emsg) |
| 30 | wincmd w |
| 31 | let ac = &lines - (&cmdheight + winheight(0) + !!v) |
| 32 | let emsg = printf(efmt, ac, v, 'right') |
| 33 | call assert_equal(0, ac, emsg) |
| 34 | new | only! |
| 35 | endfor |
| 36 | set ls&vim |
| 37 | endfunc |
| 38 | |
Bram Moolenaar | 5d2ca04 | 2016-06-26 17:11:21 +0200 | [diff] [blame] | 39 | function Test_window_cmd_wincmd_gf() |
| 40 | let fname = 'test_gf.txt' |
| 41 | let swp_fname = '.' . fname . '.swp' |
| 42 | call writefile([], fname) |
| 43 | call writefile([], swp_fname) |
| 44 | function s:swap_exists() |
| 45 | let v:swapchoice = s:swap_choice |
| 46 | endfunc |
Bram Moolenaar | eaa49e4 | 2019-07-13 18:08:59 +0200 | [diff] [blame] | 47 | " Remove the catch-all that runtest.vim adds |
| 48 | au! SwapExists |
Bram Moolenaar | 5d2ca04 | 2016-06-26 17:11:21 +0200 | [diff] [blame] | 49 | augroup test_window_cmd_wincmd_gf |
| 50 | autocmd! |
| 51 | exec "autocmd SwapExists " . fname . " call s:swap_exists()" |
| 52 | augroup END |
| 53 | |
| 54 | call setline(1, fname) |
| 55 | " (E)dit anyway |
| 56 | let s:swap_choice = 'e' |
| 57 | wincmd gf |
| 58 | call assert_equal(2, tabpagenr()) |
| 59 | call assert_equal(fname, bufname("%")) |
| 60 | quit! |
| 61 | |
| 62 | " (Q)uit |
| 63 | let s:swap_choice = 'q' |
| 64 | wincmd gf |
| 65 | call assert_equal(1, tabpagenr()) |
| 66 | call assert_notequal(fname, bufname("%")) |
| 67 | new | only! |
| 68 | |
| 69 | call delete(fname) |
| 70 | call delete(swp_fname) |
| 71 | augroup! test_window_cmd_wincmd_gf |
| 72 | endfunc |
| 73 | |
Bram Moolenaar | 4520d44 | 2017-03-19 16:09:46 +0100 | [diff] [blame] | 74 | func Test_window_quit() |
| 75 | e Xa |
| 76 | split Xb |
Bram Moolenaar | f92e58c | 2019-09-08 21:51:41 +0200 | [diff] [blame] | 77 | call assert_equal(2, '$'->winnr()) |
Bram Moolenaar | 4520d44 | 2017-03-19 16:09:46 +0100 | [diff] [blame] | 78 | call assert_equal('Xb', bufname(winbufnr(1))) |
| 79 | call assert_equal('Xa', bufname(winbufnr(2))) |
| 80 | |
| 81 | wincmd q |
| 82 | call assert_equal(1, winnr('$')) |
| 83 | call assert_equal('Xa', bufname(winbufnr(1))) |
| 84 | |
| 85 | bw Xa Xb |
| 86 | endfunc |
| 87 | |
| 88 | func Test_window_horizontal_split() |
| 89 | call assert_equal(1, winnr('$')) |
| 90 | 3wincmd s |
| 91 | call assert_equal(2, winnr('$')) |
| 92 | call assert_equal(3, winheight(0)) |
Bram Moolenaar | f92e58c | 2019-09-08 21:51:41 +0200 | [diff] [blame] | 93 | call assert_equal(winwidth(1), 2->winwidth()) |
Bram Moolenaar | 4520d44 | 2017-03-19 16:09:46 +0100 | [diff] [blame] | 94 | |
| 95 | call assert_fails('botright topleft wincmd s', 'E442:') |
| 96 | bw |
| 97 | endfunc |
| 98 | |
| 99 | func Test_window_vertical_split() |
| 100 | call assert_equal(1, winnr('$')) |
| 101 | 3wincmd v |
| 102 | call assert_equal(2, winnr('$')) |
| 103 | call assert_equal(3, winwidth(0)) |
| 104 | call assert_equal(winheight(1), winheight(2)) |
| 105 | |
| 106 | call assert_fails('botright topleft wincmd v', 'E442:') |
| 107 | bw |
| 108 | endfunc |
| 109 | |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 110 | " Test the ":wincmd ^" and "<C-W>^" commands. |
Bram Moolenaar | 4520d44 | 2017-03-19 16:09:46 +0100 | [diff] [blame] | 111 | func Test_window_split_edit_alternate() |
Bram Moolenaar | 4520d44 | 2017-03-19 16:09:46 +0100 | [diff] [blame] | 112 | |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 113 | " Test for failure when the alternate buffer/file no longer exists. |
| 114 | edit Xfoo | %bw |
| 115 | call assert_fails(':wincmd ^', 'E23') |
| 116 | |
| 117 | " Test for the expected behavior when we have two named buffers. |
| 118 | edit Xfoo | edit Xbar |
Bram Moolenaar | 4520d44 | 2017-03-19 16:09:46 +0100 | [diff] [blame] | 119 | wincmd ^ |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 120 | call assert_equal('Xfoo', bufname(winbufnr(1))) |
| 121 | call assert_equal('Xbar', bufname(winbufnr(2))) |
| 122 | only |
Bram Moolenaar | 4520d44 | 2017-03-19 16:09:46 +0100 | [diff] [blame] | 123 | |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 124 | " Test for the expected behavior when the alternate buffer is not named. |
| 125 | enew | let l:nr1 = bufnr('%') |
| 126 | edit Xfoo | let l:nr2 = bufnr('%') |
| 127 | wincmd ^ |
| 128 | call assert_equal(l:nr1, winbufnr(1)) |
| 129 | call assert_equal(l:nr2, winbufnr(2)) |
| 130 | only |
| 131 | |
Bram Moolenaar | d42333d | 2018-11-10 20:28:19 +0100 | [diff] [blame] | 132 | " FIXME: this currently fails on AppVeyor, but passes locally |
| 133 | if !has('win32') |
| 134 | " Test the Normal mode command. |
| 135 | call feedkeys("\<C-W>\<C-^>", 'tx') |
| 136 | call assert_equal(l:nr2, winbufnr(1)) |
| 137 | call assert_equal(l:nr1, winbufnr(2)) |
| 138 | endif |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 139 | |
| 140 | %bw! |
| 141 | endfunc |
| 142 | |
| 143 | " Test the ":[count]wincmd ^" and "[count]<C-W>^" commands. |
| 144 | func Test_window_split_edit_bufnr() |
| 145 | |
| 146 | %bwipeout |
| 147 | let l:nr = bufnr('%') + 1 |
| 148 | call assert_fails(':execute "normal! ' . l:nr . '\<C-W>\<C-^>"', 'E92') |
| 149 | call assert_fails(':' . l:nr . 'wincmd ^', 'E16') |
| 150 | call assert_fails(':0wincmd ^', 'E16') |
| 151 | |
| 152 | edit Xfoo | edit Xbar | edit Xbaz |
| 153 | let l:foo_nr = bufnr('Xfoo') |
| 154 | let l:bar_nr = bufnr('Xbar') |
| 155 | let l:baz_nr = bufnr('Xbaz') |
| 156 | |
Bram Moolenaar | 8617b40 | 2018-11-10 20:47:48 +0100 | [diff] [blame] | 157 | " FIXME: this currently fails on AppVeyor, but passes locally |
| 158 | if !has('win32') |
| 159 | call feedkeys(l:foo_nr . "\<C-W>\<C-^>", 'tx') |
| 160 | call assert_equal('Xfoo', bufname(winbufnr(1))) |
| 161 | call assert_equal('Xbaz', bufname(winbufnr(2))) |
| 162 | only |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 163 | |
Bram Moolenaar | 8617b40 | 2018-11-10 20:47:48 +0100 | [diff] [blame] | 164 | call feedkeys(l:bar_nr . "\<C-W>\<C-^>", 'tx') |
| 165 | call assert_equal('Xbar', bufname(winbufnr(1))) |
| 166 | call assert_equal('Xfoo', bufname(winbufnr(2))) |
| 167 | only |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 168 | |
Bram Moolenaar | 8617b40 | 2018-11-10 20:47:48 +0100 | [diff] [blame] | 169 | execute l:baz_nr . 'wincmd ^' |
| 170 | call assert_equal('Xbaz', bufname(winbufnr(1))) |
| 171 | call assert_equal('Xbar', bufname(winbufnr(2))) |
| 172 | endif |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 173 | |
| 174 | %bw! |
Bram Moolenaar | 4520d44 | 2017-03-19 16:09:46 +0100 | [diff] [blame] | 175 | endfunc |
| 176 | |
Bram Moolenaar | 9b9be00 | 2020-03-22 14:41:22 +0100 | [diff] [blame] | 177 | func Test_window_split_no_room() |
| 178 | " N horizontal windows need >= 2*N + 1 lines: |
| 179 | " - 1 line + 1 status line in each window |
| 180 | " - 1 Ex command line |
| 181 | " |
| 182 | " 2*N + 1 <= &lines |
| 183 | " N <= (lines - 1)/2 |
| 184 | " |
| 185 | " Beyond that number of windows, E36: Not enough room is expected. |
| 186 | let hor_win_count = (&lines - 1)/2 |
| 187 | let hor_split_count = hor_win_count - 1 |
| 188 | for s in range(1, hor_split_count) | split | endfor |
| 189 | call assert_fails('split', 'E36:') |
| 190 | |
| 191 | " N vertical windows need >= 2*(N - 1) + 1 columns: |
| 192 | " - 1 column + 1 separator for each window (except last window) |
| 193 | " - 1 column for the last window which does not have separator |
| 194 | " |
| 195 | " 2*(N - 1) + 1 <= &columns |
| 196 | " 2*N - 1 <= &columns |
| 197 | " N <= (&columns + 1)/2 |
| 198 | let ver_win_count = (&columns + 1)/2 |
| 199 | let ver_split_count = ver_win_count - 1 |
| 200 | for s in range(1, ver_split_count) | vsplit | endfor |
| 201 | call assert_fails('vsplit', 'E36:') |
| 202 | |
| 203 | %bw! |
| 204 | endfunc |
| 205 | |
Bram Moolenaar | 4520d44 | 2017-03-19 16:09:46 +0100 | [diff] [blame] | 206 | func Test_window_preview() |
Bram Moolenaar | 5a4c308 | 2019-12-01 15:23:11 +0100 | [diff] [blame] | 207 | CheckFeature quickfix |
| 208 | |
Bram Moolenaar | 4520d44 | 2017-03-19 16:09:46 +0100 | [diff] [blame] | 209 | " Open a preview window |
| 210 | pedit Xa |
| 211 | call assert_equal(2, winnr('$')) |
| 212 | call assert_equal(0, &previewwindow) |
| 213 | |
| 214 | " Go to the preview window |
| 215 | wincmd P |
| 216 | call assert_equal(1, &previewwindow) |
| 217 | |
| 218 | " Close preview window |
| 219 | wincmd z |
| 220 | call assert_equal(1, winnr('$')) |
| 221 | call assert_equal(0, &previewwindow) |
| 222 | |
| 223 | call assert_fails('wincmd P', 'E441:') |
| 224 | endfunc |
| 225 | |
Bram Moolenaar | 026587b | 2019-08-17 15:08:00 +0200 | [diff] [blame] | 226 | func Test_window_preview_from_help() |
Bram Moolenaar | 5a4c308 | 2019-12-01 15:23:11 +0100 | [diff] [blame] | 227 | CheckFeature quickfix |
| 228 | |
Bram Moolenaar | 026587b | 2019-08-17 15:08:00 +0200 | [diff] [blame] | 229 | filetype on |
| 230 | call writefile(['/* some C code */'], 'Xpreview.c') |
| 231 | help |
| 232 | pedit Xpreview.c |
| 233 | wincmd P |
| 234 | call assert_equal(1, &previewwindow) |
| 235 | call assert_equal('c', &filetype) |
| 236 | wincmd z |
| 237 | |
| 238 | filetype off |
| 239 | close |
| 240 | call delete('Xpreview.c') |
| 241 | endfunc |
| 242 | |
Bram Moolenaar | 4520d44 | 2017-03-19 16:09:46 +0100 | [diff] [blame] | 243 | func Test_window_exchange() |
| 244 | e Xa |
| 245 | |
| 246 | " Nothing happens with window exchange when there is 1 window |
| 247 | wincmd x |
| 248 | call assert_equal(1, winnr('$')) |
| 249 | |
| 250 | split Xb |
| 251 | split Xc |
| 252 | |
| 253 | call assert_equal('Xc', bufname(winbufnr(1))) |
| 254 | call assert_equal('Xb', bufname(winbufnr(2))) |
| 255 | call assert_equal('Xa', bufname(winbufnr(3))) |
| 256 | |
| 257 | " Exchange current window 1 with window 3 |
| 258 | 3wincmd x |
| 259 | call assert_equal('Xa', bufname(winbufnr(1))) |
| 260 | call assert_equal('Xb', bufname(winbufnr(2))) |
| 261 | call assert_equal('Xc', bufname(winbufnr(3))) |
| 262 | |
| 263 | " Exchange window with next when at the top window |
| 264 | wincmd x |
| 265 | call assert_equal('Xb', bufname(winbufnr(1))) |
| 266 | call assert_equal('Xa', bufname(winbufnr(2))) |
| 267 | call assert_equal('Xc', bufname(winbufnr(3))) |
| 268 | |
| 269 | " Exchange window with next when at the middle window |
| 270 | wincmd j |
| 271 | wincmd x |
| 272 | call assert_equal('Xb', bufname(winbufnr(1))) |
| 273 | call assert_equal('Xc', bufname(winbufnr(2))) |
| 274 | call assert_equal('Xa', bufname(winbufnr(3))) |
| 275 | |
| 276 | " Exchange window with next when at the bottom window. |
| 277 | " When there is no next window, it exchanges with the previous window. |
| 278 | wincmd j |
| 279 | wincmd x |
| 280 | call assert_equal('Xb', bufname(winbufnr(1))) |
| 281 | call assert_equal('Xa', bufname(winbufnr(2))) |
| 282 | call assert_equal('Xc', bufname(winbufnr(3))) |
| 283 | |
| 284 | bw Xa Xb Xc |
| 285 | endfunc |
| 286 | |
| 287 | func Test_window_rotate() |
| 288 | e Xa |
| 289 | split Xb |
| 290 | split Xc |
| 291 | call assert_equal('Xc', bufname(winbufnr(1))) |
| 292 | call assert_equal('Xb', bufname(winbufnr(2))) |
| 293 | call assert_equal('Xa', bufname(winbufnr(3))) |
| 294 | |
| 295 | " Rotate downwards |
| 296 | wincmd r |
| 297 | call assert_equal('Xa', bufname(winbufnr(1))) |
| 298 | call assert_equal('Xc', bufname(winbufnr(2))) |
| 299 | call assert_equal('Xb', bufname(winbufnr(3))) |
| 300 | |
| 301 | 2wincmd r |
| 302 | call assert_equal('Xc', bufname(winbufnr(1))) |
| 303 | call assert_equal('Xb', bufname(winbufnr(2))) |
| 304 | call assert_equal('Xa', bufname(winbufnr(3))) |
| 305 | |
| 306 | " Rotate upwards |
| 307 | wincmd R |
| 308 | call assert_equal('Xb', bufname(winbufnr(1))) |
| 309 | call assert_equal('Xa', bufname(winbufnr(2))) |
| 310 | call assert_equal('Xc', bufname(winbufnr(3))) |
| 311 | |
| 312 | 2wincmd R |
| 313 | call assert_equal('Xc', bufname(winbufnr(1))) |
| 314 | call assert_equal('Xb', bufname(winbufnr(2))) |
| 315 | call assert_equal('Xa', bufname(winbufnr(3))) |
| 316 | |
| 317 | bot vsplit |
| 318 | call assert_fails('wincmd R', 'E443:') |
| 319 | |
| 320 | bw Xa Xb Xc |
| 321 | endfunc |
| 322 | |
| 323 | func Test_window_height() |
| 324 | e Xa |
| 325 | split Xb |
| 326 | |
| 327 | let [wh1, wh2] = [winheight(1), winheight(2)] |
| 328 | " Active window (1) should have the same height or 1 more |
| 329 | " than the other window. |
| 330 | call assert_inrange(wh2, wh2 + 1, wh1) |
| 331 | |
| 332 | wincmd - |
| 333 | call assert_equal(wh1 - 1, winheight(1)) |
| 334 | call assert_equal(wh2 + 1, winheight(2)) |
| 335 | |
| 336 | wincmd + |
| 337 | call assert_equal(wh1, winheight(1)) |
Bram Moolenaar | f92e58c | 2019-09-08 21:51:41 +0200 | [diff] [blame] | 338 | call assert_equal(wh2, 2->winheight()) |
Bram Moolenaar | 4520d44 | 2017-03-19 16:09:46 +0100 | [diff] [blame] | 339 | |
| 340 | 2wincmd _ |
| 341 | call assert_equal(2, winheight(1)) |
| 342 | call assert_equal(wh1 + wh2 - 2, winheight(2)) |
| 343 | |
| 344 | wincmd = |
| 345 | call assert_equal(wh1, winheight(1)) |
| 346 | call assert_equal(wh2, winheight(2)) |
| 347 | |
| 348 | 2wincmd _ |
| 349 | set winfixheight |
| 350 | split Xc |
| 351 | let [wh1, wh2, wh3] = [winheight(1), winheight(2), winheight(3)] |
| 352 | call assert_equal(2, winheight(2)) |
| 353 | call assert_inrange(wh3, wh3 + 1, wh1) |
| 354 | 3wincmd + |
| 355 | call assert_equal(2, winheight(2)) |
| 356 | call assert_equal(wh1 + 3, winheight(1)) |
| 357 | call assert_equal(wh3 - 3, winheight(3)) |
| 358 | wincmd = |
| 359 | call assert_equal(2, winheight(2)) |
| 360 | call assert_equal(wh1, winheight(1)) |
| 361 | call assert_equal(wh3, winheight(3)) |
| 362 | |
| 363 | wincmd j |
| 364 | set winfixheight& |
| 365 | |
| 366 | wincmd = |
| 367 | let [wh1, wh2, wh3] = [winheight(1), winheight(2), winheight(3)] |
| 368 | " Current window (2) should have the same height or 1 more |
| 369 | " than the other windows. |
| 370 | call assert_inrange(wh1, wh1 + 1, wh2) |
| 371 | call assert_inrange(wh3, wh3 + 1, wh2) |
| 372 | |
| 373 | bw Xa Xb Xc |
| 374 | endfunc |
| 375 | |
| 376 | func Test_window_width() |
| 377 | e Xa |
| 378 | vsplit Xb |
| 379 | |
| 380 | let [ww1, ww2] = [winwidth(1), winwidth(2)] |
| 381 | " Active window (1) should have the same width or 1 more |
| 382 | " than the other window. |
| 383 | call assert_inrange(ww2, ww2 + 1, ww1) |
| 384 | |
| 385 | wincmd < |
| 386 | call assert_equal(ww1 - 1, winwidth(1)) |
| 387 | call assert_equal(ww2 + 1, winwidth(2)) |
| 388 | |
| 389 | wincmd > |
| 390 | call assert_equal(ww1, winwidth(1)) |
| 391 | call assert_equal(ww2, winwidth(2)) |
| 392 | |
| 393 | 2wincmd | |
| 394 | call assert_equal(2, winwidth(1)) |
| 395 | call assert_equal(ww1 + ww2 - 2, winwidth(2)) |
| 396 | |
| 397 | wincmd = |
| 398 | call assert_equal(ww1, winwidth(1)) |
| 399 | call assert_equal(ww2, winwidth(2)) |
| 400 | |
| 401 | 2wincmd | |
| 402 | set winfixwidth |
| 403 | vsplit Xc |
| 404 | let [ww1, ww2, ww3] = [winwidth(1), winwidth(2), winwidth(3)] |
Bram Moolenaar | 38e3483 | 2017-03-19 20:22:36 +0100 | [diff] [blame] | 405 | call assert_equal(2, winwidth(2)) |
Bram Moolenaar | 4520d44 | 2017-03-19 16:09:46 +0100 | [diff] [blame] | 406 | call assert_inrange(ww3, ww3 + 1, ww1) |
| 407 | 3wincmd > |
Bram Moolenaar | 38e3483 | 2017-03-19 20:22:36 +0100 | [diff] [blame] | 408 | call assert_equal(2, winwidth(2)) |
Bram Moolenaar | 4520d44 | 2017-03-19 16:09:46 +0100 | [diff] [blame] | 409 | call assert_equal(ww1 + 3, winwidth(1)) |
| 410 | call assert_equal(ww3 - 3, winwidth(3)) |
| 411 | wincmd = |
Bram Moolenaar | 38e3483 | 2017-03-19 20:22:36 +0100 | [diff] [blame] | 412 | call assert_equal(2, winwidth(2)) |
Bram Moolenaar | 4520d44 | 2017-03-19 16:09:46 +0100 | [diff] [blame] | 413 | call assert_equal(ww1, winwidth(1)) |
| 414 | call assert_equal(ww3, winwidth(3)) |
| 415 | |
| 416 | wincmd l |
| 417 | set winfixwidth& |
| 418 | |
| 419 | wincmd = |
| 420 | let [ww1, ww2, ww3] = [winwidth(1), winwidth(2), winwidth(3)] |
| 421 | " Current window (2) should have the same width or 1 more |
| 422 | " than the other windows. |
| 423 | call assert_inrange(ww1, ww1 + 1, ww2) |
| 424 | call assert_inrange(ww3, ww3 + 1, ww2) |
| 425 | |
| 426 | bw Xa Xb Xc |
| 427 | endfunc |
| 428 | |
Bram Moolenaar | 8eeeba8 | 2017-06-25 22:45:39 +0200 | [diff] [blame] | 429 | func Test_equalalways_on_close() |
| 430 | set equalalways |
| 431 | vsplit |
| 432 | windo split |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 433 | split |
Bram Moolenaar | 8eeeba8 | 2017-06-25 22:45:39 +0200 | [diff] [blame] | 434 | wincmd J |
| 435 | " now we have a frame top-left with two windows, a frame top-right with two |
| 436 | " windows and a frame at the bottom, full-width. |
| 437 | let height_1 = winheight(1) |
| 438 | let height_2 = winheight(2) |
| 439 | let height_3 = winheight(3) |
| 440 | let height_4 = winheight(4) |
| 441 | " closing the bottom window causes all windows to be resized. |
| 442 | close |
| 443 | call assert_notequal(height_1, winheight(1)) |
| 444 | call assert_notequal(height_2, winheight(2)) |
| 445 | call assert_notequal(height_3, winheight(3)) |
| 446 | call assert_notequal(height_4, winheight(4)) |
| 447 | call assert_equal(winheight(1), winheight(3)) |
| 448 | call assert_equal(winheight(2), winheight(4)) |
| 449 | |
| 450 | 1wincmd w |
| 451 | split |
| 452 | 4wincmd w |
| 453 | resize + 5 |
| 454 | " left column has three windows, equalized heights. |
| 455 | " right column has two windows, top one a bit higher |
| 456 | let height_1 = winheight(1) |
| 457 | let height_2 = winheight(2) |
| 458 | let height_4 = winheight(4) |
| 459 | let height_5 = winheight(5) |
| 460 | 3wincmd w |
| 461 | " closing window in left column equalizes heights in left column but not in |
| 462 | " the right column |
| 463 | close |
| 464 | call assert_notequal(height_1, winheight(1)) |
| 465 | call assert_notequal(height_2, winheight(2)) |
| 466 | call assert_equal(height_4, winheight(3)) |
| 467 | call assert_equal(height_5, winheight(4)) |
| 468 | |
| 469 | only |
| 470 | set equalalways& |
| 471 | endfunc |
| 472 | |
Bram Moolenaar | 22044dc | 2017-12-02 15:43:37 +0100 | [diff] [blame] | 473 | func Test_win_screenpos() |
Bram Moolenaar | 5a4c308 | 2019-12-01 15:23:11 +0100 | [diff] [blame] | 474 | CheckFeature quickfix |
| 475 | |
Bram Moolenaar | 22044dc | 2017-12-02 15:43:37 +0100 | [diff] [blame] | 476 | call assert_equal(1, winnr('$')) |
| 477 | split |
| 478 | vsplit |
| 479 | 10wincmd _ |
| 480 | 30wincmd | |
| 481 | call assert_equal([1, 1], win_screenpos(1)) |
| 482 | call assert_equal([1, 32], win_screenpos(2)) |
| 483 | call assert_equal([12, 1], win_screenpos(3)) |
| 484 | call assert_equal([0, 0], win_screenpos(4)) |
| 485 | only |
| 486 | endfunc |
| 487 | |
Bram Moolenaar | 4520d44 | 2017-03-19 16:09:46 +0100 | [diff] [blame] | 488 | func Test_window_jump_tag() |
Bram Moolenaar | 5a4c308 | 2019-12-01 15:23:11 +0100 | [diff] [blame] | 489 | CheckFeature quickfix |
| 490 | |
Bram Moolenaar | 4520d44 | 2017-03-19 16:09:46 +0100 | [diff] [blame] | 491 | help |
| 492 | /iccf |
| 493 | call assert_match('^|iccf|', getline('.')) |
| 494 | call assert_equal(2, winnr('$')) |
| 495 | 2wincmd } |
| 496 | call assert_equal(3, winnr('$')) |
| 497 | call assert_match('^|iccf|', getline('.')) |
| 498 | wincmd k |
| 499 | call assert_match('\*iccf\*', getline('.')) |
| 500 | call assert_equal(2, winheight(0)) |
| 501 | |
| 502 | wincmd z |
| 503 | set previewheight=4 |
| 504 | help |
| 505 | /bugs |
| 506 | wincmd } |
| 507 | wincmd k |
| 508 | call assert_match('\*bugs\*', getline('.')) |
| 509 | call assert_equal(4, winheight(0)) |
| 510 | set previewheight& |
| 511 | |
| 512 | %bw! |
| 513 | endfunc |
| 514 | |
| 515 | func Test_window_newtab() |
| 516 | e Xa |
| 517 | |
| 518 | call assert_equal(1, tabpagenr('$')) |
| 519 | call assert_equal("\nAlready only one window", execute('wincmd T')) |
| 520 | |
| 521 | split Xb |
| 522 | split Xc |
| 523 | |
| 524 | wincmd T |
| 525 | call assert_equal(2, tabpagenr('$')) |
| 526 | call assert_equal(['Xb', 'Xa'], map(tabpagebuflist(1), 'bufname(v:val)')) |
Bram Moolenaar | ce90e36 | 2019-09-08 18:58:44 +0200 | [diff] [blame] | 527 | call assert_equal(['Xc' ], map(2->tabpagebuflist(), 'bufname(v:val)')) |
Bram Moolenaar | 4520d44 | 2017-03-19 16:09:46 +0100 | [diff] [blame] | 528 | |
| 529 | %bw! |
| 530 | endfunc |
| 531 | |
Bram Moolenaar | f79225e | 2017-03-18 23:11:04 +0100 | [diff] [blame] | 532 | func Test_next_split_all() |
| 533 | " This was causing an illegal memory access. |
| 534 | n x |
| 535 | norm axxx |
| 536 | split |
| 537 | split |
| 538 | s/x |
| 539 | s/x |
| 540 | all |
| 541 | bwipe! |
| 542 | endfunc |
| 543 | |
Bram Moolenaar | 75373f3 | 2017-08-07 22:02:30 +0200 | [diff] [blame] | 544 | " Tests for adjusting window and contents |
| 545 | func GetScreenStr(row) |
| 546 | let str = "" |
| 547 | for c in range(1,3) |
| 548 | let str .= nr2char(screenchar(a:row, c)) |
| 549 | endfor |
| 550 | return str |
| 551 | endfunc |
| 552 | |
| 553 | func Test_window_contents() |
| 554 | enew! | only | new |
| 555 | call setline(1, range(1,256)) |
| 556 | |
| 557 | exe "norm! \<C-W>t\<C-W>=1Gzt\<C-W>w\<C-W>+" |
| 558 | redraw |
Bram Moolenaar | 72cf47a | 2018-05-10 18:23:29 +0200 | [diff] [blame] | 559 | let s3 = GetScreenStr(1) |
Bram Moolenaar | 75373f3 | 2017-08-07 22:02:30 +0200 | [diff] [blame] | 560 | wincmd p |
| 561 | call assert_equal(1, line("w0")) |
| 562 | call assert_equal('1 ', s3) |
| 563 | |
| 564 | exe "norm! \<C-W>t\<C-W>=50Gzt\<C-W>w\<C-W>+" |
| 565 | redraw |
Bram Moolenaar | 72cf47a | 2018-05-10 18:23:29 +0200 | [diff] [blame] | 566 | let s3 = GetScreenStr(1) |
Bram Moolenaar | 75373f3 | 2017-08-07 22:02:30 +0200 | [diff] [blame] | 567 | wincmd p |
| 568 | call assert_equal(50, line("w0")) |
| 569 | call assert_equal('50 ', s3) |
| 570 | |
| 571 | exe "norm! \<C-W>t\<C-W>=59Gzt\<C-W>w\<C-W>+" |
| 572 | redraw |
Bram Moolenaar | 72cf47a | 2018-05-10 18:23:29 +0200 | [diff] [blame] | 573 | let s3 = GetScreenStr(1) |
Bram Moolenaar | 75373f3 | 2017-08-07 22:02:30 +0200 | [diff] [blame] | 574 | wincmd p |
| 575 | call assert_equal(59, line("w0")) |
| 576 | call assert_equal('59 ', s3) |
| 577 | |
Bram Moolenaar | 8b63313 | 2020-03-20 18:20:51 +0100 | [diff] [blame] | 578 | %d |
| 579 | call setline(1, ['one', 'two', 'three']) |
| 580 | call assert_equal(1, line('w0')) |
| 581 | call assert_equal(3, line('w$')) |
| 582 | |
Bram Moolenaar | 75373f3 | 2017-08-07 22:02:30 +0200 | [diff] [blame] | 583 | bwipeout! |
| 584 | call test_garbagecollect_now() |
| 585 | endfunc |
| 586 | |
Bram Moolenaar | 2efb323 | 2017-12-19 12:27:23 +0100 | [diff] [blame] | 587 | func Test_window_colon_command() |
| 588 | " This was reading invalid memory. |
| 589 | exe "norm! v\<C-W>:\<C-U>echo v:version" |
| 590 | endfunc |
| 591 | |
Bram Moolenaar | 6f361c9 | 2018-01-31 19:06:50 +0100 | [diff] [blame] | 592 | func Test_access_freed_mem() |
Bram Moolenaar | 1417c76 | 2019-07-27 17:31:36 +0200 | [diff] [blame] | 593 | call assert_equal(&columns, winwidth(0)) |
Bram Moolenaar | 6f361c9 | 2018-01-31 19:06:50 +0100 | [diff] [blame] | 594 | " This was accessing freed memory |
| 595 | au * 0 vs xxx |
| 596 | arg 0 |
| 597 | argadd |
Bram Moolenaar | 1417c76 | 2019-07-27 17:31:36 +0200 | [diff] [blame] | 598 | call assert_fails("all", "E249:") |
Bram Moolenaar | 6f361c9 | 2018-01-31 19:06:50 +0100 | [diff] [blame] | 599 | au! |
| 600 | bwipe xxx |
Bram Moolenaar | 1417c76 | 2019-07-27 17:31:36 +0200 | [diff] [blame] | 601 | call assert_equal(&columns, winwidth(0)) |
Bram Moolenaar | 6f361c9 | 2018-01-31 19:06:50 +0100 | [diff] [blame] | 602 | endfunc |
| 603 | |
Bram Moolenaar | a27e1dc | 2019-10-07 22:27:36 +0200 | [diff] [blame] | 604 | func Test_insert_cleared_on_switch_to_term() |
| 605 | CheckFeature terminal |
| 606 | |
| 607 | set showmode |
| 608 | terminal |
| 609 | wincmd p |
| 610 | |
| 611 | call feedkeys("i\<C-O>", 'ntx') |
| 612 | redraw |
| 613 | |
| 614 | " The "-- (insert) --" indicator should be visible. |
| 615 | let chars = map(range(1, &columns), 'nr2char(screenchar(&lines, v:val))') |
| 616 | let str = trim(join(chars, '')) |
| 617 | call assert_equal('-- (insert) --', str) |
| 618 | |
| 619 | call feedkeys("\<C-W>p", 'ntx') |
| 620 | redraw |
| 621 | |
| 622 | " The "-- (insert) --" indicator should have been cleared. |
| 623 | let chars = map(range(1, &columns), 'nr2char(screenchar(&lines, v:val))') |
| 624 | let str = trim(join(chars, '')) |
| 625 | call assert_equal('', str) |
| 626 | |
| 627 | set showmode& |
| 628 | %bw! |
| 629 | endfunc |
| 630 | |
Bram Moolenaar | 5bab555 | 2018-04-13 20:41:29 +0200 | [diff] [blame] | 631 | func Test_visual_cleared_after_window_split() |
| 632 | new | only! |
| 633 | let smd_save = &showmode |
| 634 | set showmode |
| 635 | let ls_save = &laststatus |
| 636 | set laststatus=1 |
| 637 | call setline(1, ['a', 'b', 'c', 'd', '']) |
| 638 | norm! G |
| 639 | exe "norm! kkvk" |
| 640 | redraw |
| 641 | exe "norm! \<C-W>v" |
| 642 | redraw |
| 643 | " check if '-- VISUAL --' disappeared from command line |
| 644 | let columns = range(1, &columns) |
| 645 | let cmdlinechars = map(columns, 'nr2char(screenchar(&lines, v:val))') |
| 646 | let cmdline = join(cmdlinechars, '') |
| 647 | let cmdline_ltrim = substitute(cmdline, '^\s*', "", "") |
| 648 | let mode_shown = substitute(cmdline_ltrim, '\s*$', "", "") |
| 649 | call assert_equal('', mode_shown) |
| 650 | let &showmode = smd_save |
| 651 | let &laststatus = ls_save |
| 652 | bwipe! |
| 653 | endfunc |
| 654 | |
Bram Moolenaar | 72cf47a | 2018-05-10 18:23:29 +0200 | [diff] [blame] | 655 | func Test_winrestcmd() |
| 656 | 2split |
| 657 | 3vsplit |
| 658 | let a = winrestcmd() |
| 659 | call assert_equal(2, winheight(0)) |
| 660 | call assert_equal(3, winwidth(0)) |
| 661 | wincmd = |
| 662 | call assert_notequal(2, winheight(0)) |
| 663 | call assert_notequal(3, winwidth(0)) |
| 664 | exe a |
| 665 | call assert_equal(2, winheight(0)) |
| 666 | call assert_equal(3, winwidth(0)) |
| 667 | only |
| 668 | endfunc |
| 669 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 670 | func Fun_RenewFile() |
Bram Moolenaar | 026587b | 2019-08-17 15:08:00 +0200 | [diff] [blame] | 671 | " Need to wait a bit for the timestamp to be older. |
Bram Moolenaar | ce90e36 | 2019-09-08 18:58:44 +0200 | [diff] [blame] | 672 | let old_ftime = getftime("tmp.txt") |
| 673 | while getftime("tmp.txt") == old_ftime |
| 674 | sleep 100m |
| 675 | silent execute '!echo "1" > tmp.txt' |
| 676 | endwhile |
Bram Moolenaar | a42df59 | 2018-12-24 00:22:39 +0100 | [diff] [blame] | 677 | sp |
| 678 | wincmd p |
| 679 | edit! tmp.txt |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 680 | endfunc |
Bram Moolenaar | a42df59 | 2018-12-24 00:22:39 +0100 | [diff] [blame] | 681 | |
| 682 | func Test_window_prevwin() |
| 683 | " Can we make this work on MS-Windows? |
| 684 | if !has('unix') |
| 685 | return |
| 686 | endif |
| 687 | |
| 688 | set hidden autoread |
| 689 | call writefile(['2'], 'tmp.txt') |
| 690 | new tmp.txt |
| 691 | q |
Bram Moolenaar | a42df59 | 2018-12-24 00:22:39 +0100 | [diff] [blame] | 692 | call Fun_RenewFile() |
| 693 | call assert_equal(2, winnr()) |
| 694 | wincmd p |
| 695 | call assert_equal(1, winnr()) |
| 696 | wincmd p |
| 697 | q |
| 698 | call Fun_RenewFile() |
| 699 | call assert_equal(2, winnr()) |
| 700 | wincmd p |
| 701 | call assert_equal(1, winnr()) |
| 702 | wincmd p |
| 703 | " reset |
| 704 | q |
| 705 | call delete('tmp.txt') |
| 706 | set hidden&vim autoread&vim |
| 707 | delfunc Fun_RenewFile |
| 708 | endfunc |
| 709 | |
Bram Moolenaar | 8fcb60f | 2019-03-04 13:18:30 +0100 | [diff] [blame] | 710 | func Test_relative_cursor_position_in_one_line_window() |
| 711 | new |
| 712 | only |
| 713 | call setline(1, range(1, 10000)) |
| 714 | normal 50% |
| 715 | let lnum = getcurpos()[1] |
| 716 | split |
| 717 | split |
| 718 | " make third window take as many lines as possible, other windows will |
| 719 | " become one line |
| 720 | 3wincmd w |
| 721 | for i in range(1, &lines - 6) |
| 722 | wincmd + |
| 723 | redraw! |
| 724 | endfor |
| 725 | |
| 726 | " first and second window should show cursor line |
| 727 | let wininfo = getwininfo() |
| 728 | call assert_equal(lnum, wininfo[0].topline) |
| 729 | call assert_equal(lnum, wininfo[1].topline) |
| 730 | |
| 731 | only! |
| 732 | bwipe! |
| 733 | endfunc |
| 734 | |
| 735 | func Test_relative_cursor_position_after_move_and_resize() |
| 736 | let so_save = &so |
| 737 | set so=0 |
| 738 | enew |
| 739 | call setline(1, range(1, 10000)) |
| 740 | normal 50% |
| 741 | split |
| 742 | 1wincmd w |
| 743 | " Move cursor to first line in window |
| 744 | normal H |
| 745 | redraw! |
| 746 | " Reduce window height to two lines |
| 747 | let height = winheight(0) |
| 748 | while winheight(0) > 2 |
| 749 | wincmd - |
| 750 | redraw! |
| 751 | endwhile |
| 752 | " move cursor to second/last line in window |
| 753 | normal j |
| 754 | " restore previous height |
| 755 | while winheight(0) < height |
| 756 | wincmd + |
| 757 | redraw! |
| 758 | endwhile |
| 759 | " make window two lines again |
| 760 | while winheight(0) > 2 |
| 761 | wincmd - |
| 762 | redraw! |
| 763 | endwhile |
| 764 | |
| 765 | " cursor should be at bottom line |
| 766 | let info = getwininfo(win_getid())[0] |
| 767 | call assert_equal(info.topline + 1, getcurpos()[1]) |
| 768 | |
| 769 | only! |
| 770 | bwipe! |
| 771 | let &so = so_save |
| 772 | endfunc |
| 773 | |
| 774 | func Test_relative_cursor_position_after_resize() |
| 775 | let so_save = &so |
| 776 | set so=0 |
| 777 | enew |
| 778 | call setline(1, range(1, 10000)) |
| 779 | normal 50% |
| 780 | split |
| 781 | 1wincmd w |
| 782 | let winid1 = win_getid() |
| 783 | let info = getwininfo(winid1)[0] |
| 784 | " Move cursor to second line in window |
| 785 | exe "normal " . (info.topline + 1) . "G" |
| 786 | redraw! |
| 787 | let lnum = getcurpos()[1] |
| 788 | |
| 789 | " Make the window only two lines high, cursor should end up in top line |
| 790 | 2wincmd w |
| 791 | exe (info.height - 2) . "wincmd +" |
| 792 | redraw! |
| 793 | let info = getwininfo(winid1)[0] |
| 794 | call assert_equal(lnum, info.topline) |
| 795 | |
| 796 | only! |
| 797 | bwipe! |
| 798 | let &so = so_save |
| 799 | endfunc |
| 800 | |
| 801 | func Test_relative_cursor_second_line_after_resize() |
| 802 | let so_save = &so |
| 803 | set so=0 |
| 804 | enew |
| 805 | call setline(1, range(1, 10000)) |
| 806 | normal 50% |
| 807 | split |
| 808 | 1wincmd w |
| 809 | let winid1 = win_getid() |
| 810 | let info = getwininfo(winid1)[0] |
| 811 | |
| 812 | " Make the window only two lines high |
| 813 | 2wincmd _ |
| 814 | |
| 815 | " Move cursor to second line in window |
| 816 | normal H |
| 817 | normal j |
| 818 | |
| 819 | " Make window size bigger, then back to 2 lines |
| 820 | for i in range(1, 10) |
| 821 | wincmd + |
| 822 | redraw! |
| 823 | endfor |
| 824 | for i in range(1, 10) |
| 825 | wincmd - |
| 826 | redraw! |
| 827 | endfor |
| 828 | |
| 829 | " cursor should end up in bottom line |
| 830 | let info = getwininfo(winid1)[0] |
| 831 | call assert_equal(info.topline + 1, getcurpos()[1]) |
| 832 | |
| 833 | only! |
| 834 | bwipe! |
| 835 | let &so = so_save |
| 836 | endfunc |
| 837 | |
Bram Moolenaar | a9b2535 | 2019-05-12 14:25:30 +0200 | [diff] [blame] | 838 | func Test_split_noscroll() |
| 839 | let so_save = &so |
Bram Moolenaar | bd2d68c | 2019-05-18 15:36:11 +0200 | [diff] [blame] | 840 | enew |
| 841 | call setline(1, range(1, 8)) |
Bram Moolenaar | a9b2535 | 2019-05-12 14:25:30 +0200 | [diff] [blame] | 842 | normal 100% |
| 843 | split |
| 844 | |
| 845 | 1wincmd w |
| 846 | let winid1 = win_getid() |
| 847 | let info1 = getwininfo(winid1)[0] |
| 848 | |
| 849 | 2wincmd w |
| 850 | let winid2 = win_getid() |
| 851 | let info2 = getwininfo(winid2)[0] |
| 852 | |
| 853 | call assert_equal(1, info1.topline) |
| 854 | call assert_equal(1, info2.topline) |
| 855 | |
Bram Moolenaar | bd2d68c | 2019-05-18 15:36:11 +0200 | [diff] [blame] | 856 | " window that fits all lines by itself, but not when split: closing other |
| 857 | " window should restore fraction. |
Bram Moolenaar | a9b2535 | 2019-05-12 14:25:30 +0200 | [diff] [blame] | 858 | only! |
Bram Moolenaar | bd2d68c | 2019-05-18 15:36:11 +0200 | [diff] [blame] | 859 | call setline(1, range(1, &lines - 10)) |
| 860 | exe &lines / 4 |
| 861 | let winid1 = win_getid() |
| 862 | let info1 = getwininfo(winid1)[0] |
| 863 | call assert_equal(1, info1.topline) |
| 864 | new |
| 865 | redraw |
| 866 | close |
| 867 | let info1 = getwininfo(winid1)[0] |
| 868 | call assert_equal(1, info1.topline) |
| 869 | |
Bram Moolenaar | a9b2535 | 2019-05-12 14:25:30 +0200 | [diff] [blame] | 870 | bwipe! |
| 871 | let &so = so_save |
| 872 | endfunc |
| 873 | |
Bram Moolenaar | 46ad288 | 2019-04-08 20:01:47 +0200 | [diff] [blame] | 874 | " Tests for the winnr() function |
| 875 | func Test_winnr() |
| 876 | only | tabonly |
| 877 | call assert_equal(1, winnr('j')) |
| 878 | call assert_equal(1, winnr('k')) |
| 879 | call assert_equal(1, winnr('h')) |
| 880 | call assert_equal(1, winnr('l')) |
| 881 | |
| 882 | " create a set of horizontally and vertically split windows |
| 883 | leftabove new | wincmd p |
| 884 | leftabove new | wincmd p |
| 885 | rightbelow new | wincmd p |
| 886 | rightbelow new | wincmd p |
| 887 | leftabove vnew | wincmd p |
| 888 | leftabove vnew | wincmd p |
| 889 | rightbelow vnew | wincmd p |
| 890 | rightbelow vnew | wincmd p |
| 891 | |
| 892 | call assert_equal(8, winnr('j')) |
| 893 | call assert_equal(2, winnr('k')) |
| 894 | call assert_equal(4, winnr('h')) |
| 895 | call assert_equal(6, winnr('l')) |
| 896 | call assert_equal(9, winnr('2j')) |
| 897 | call assert_equal(1, winnr('2k')) |
| 898 | call assert_equal(3, winnr('2h')) |
| 899 | call assert_equal(7, winnr('2l')) |
| 900 | |
| 901 | " Error cases |
| 902 | call assert_fails("echo winnr('0.2k')", 'E15:') |
| 903 | call assert_equal(2, winnr('-2k')) |
| 904 | call assert_fails("echo winnr('-2xj')", 'E15:') |
| 905 | call assert_fails("echo winnr('j2j')", 'E15:') |
| 906 | call assert_fails("echo winnr('ll')", 'E15:') |
| 907 | call assert_fails("echo winnr('5')", 'E15:') |
| 908 | call assert_equal(4, winnr('0h')) |
| 909 | |
| 910 | tabnew |
| 911 | call assert_equal(8, tabpagewinnr(1, 'j')) |
Bram Moolenaar | ce90e36 | 2019-09-08 18:58:44 +0200 | [diff] [blame] | 912 | call assert_equal(2, 1->tabpagewinnr('k')) |
Bram Moolenaar | 46ad288 | 2019-04-08 20:01:47 +0200 | [diff] [blame] | 913 | call assert_equal(4, tabpagewinnr(1, 'h')) |
| 914 | call assert_equal(6, tabpagewinnr(1, 'l')) |
| 915 | |
| 916 | only | tabonly |
| 917 | endfunc |
| 918 | |
Bram Moolenaar | f92e58c | 2019-09-08 21:51:41 +0200 | [diff] [blame] | 919 | func Test_winrestview() |
| 920 | split runtest.vim |
| 921 | normal 50% |
| 922 | let view = winsaveview() |
| 923 | close |
| 924 | split runtest.vim |
| 925 | eval view->winrestview() |
| 926 | call assert_equal(view, winsaveview()) |
| 927 | |
| 928 | bwipe! |
| 929 | endfunc |
| 930 | |
Bram Moolenaar | d20dcb3 | 2019-09-10 21:22:58 +0200 | [diff] [blame] | 931 | func Test_win_splitmove() |
Bram Moolenaar | 5a4c308 | 2019-12-01 15:23:11 +0100 | [diff] [blame] | 932 | CheckFeature quickfix |
| 933 | |
Bram Moolenaar | d20dcb3 | 2019-09-10 21:22:58 +0200 | [diff] [blame] | 934 | edit a |
| 935 | leftabove split b |
| 936 | leftabove vsplit c |
| 937 | leftabove split d |
| 938 | call assert_equal(0, win_splitmove(winnr(), winnr('l'))) |
| 939 | call assert_equal(bufname(winbufnr(1)), 'c') |
| 940 | call assert_equal(bufname(winbufnr(2)), 'd') |
| 941 | call assert_equal(bufname(winbufnr(3)), 'b') |
| 942 | call assert_equal(bufname(winbufnr(4)), 'a') |
| 943 | call assert_equal(0, win_splitmove(winnr(), winnr('j'), {'vertical': 1})) |
| 944 | call assert_equal(0, win_splitmove(winnr(), winnr('j'), {'vertical': 1})) |
| 945 | call assert_equal(bufname(winbufnr(1)), 'c') |
| 946 | call assert_equal(bufname(winbufnr(2)), 'b') |
| 947 | call assert_equal(bufname(winbufnr(3)), 'd') |
| 948 | call assert_equal(bufname(winbufnr(4)), 'a') |
| 949 | call assert_equal(0, win_splitmove(winnr(), winnr('k'), {'vertical': 1})) |
| 950 | call assert_equal(bufname(winbufnr(1)), 'd') |
| 951 | call assert_equal(bufname(winbufnr(2)), 'c') |
| 952 | call assert_equal(bufname(winbufnr(3)), 'b') |
| 953 | call assert_equal(bufname(winbufnr(4)), 'a') |
| 954 | call assert_equal(0, win_splitmove(winnr(), winnr('j'), {'rightbelow': v:true})) |
| 955 | call assert_equal(bufname(winbufnr(1)), 'c') |
| 956 | call assert_equal(bufname(winbufnr(2)), 'b') |
| 957 | call assert_equal(bufname(winbufnr(3)), 'a') |
| 958 | call assert_equal(bufname(winbufnr(4)), 'd') |
| 959 | only | bd |
| 960 | |
| 961 | call assert_fails('call win_splitmove(winnr(), 123)', 'E957:') |
| 962 | call assert_fails('call win_splitmove(123, winnr())', 'E957:') |
| 963 | call assert_fails('call win_splitmove(winnr(), winnr())', 'E957:') |
Bram Moolenaar | 7b94e77 | 2020-01-06 21:03:24 +0100 | [diff] [blame] | 964 | |
| 965 | tabnew |
| 966 | call assert_fails('call win_splitmove(1, win_getid(1, 1))', 'E957:') |
| 967 | tabclose |
Bram Moolenaar | d20dcb3 | 2019-09-10 21:22:58 +0200 | [diff] [blame] | 968 | endfunc |
| 969 | |
Bram Moolenaar | e20b9ec | 2020-02-03 21:40:04 +0100 | [diff] [blame] | 970 | " Test for the :only command |
| 971 | func Test_window_only() |
| 972 | new |
| 973 | set modified |
| 974 | new |
| 975 | call assert_fails('only', 'E445:') |
| 976 | only! |
Bram Moolenaar | bc2b71d | 2020-02-17 21:33:30 +0100 | [diff] [blame] | 977 | " Test for :only with a count |
| 978 | let wid = win_getid() |
| 979 | new |
| 980 | new |
| 981 | 3only |
| 982 | call assert_equal(1, winnr('$')) |
| 983 | call assert_equal(wid, win_getid()) |
| 984 | call assert_fails('close', 'E444:') |
| 985 | call assert_fails('%close', 'E16:') |
Bram Moolenaar | e20b9ec | 2020-02-03 21:40:04 +0100 | [diff] [blame] | 986 | endfunc |
| 987 | |
Bram Moolenaar | 9f6277b | 2020-02-11 22:04:02 +0100 | [diff] [blame] | 988 | " Test for errors with :wincmd |
| 989 | func Test_wincmd_errors() |
| 990 | call assert_fails('wincmd g', 'E474:') |
| 991 | call assert_fails('wincmd ab', 'E474:') |
| 992 | endfunc |
| 993 | |
| 994 | " Test for errors with :winpos |
| 995 | func Test_winpos_errors() |
| 996 | if !has("gui_running") && !has('win32') |
| 997 | call assert_fails('winpos', 'E188:') |
| 998 | endif |
| 999 | call assert_fails('winpos 10', 'E466:') |
| 1000 | endfunc |
| 1001 | |
Bram Moolenaar | 406cd90 | 2020-02-18 21:54:41 +0100 | [diff] [blame] | 1002 | " Test for +cmd in a :split command |
| 1003 | func Test_split_cmd() |
| 1004 | split +set\ readonly |
| 1005 | call assert_equal(1, &readonly) |
| 1006 | call assert_equal(2, winnr('$')) |
| 1007 | close |
| 1008 | endfunc |
| 1009 | |
Bram Moolenaar | 5080b0a | 2020-03-22 21:23:47 +0100 | [diff] [blame] | 1010 | " Create maximum number of horizontally or vertically split windows and then |
| 1011 | " run commands that create a new horizontally/vertically split window |
| 1012 | func Run_noroom_for_newwindow_test(dir_arg) |
| 1013 | let dir = (a:dir_arg == 'v') ? 'vert ' : '' |
| 1014 | |
| 1015 | " Open as many windows as possible |
Bram Moolenaar | ab505b1 | 2020-03-23 19:28:44 +0100 | [diff] [blame^] | 1016 | while v:true |
Bram Moolenaar | 5080b0a | 2020-03-22 21:23:47 +0100 | [diff] [blame] | 1017 | try |
| 1018 | exe dir . 'new' |
| 1019 | catch /E36:/ |
| 1020 | break |
| 1021 | endtry |
Bram Moolenaar | ab505b1 | 2020-03-23 19:28:44 +0100 | [diff] [blame^] | 1022 | endwhile |
Bram Moolenaar | 5080b0a | 2020-03-22 21:23:47 +0100 | [diff] [blame] | 1023 | |
| 1024 | call writefile(['first', 'second', 'third'], 'Xfile1') |
| 1025 | call writefile([], 'Xfile2') |
| 1026 | call writefile([], 'Xfile3') |
| 1027 | |
| 1028 | " Argument list related commands |
| 1029 | args Xfile1 Xfile2 Xfile3 |
| 1030 | next |
| 1031 | for cmd in ['sargument 2', 'snext', 'sprevious', 'sNext', 'srewind', |
| 1032 | \ 'sfirst', 'slast'] |
| 1033 | call assert_fails(dir .. cmd, 'E36:') |
| 1034 | endfor |
| 1035 | %argdelete |
| 1036 | |
| 1037 | " Buffer related commands |
| 1038 | set modified |
| 1039 | hide enew |
| 1040 | for cmd in ['sbuffer Xfile1', 'sbnext', 'sbprevious', 'sbNext', 'sbrewind', |
| 1041 | \ 'sbfirst', 'sblast', 'sball', 'sbmodified', 'sunhide'] |
| 1042 | call assert_fails(dir .. cmd, 'E36:') |
| 1043 | endfor |
| 1044 | |
| 1045 | " Window related commands |
| 1046 | for cmd in ['split', 'split Xfile2', 'new', 'new Xfile3', 'sview Xfile1', |
| 1047 | \ 'sfind runtest.vim'] |
| 1048 | call assert_fails(dir .. cmd, 'E36:') |
| 1049 | endfor |
| 1050 | |
| 1051 | " Help |
| 1052 | call assert_fails(dir .. 'help', 'E36:') |
| 1053 | call assert_fails(dir .. 'helpgrep window', 'E36:') |
| 1054 | |
| 1055 | " Command-line window |
| 1056 | if a:dir_arg == 'h' |
| 1057 | " Cmd-line window is always a horizontally split window |
| 1058 | call assert_beeps('call feedkeys("q:\<CR>", "xt")') |
| 1059 | endif |
| 1060 | |
| 1061 | " Quickfix and location list window |
| 1062 | if has('quickfix') |
| 1063 | cexpr '' |
| 1064 | call assert_fails(dir .. 'copen', 'E36:') |
| 1065 | lexpr '' |
| 1066 | call assert_fails(dir .. 'lopen', 'E36:') |
| 1067 | |
| 1068 | " Preview window |
| 1069 | call assert_fails(dir .. 'pedit Xfile2', 'E36:') |
| 1070 | call setline(1, 'abc') |
| 1071 | call assert_fails(dir .. 'psearch abc', 'E36:') |
| 1072 | endif |
| 1073 | |
| 1074 | " Window commands (CTRL-W ^ and CTRL-W f) |
| 1075 | if a:dir_arg == 'h' |
| 1076 | call assert_fails('call feedkeys("\<C-W>^", "xt")', 'E36:') |
| 1077 | call setline(1, 'Xfile1') |
| 1078 | call assert_fails('call feedkeys("gg\<C-W>f", "xt")', 'E36:') |
| 1079 | endif |
| 1080 | enew! |
| 1081 | |
| 1082 | " Tag commands (:stag, :stselect and :stjump) |
| 1083 | call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", |
| 1084 | \ "second\tXfile1\t2", |
| 1085 | \ "third\tXfile1\t3",], |
| 1086 | \ 'Xtags') |
| 1087 | set tags=Xtags |
| 1088 | call assert_fails(dir .. 'stag second', 'E36:') |
| 1089 | call assert_fails('call feedkeys(":" .. dir .. "stselect second\n1\n", "xt")', 'E36:') |
| 1090 | call assert_fails(dir .. 'stjump second', 'E36:') |
| 1091 | call assert_fails(dir .. 'ptag second', 'E36:') |
| 1092 | set tags& |
| 1093 | call delete('Xtags') |
| 1094 | |
| 1095 | " :isplit and :dsplit |
| 1096 | call setline(1, ['#define FOO 1', 'FOO']) |
| 1097 | normal 2G |
| 1098 | call assert_fails(dir .. 'isplit FOO', 'E36:') |
| 1099 | call assert_fails(dir .. 'dsplit FOO', 'E36:') |
| 1100 | |
| 1101 | " terminal |
| 1102 | if has('terminal') |
| 1103 | call assert_fails(dir .. 'terminal', 'E36:') |
| 1104 | endif |
| 1105 | |
| 1106 | %bwipe! |
| 1107 | call delete('Xfile1') |
| 1108 | call delete('Xfile2') |
| 1109 | call delete('Xfile3') |
| 1110 | only |
| 1111 | endfunc |
| 1112 | |
| 1113 | func Test_split_cmds_with_no_room() |
| 1114 | call Run_noroom_for_newwindow_test('h') |
| 1115 | call Run_noroom_for_newwindow_test('v') |
| 1116 | endfunc |
| 1117 | |
Bram Moolenaar | 9e4d821 | 2016-08-18 23:04:48 +0200 | [diff] [blame] | 1118 | " vim: shiftwidth=2 sts=2 expandtab |