Bram Moolenaar | 991dea3 | 2016-05-24 11:31:32 +0200 | [diff] [blame] | 1 | " Tests for window cmd (:wincmd, :split, :vsplit, :resize and etc...) |
| 2 | |
| 3 | func Test_window_cmd_ls0_with_split() |
| 4 | set ls=0 |
| 5 | set splitbelow |
| 6 | split |
| 7 | quit |
| 8 | call assert_equal(0, &lines - &cmdheight - winheight(0)) |
| 9 | new | only! |
| 10 | " |
| 11 | set splitbelow&vim |
| 12 | botright split |
| 13 | quit |
| 14 | call assert_equal(0, &lines - &cmdheight - winheight(0)) |
| 15 | new | only! |
| 16 | set ls&vim |
| 17 | endfunc |
| 18 | |
| 19 | func Test_window_cmd_cmdwin_with_vsp() |
Bram Moolenaar | 72cf47a | 2018-05-10 18:23:29 +0200 | [diff] [blame] | 20 | let efmt = 'Expected 0 but got %d (in ls=%d, %s window)' |
Bram Moolenaar | 991dea3 | 2016-05-24 11:31:32 +0200 | [diff] [blame] | 21 | for v in range(0, 2) |
| 22 | exec "set ls=" . v |
| 23 | vsplit |
| 24 | call feedkeys("q:\<CR>") |
| 25 | let ac = &lines - (&cmdheight + winheight(0) + !!v) |
| 26 | let emsg = printf(efmt, ac, v, 'left') |
| 27 | call assert_equal(0, ac, emsg) |
| 28 | wincmd w |
| 29 | let ac = &lines - (&cmdheight + winheight(0) + !!v) |
| 30 | let emsg = printf(efmt, ac, v, 'right') |
| 31 | call assert_equal(0, ac, emsg) |
| 32 | new | only! |
| 33 | endfor |
| 34 | set ls&vim |
| 35 | endfunc |
| 36 | |
Bram Moolenaar | 5d2ca04 | 2016-06-26 17:11:21 +0200 | [diff] [blame] | 37 | function Test_window_cmd_wincmd_gf() |
| 38 | let fname = 'test_gf.txt' |
| 39 | let swp_fname = '.' . fname . '.swp' |
| 40 | call writefile([], fname) |
| 41 | call writefile([], swp_fname) |
| 42 | function s:swap_exists() |
| 43 | let v:swapchoice = s:swap_choice |
| 44 | endfunc |
| 45 | augroup test_window_cmd_wincmd_gf |
| 46 | autocmd! |
| 47 | exec "autocmd SwapExists " . fname . " call s:swap_exists()" |
| 48 | augroup END |
| 49 | |
| 50 | call setline(1, fname) |
| 51 | " (E)dit anyway |
| 52 | let s:swap_choice = 'e' |
| 53 | wincmd gf |
| 54 | call assert_equal(2, tabpagenr()) |
| 55 | call assert_equal(fname, bufname("%")) |
| 56 | quit! |
| 57 | |
| 58 | " (Q)uit |
| 59 | let s:swap_choice = 'q' |
| 60 | wincmd gf |
| 61 | call assert_equal(1, tabpagenr()) |
| 62 | call assert_notequal(fname, bufname("%")) |
| 63 | new | only! |
| 64 | |
| 65 | call delete(fname) |
| 66 | call delete(swp_fname) |
| 67 | augroup! test_window_cmd_wincmd_gf |
| 68 | endfunc |
| 69 | |
Bram Moolenaar | 4520d44 | 2017-03-19 16:09:46 +0100 | [diff] [blame] | 70 | func Test_window_quit() |
| 71 | e Xa |
| 72 | split Xb |
| 73 | call assert_equal(2, winnr('$')) |
| 74 | call assert_equal('Xb', bufname(winbufnr(1))) |
| 75 | call assert_equal('Xa', bufname(winbufnr(2))) |
| 76 | |
| 77 | wincmd q |
| 78 | call assert_equal(1, winnr('$')) |
| 79 | call assert_equal('Xa', bufname(winbufnr(1))) |
| 80 | |
| 81 | bw Xa Xb |
| 82 | endfunc |
| 83 | |
| 84 | func Test_window_horizontal_split() |
| 85 | call assert_equal(1, winnr('$')) |
| 86 | 3wincmd s |
| 87 | call assert_equal(2, winnr('$')) |
| 88 | call assert_equal(3, winheight(0)) |
| 89 | call assert_equal(winwidth(1), winwidth(2)) |
| 90 | |
| 91 | call assert_fails('botright topleft wincmd s', 'E442:') |
| 92 | bw |
| 93 | endfunc |
| 94 | |
| 95 | func Test_window_vertical_split() |
| 96 | call assert_equal(1, winnr('$')) |
| 97 | 3wincmd v |
| 98 | call assert_equal(2, winnr('$')) |
| 99 | call assert_equal(3, winwidth(0)) |
| 100 | call assert_equal(winheight(1), winheight(2)) |
| 101 | |
| 102 | call assert_fails('botright topleft wincmd v', 'E442:') |
| 103 | bw |
| 104 | endfunc |
| 105 | |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 106 | " Test the ":wincmd ^" and "<C-W>^" commands. |
Bram Moolenaar | 4520d44 | 2017-03-19 16:09:46 +0100 | [diff] [blame] | 107 | func Test_window_split_edit_alternate() |
Bram Moolenaar | 4520d44 | 2017-03-19 16:09:46 +0100 | [diff] [blame] | 108 | |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 109 | " Test for failure when the alternate buffer/file no longer exists. |
| 110 | edit Xfoo | %bw |
| 111 | call assert_fails(':wincmd ^', 'E23') |
| 112 | |
| 113 | " Test for the expected behavior when we have two named buffers. |
| 114 | edit Xfoo | edit Xbar |
Bram Moolenaar | 4520d44 | 2017-03-19 16:09:46 +0100 | [diff] [blame] | 115 | wincmd ^ |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 116 | call assert_equal('Xfoo', bufname(winbufnr(1))) |
| 117 | call assert_equal('Xbar', bufname(winbufnr(2))) |
| 118 | only |
Bram Moolenaar | 4520d44 | 2017-03-19 16:09:46 +0100 | [diff] [blame] | 119 | |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 120 | " Test for the expected behavior when the alternate buffer is not named. |
| 121 | enew | let l:nr1 = bufnr('%') |
| 122 | edit Xfoo | let l:nr2 = bufnr('%') |
| 123 | wincmd ^ |
| 124 | call assert_equal(l:nr1, winbufnr(1)) |
| 125 | call assert_equal(l:nr2, winbufnr(2)) |
| 126 | only |
| 127 | |
Bram Moolenaar | d42333d | 2018-11-10 20:28:19 +0100 | [diff] [blame] | 128 | " FIXME: this currently fails on AppVeyor, but passes locally |
| 129 | if !has('win32') |
| 130 | " Test the Normal mode command. |
| 131 | call feedkeys("\<C-W>\<C-^>", 'tx') |
| 132 | call assert_equal(l:nr2, winbufnr(1)) |
| 133 | call assert_equal(l:nr1, winbufnr(2)) |
| 134 | endif |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 135 | |
| 136 | %bw! |
| 137 | endfunc |
| 138 | |
| 139 | " Test the ":[count]wincmd ^" and "[count]<C-W>^" commands. |
| 140 | func Test_window_split_edit_bufnr() |
| 141 | |
| 142 | %bwipeout |
| 143 | let l:nr = bufnr('%') + 1 |
| 144 | call assert_fails(':execute "normal! ' . l:nr . '\<C-W>\<C-^>"', 'E92') |
| 145 | call assert_fails(':' . l:nr . 'wincmd ^', 'E16') |
| 146 | call assert_fails(':0wincmd ^', 'E16') |
| 147 | |
| 148 | edit Xfoo | edit Xbar | edit Xbaz |
| 149 | let l:foo_nr = bufnr('Xfoo') |
| 150 | let l:bar_nr = bufnr('Xbar') |
| 151 | let l:baz_nr = bufnr('Xbaz') |
| 152 | |
Bram Moolenaar | 8617b40 | 2018-11-10 20:47:48 +0100 | [diff] [blame] | 153 | " FIXME: this currently fails on AppVeyor, but passes locally |
| 154 | if !has('win32') |
| 155 | call feedkeys(l:foo_nr . "\<C-W>\<C-^>", 'tx') |
| 156 | call assert_equal('Xfoo', bufname(winbufnr(1))) |
| 157 | call assert_equal('Xbaz', bufname(winbufnr(2))) |
| 158 | only |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 159 | |
Bram Moolenaar | 8617b40 | 2018-11-10 20:47:48 +0100 | [diff] [blame] | 160 | call feedkeys(l:bar_nr . "\<C-W>\<C-^>", 'tx') |
| 161 | call assert_equal('Xbar', bufname(winbufnr(1))) |
| 162 | call assert_equal('Xfoo', bufname(winbufnr(2))) |
| 163 | only |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 164 | |
Bram Moolenaar | 8617b40 | 2018-11-10 20:47:48 +0100 | [diff] [blame] | 165 | execute l:baz_nr . 'wincmd ^' |
| 166 | call assert_equal('Xbaz', bufname(winbufnr(1))) |
| 167 | call assert_equal('Xbar', bufname(winbufnr(2))) |
| 168 | endif |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 169 | |
| 170 | %bw! |
Bram Moolenaar | 4520d44 | 2017-03-19 16:09:46 +0100 | [diff] [blame] | 171 | endfunc |
| 172 | |
| 173 | func Test_window_preview() |
| 174 | " Open a preview window |
| 175 | pedit Xa |
| 176 | call assert_equal(2, winnr('$')) |
| 177 | call assert_equal(0, &previewwindow) |
| 178 | |
| 179 | " Go to the preview window |
| 180 | wincmd P |
| 181 | call assert_equal(1, &previewwindow) |
| 182 | |
| 183 | " Close preview window |
| 184 | wincmd z |
| 185 | call assert_equal(1, winnr('$')) |
| 186 | call assert_equal(0, &previewwindow) |
| 187 | |
| 188 | call assert_fails('wincmd P', 'E441:') |
| 189 | endfunc |
| 190 | |
| 191 | func Test_window_exchange() |
| 192 | e Xa |
| 193 | |
| 194 | " Nothing happens with window exchange when there is 1 window |
| 195 | wincmd x |
| 196 | call assert_equal(1, winnr('$')) |
| 197 | |
| 198 | split Xb |
| 199 | split Xc |
| 200 | |
| 201 | call assert_equal('Xc', bufname(winbufnr(1))) |
| 202 | call assert_equal('Xb', bufname(winbufnr(2))) |
| 203 | call assert_equal('Xa', bufname(winbufnr(3))) |
| 204 | |
| 205 | " Exchange current window 1 with window 3 |
| 206 | 3wincmd x |
| 207 | call assert_equal('Xa', bufname(winbufnr(1))) |
| 208 | call assert_equal('Xb', bufname(winbufnr(2))) |
| 209 | call assert_equal('Xc', bufname(winbufnr(3))) |
| 210 | |
| 211 | " Exchange window with next when at the top window |
| 212 | wincmd x |
| 213 | call assert_equal('Xb', bufname(winbufnr(1))) |
| 214 | call assert_equal('Xa', bufname(winbufnr(2))) |
| 215 | call assert_equal('Xc', bufname(winbufnr(3))) |
| 216 | |
| 217 | " Exchange window with next when at the middle window |
| 218 | wincmd j |
| 219 | wincmd x |
| 220 | call assert_equal('Xb', bufname(winbufnr(1))) |
| 221 | call assert_equal('Xc', bufname(winbufnr(2))) |
| 222 | call assert_equal('Xa', bufname(winbufnr(3))) |
| 223 | |
| 224 | " Exchange window with next when at the bottom window. |
| 225 | " When there is no next window, it exchanges with the previous window. |
| 226 | wincmd j |
| 227 | wincmd x |
| 228 | call assert_equal('Xb', bufname(winbufnr(1))) |
| 229 | call assert_equal('Xa', bufname(winbufnr(2))) |
| 230 | call assert_equal('Xc', bufname(winbufnr(3))) |
| 231 | |
| 232 | bw Xa Xb Xc |
| 233 | endfunc |
| 234 | |
| 235 | func Test_window_rotate() |
| 236 | e Xa |
| 237 | split Xb |
| 238 | split Xc |
| 239 | call assert_equal('Xc', bufname(winbufnr(1))) |
| 240 | call assert_equal('Xb', bufname(winbufnr(2))) |
| 241 | call assert_equal('Xa', bufname(winbufnr(3))) |
| 242 | |
| 243 | " Rotate downwards |
| 244 | wincmd r |
| 245 | call assert_equal('Xa', bufname(winbufnr(1))) |
| 246 | call assert_equal('Xc', bufname(winbufnr(2))) |
| 247 | call assert_equal('Xb', bufname(winbufnr(3))) |
| 248 | |
| 249 | 2wincmd r |
| 250 | call assert_equal('Xc', bufname(winbufnr(1))) |
| 251 | call assert_equal('Xb', bufname(winbufnr(2))) |
| 252 | call assert_equal('Xa', bufname(winbufnr(3))) |
| 253 | |
| 254 | " Rotate upwards |
| 255 | wincmd R |
| 256 | call assert_equal('Xb', bufname(winbufnr(1))) |
| 257 | call assert_equal('Xa', bufname(winbufnr(2))) |
| 258 | call assert_equal('Xc', bufname(winbufnr(3))) |
| 259 | |
| 260 | 2wincmd R |
| 261 | call assert_equal('Xc', bufname(winbufnr(1))) |
| 262 | call assert_equal('Xb', bufname(winbufnr(2))) |
| 263 | call assert_equal('Xa', bufname(winbufnr(3))) |
| 264 | |
| 265 | bot vsplit |
| 266 | call assert_fails('wincmd R', 'E443:') |
| 267 | |
| 268 | bw Xa Xb Xc |
| 269 | endfunc |
| 270 | |
| 271 | func Test_window_height() |
| 272 | e Xa |
| 273 | split Xb |
| 274 | |
| 275 | let [wh1, wh2] = [winheight(1), winheight(2)] |
| 276 | " Active window (1) should have the same height or 1 more |
| 277 | " than the other window. |
| 278 | call assert_inrange(wh2, wh2 + 1, wh1) |
| 279 | |
| 280 | wincmd - |
| 281 | call assert_equal(wh1 - 1, winheight(1)) |
| 282 | call assert_equal(wh2 + 1, winheight(2)) |
| 283 | |
| 284 | wincmd + |
| 285 | call assert_equal(wh1, winheight(1)) |
| 286 | call assert_equal(wh2, winheight(2)) |
| 287 | |
| 288 | 2wincmd _ |
| 289 | call assert_equal(2, winheight(1)) |
| 290 | call assert_equal(wh1 + wh2 - 2, winheight(2)) |
| 291 | |
| 292 | wincmd = |
| 293 | call assert_equal(wh1, winheight(1)) |
| 294 | call assert_equal(wh2, winheight(2)) |
| 295 | |
| 296 | 2wincmd _ |
| 297 | set winfixheight |
| 298 | split Xc |
| 299 | let [wh1, wh2, wh3] = [winheight(1), winheight(2), winheight(3)] |
| 300 | call assert_equal(2, winheight(2)) |
| 301 | call assert_inrange(wh3, wh3 + 1, wh1) |
| 302 | 3wincmd + |
| 303 | call assert_equal(2, winheight(2)) |
| 304 | call assert_equal(wh1 + 3, winheight(1)) |
| 305 | call assert_equal(wh3 - 3, winheight(3)) |
| 306 | wincmd = |
| 307 | call assert_equal(2, winheight(2)) |
| 308 | call assert_equal(wh1, winheight(1)) |
| 309 | call assert_equal(wh3, winheight(3)) |
| 310 | |
| 311 | wincmd j |
| 312 | set winfixheight& |
| 313 | |
| 314 | wincmd = |
| 315 | let [wh1, wh2, wh3] = [winheight(1), winheight(2), winheight(3)] |
| 316 | " Current window (2) should have the same height or 1 more |
| 317 | " than the other windows. |
| 318 | call assert_inrange(wh1, wh1 + 1, wh2) |
| 319 | call assert_inrange(wh3, wh3 + 1, wh2) |
| 320 | |
| 321 | bw Xa Xb Xc |
| 322 | endfunc |
| 323 | |
| 324 | func Test_window_width() |
| 325 | e Xa |
| 326 | vsplit Xb |
| 327 | |
| 328 | let [ww1, ww2] = [winwidth(1), winwidth(2)] |
| 329 | " Active window (1) should have the same width or 1 more |
| 330 | " than the other window. |
| 331 | call assert_inrange(ww2, ww2 + 1, ww1) |
| 332 | |
| 333 | wincmd < |
| 334 | call assert_equal(ww1 - 1, winwidth(1)) |
| 335 | call assert_equal(ww2 + 1, winwidth(2)) |
| 336 | |
| 337 | wincmd > |
| 338 | call assert_equal(ww1, winwidth(1)) |
| 339 | call assert_equal(ww2, winwidth(2)) |
| 340 | |
| 341 | 2wincmd | |
| 342 | call assert_equal(2, winwidth(1)) |
| 343 | call assert_equal(ww1 + ww2 - 2, winwidth(2)) |
| 344 | |
| 345 | wincmd = |
| 346 | call assert_equal(ww1, winwidth(1)) |
| 347 | call assert_equal(ww2, winwidth(2)) |
| 348 | |
| 349 | 2wincmd | |
| 350 | set winfixwidth |
| 351 | vsplit Xc |
| 352 | let [ww1, ww2, ww3] = [winwidth(1), winwidth(2), winwidth(3)] |
Bram Moolenaar | 38e3483 | 2017-03-19 20:22:36 +0100 | [diff] [blame] | 353 | call assert_equal(2, winwidth(2)) |
Bram Moolenaar | 4520d44 | 2017-03-19 16:09:46 +0100 | [diff] [blame] | 354 | call assert_inrange(ww3, ww3 + 1, ww1) |
| 355 | 3wincmd > |
Bram Moolenaar | 38e3483 | 2017-03-19 20:22:36 +0100 | [diff] [blame] | 356 | call assert_equal(2, winwidth(2)) |
Bram Moolenaar | 4520d44 | 2017-03-19 16:09:46 +0100 | [diff] [blame] | 357 | call assert_equal(ww1 + 3, winwidth(1)) |
| 358 | call assert_equal(ww3 - 3, winwidth(3)) |
| 359 | wincmd = |
Bram Moolenaar | 38e3483 | 2017-03-19 20:22:36 +0100 | [diff] [blame] | 360 | call assert_equal(2, winwidth(2)) |
Bram Moolenaar | 4520d44 | 2017-03-19 16:09:46 +0100 | [diff] [blame] | 361 | call assert_equal(ww1, winwidth(1)) |
| 362 | call assert_equal(ww3, winwidth(3)) |
| 363 | |
| 364 | wincmd l |
| 365 | set winfixwidth& |
| 366 | |
| 367 | wincmd = |
| 368 | let [ww1, ww2, ww3] = [winwidth(1), winwidth(2), winwidth(3)] |
| 369 | " Current window (2) should have the same width or 1 more |
| 370 | " than the other windows. |
| 371 | call assert_inrange(ww1, ww1 + 1, ww2) |
| 372 | call assert_inrange(ww3, ww3 + 1, ww2) |
| 373 | |
| 374 | bw Xa Xb Xc |
| 375 | endfunc |
| 376 | |
Bram Moolenaar | 8eeeba8 | 2017-06-25 22:45:39 +0200 | [diff] [blame] | 377 | func Test_equalalways_on_close() |
| 378 | set equalalways |
| 379 | vsplit |
| 380 | windo split |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 381 | split |
Bram Moolenaar | 8eeeba8 | 2017-06-25 22:45:39 +0200 | [diff] [blame] | 382 | wincmd J |
| 383 | " now we have a frame top-left with two windows, a frame top-right with two |
| 384 | " windows and a frame at the bottom, full-width. |
| 385 | let height_1 = winheight(1) |
| 386 | let height_2 = winheight(2) |
| 387 | let height_3 = winheight(3) |
| 388 | let height_4 = winheight(4) |
| 389 | " closing the bottom window causes all windows to be resized. |
| 390 | close |
| 391 | call assert_notequal(height_1, winheight(1)) |
| 392 | call assert_notequal(height_2, winheight(2)) |
| 393 | call assert_notequal(height_3, winheight(3)) |
| 394 | call assert_notequal(height_4, winheight(4)) |
| 395 | call assert_equal(winheight(1), winheight(3)) |
| 396 | call assert_equal(winheight(2), winheight(4)) |
| 397 | |
| 398 | 1wincmd w |
| 399 | split |
| 400 | 4wincmd w |
| 401 | resize + 5 |
| 402 | " left column has three windows, equalized heights. |
| 403 | " right column has two windows, top one a bit higher |
| 404 | let height_1 = winheight(1) |
| 405 | let height_2 = winheight(2) |
| 406 | let height_4 = winheight(4) |
| 407 | let height_5 = winheight(5) |
| 408 | 3wincmd w |
| 409 | " closing window in left column equalizes heights in left column but not in |
| 410 | " the right column |
| 411 | close |
| 412 | call assert_notequal(height_1, winheight(1)) |
| 413 | call assert_notequal(height_2, winheight(2)) |
| 414 | call assert_equal(height_4, winheight(3)) |
| 415 | call assert_equal(height_5, winheight(4)) |
| 416 | |
| 417 | only |
| 418 | set equalalways& |
| 419 | endfunc |
| 420 | |
Bram Moolenaar | 22044dc | 2017-12-02 15:43:37 +0100 | [diff] [blame] | 421 | func Test_win_screenpos() |
| 422 | call assert_equal(1, winnr('$')) |
| 423 | split |
| 424 | vsplit |
| 425 | 10wincmd _ |
| 426 | 30wincmd | |
| 427 | call assert_equal([1, 1], win_screenpos(1)) |
| 428 | call assert_equal([1, 32], win_screenpos(2)) |
| 429 | call assert_equal([12, 1], win_screenpos(3)) |
| 430 | call assert_equal([0, 0], win_screenpos(4)) |
| 431 | only |
| 432 | endfunc |
| 433 | |
Bram Moolenaar | 4520d44 | 2017-03-19 16:09:46 +0100 | [diff] [blame] | 434 | func Test_window_jump_tag() |
| 435 | help |
| 436 | /iccf |
| 437 | call assert_match('^|iccf|', getline('.')) |
| 438 | call assert_equal(2, winnr('$')) |
| 439 | 2wincmd } |
| 440 | call assert_equal(3, winnr('$')) |
| 441 | call assert_match('^|iccf|', getline('.')) |
| 442 | wincmd k |
| 443 | call assert_match('\*iccf\*', getline('.')) |
| 444 | call assert_equal(2, winheight(0)) |
| 445 | |
| 446 | wincmd z |
| 447 | set previewheight=4 |
| 448 | help |
| 449 | /bugs |
| 450 | wincmd } |
| 451 | wincmd k |
| 452 | call assert_match('\*bugs\*', getline('.')) |
| 453 | call assert_equal(4, winheight(0)) |
| 454 | set previewheight& |
| 455 | |
| 456 | %bw! |
| 457 | endfunc |
| 458 | |
| 459 | func Test_window_newtab() |
| 460 | e Xa |
| 461 | |
| 462 | call assert_equal(1, tabpagenr('$')) |
| 463 | call assert_equal("\nAlready only one window", execute('wincmd T')) |
| 464 | |
| 465 | split Xb |
| 466 | split Xc |
| 467 | |
| 468 | wincmd T |
| 469 | call assert_equal(2, tabpagenr('$')) |
| 470 | call assert_equal(['Xb', 'Xa'], map(tabpagebuflist(1), 'bufname(v:val)')) |
| 471 | call assert_equal(['Xc' ], map(tabpagebuflist(2), 'bufname(v:val)')) |
| 472 | |
| 473 | %bw! |
| 474 | endfunc |
| 475 | |
Bram Moolenaar | f79225e | 2017-03-18 23:11:04 +0100 | [diff] [blame] | 476 | func Test_next_split_all() |
| 477 | " This was causing an illegal memory access. |
| 478 | n x |
| 479 | norm axxx |
| 480 | split |
| 481 | split |
| 482 | s/x |
| 483 | s/x |
| 484 | all |
| 485 | bwipe! |
| 486 | endfunc |
| 487 | |
Bram Moolenaar | 75373f3 | 2017-08-07 22:02:30 +0200 | [diff] [blame] | 488 | " Tests for adjusting window and contents |
| 489 | func GetScreenStr(row) |
| 490 | let str = "" |
| 491 | for c in range(1,3) |
| 492 | let str .= nr2char(screenchar(a:row, c)) |
| 493 | endfor |
| 494 | return str |
| 495 | endfunc |
| 496 | |
| 497 | func Test_window_contents() |
| 498 | enew! | only | new |
| 499 | call setline(1, range(1,256)) |
| 500 | |
| 501 | exe "norm! \<C-W>t\<C-W>=1Gzt\<C-W>w\<C-W>+" |
| 502 | redraw |
Bram Moolenaar | 72cf47a | 2018-05-10 18:23:29 +0200 | [diff] [blame] | 503 | let s3 = GetScreenStr(1) |
Bram Moolenaar | 75373f3 | 2017-08-07 22:02:30 +0200 | [diff] [blame] | 504 | wincmd p |
| 505 | call assert_equal(1, line("w0")) |
| 506 | call assert_equal('1 ', s3) |
| 507 | |
| 508 | exe "norm! \<C-W>t\<C-W>=50Gzt\<C-W>w\<C-W>+" |
| 509 | redraw |
Bram Moolenaar | 72cf47a | 2018-05-10 18:23:29 +0200 | [diff] [blame] | 510 | let s3 = GetScreenStr(1) |
Bram Moolenaar | 75373f3 | 2017-08-07 22:02:30 +0200 | [diff] [blame] | 511 | wincmd p |
| 512 | call assert_equal(50, line("w0")) |
| 513 | call assert_equal('50 ', s3) |
| 514 | |
| 515 | exe "norm! \<C-W>t\<C-W>=59Gzt\<C-W>w\<C-W>+" |
| 516 | redraw |
Bram Moolenaar | 72cf47a | 2018-05-10 18:23:29 +0200 | [diff] [blame] | 517 | let s3 = GetScreenStr(1) |
Bram Moolenaar | 75373f3 | 2017-08-07 22:02:30 +0200 | [diff] [blame] | 518 | wincmd p |
| 519 | call assert_equal(59, line("w0")) |
| 520 | call assert_equal('59 ', s3) |
| 521 | |
| 522 | bwipeout! |
| 523 | call test_garbagecollect_now() |
| 524 | endfunc |
| 525 | |
Bram Moolenaar | 2efb323 | 2017-12-19 12:27:23 +0100 | [diff] [blame] | 526 | func Test_window_colon_command() |
| 527 | " This was reading invalid memory. |
| 528 | exe "norm! v\<C-W>:\<C-U>echo v:version" |
| 529 | endfunc |
| 530 | |
Bram Moolenaar | 6f361c9 | 2018-01-31 19:06:50 +0100 | [diff] [blame] | 531 | func Test_access_freed_mem() |
| 532 | " This was accessing freed memory |
| 533 | au * 0 vs xxx |
| 534 | arg 0 |
| 535 | argadd |
| 536 | all |
| 537 | all |
| 538 | au! |
| 539 | bwipe xxx |
| 540 | endfunc |
| 541 | |
Bram Moolenaar | 5bab555 | 2018-04-13 20:41:29 +0200 | [diff] [blame] | 542 | func Test_visual_cleared_after_window_split() |
| 543 | new | only! |
| 544 | let smd_save = &showmode |
| 545 | set showmode |
| 546 | let ls_save = &laststatus |
| 547 | set laststatus=1 |
| 548 | call setline(1, ['a', 'b', 'c', 'd', '']) |
| 549 | norm! G |
| 550 | exe "norm! kkvk" |
| 551 | redraw |
| 552 | exe "norm! \<C-W>v" |
| 553 | redraw |
| 554 | " check if '-- VISUAL --' disappeared from command line |
| 555 | let columns = range(1, &columns) |
| 556 | let cmdlinechars = map(columns, 'nr2char(screenchar(&lines, v:val))') |
| 557 | let cmdline = join(cmdlinechars, '') |
| 558 | let cmdline_ltrim = substitute(cmdline, '^\s*', "", "") |
| 559 | let mode_shown = substitute(cmdline_ltrim, '\s*$', "", "") |
| 560 | call assert_equal('', mode_shown) |
| 561 | let &showmode = smd_save |
| 562 | let &laststatus = ls_save |
| 563 | bwipe! |
| 564 | endfunc |
| 565 | |
Bram Moolenaar | 72cf47a | 2018-05-10 18:23:29 +0200 | [diff] [blame] | 566 | func Test_winrestcmd() |
| 567 | 2split |
| 568 | 3vsplit |
| 569 | let a = winrestcmd() |
| 570 | call assert_equal(2, winheight(0)) |
| 571 | call assert_equal(3, winwidth(0)) |
| 572 | wincmd = |
| 573 | call assert_notequal(2, winheight(0)) |
| 574 | call assert_notequal(3, winwidth(0)) |
| 575 | exe a |
| 576 | call assert_equal(2, winheight(0)) |
| 577 | call assert_equal(3, winwidth(0)) |
| 578 | only |
| 579 | endfunc |
| 580 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame^] | 581 | func Fun_RenewFile() |
Bram Moolenaar | a42df59 | 2018-12-24 00:22:39 +0100 | [diff] [blame] | 582 | sleep 2 |
| 583 | silent execute '!echo "1" > tmp.txt' |
| 584 | sp |
| 585 | wincmd p |
| 586 | edit! tmp.txt |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame^] | 587 | endfunc |
Bram Moolenaar | a42df59 | 2018-12-24 00:22:39 +0100 | [diff] [blame] | 588 | |
| 589 | func Test_window_prevwin() |
| 590 | " Can we make this work on MS-Windows? |
| 591 | if !has('unix') |
| 592 | return |
| 593 | endif |
| 594 | |
| 595 | set hidden autoread |
| 596 | call writefile(['2'], 'tmp.txt') |
| 597 | new tmp.txt |
| 598 | q |
| 599 | " Need to wait a bit for the timestamp to be older. |
| 600 | call Fun_RenewFile() |
| 601 | call assert_equal(2, winnr()) |
| 602 | wincmd p |
| 603 | call assert_equal(1, winnr()) |
| 604 | wincmd p |
| 605 | q |
| 606 | call Fun_RenewFile() |
| 607 | call assert_equal(2, winnr()) |
| 608 | wincmd p |
| 609 | call assert_equal(1, winnr()) |
| 610 | wincmd p |
| 611 | " reset |
| 612 | q |
| 613 | call delete('tmp.txt') |
| 614 | set hidden&vim autoread&vim |
| 615 | delfunc Fun_RenewFile |
| 616 | endfunc |
| 617 | |
Bram Moolenaar | 9e4d821 | 2016-08-18 23:04:48 +0200 | [diff] [blame] | 618 | " vim: shiftwidth=2 sts=2 expandtab |