patch 8.2.1061: insufficient testing for src/window.c

Problem:    Insufficient testing for src/window.c.
Solution:   Add more tests. (Yegappan Lakshmanan, closes #6345)
diff --git a/src/testdir/test_window_cmd.vim b/src/testdir/test_window_cmd.vim
index e20bfa5..aa619cd 100644
--- a/src/testdir/test_window_cmd.vim
+++ b/src/testdir/test_window_cmd.vim
@@ -36,7 +36,16 @@
   set ls&vim
 endfunc
 
-function Test_window_cmd_wincmd_gf()
+" Test for jumping to windows
+func Test_window_jump()
+  new
+  " jumping to a window with a count greater than the max windows
+  exe "normal 4\<C-W>w"
+  call assert_equal(2, winnr())
+  only
+endfunc
+
+func Test_window_cmd_wincmd_gf()
   let fname = 'test_gf.txt'
   let swp_fname = '.' . fname . '.swp'
   call writefile([], fname)
@@ -1099,4 +1108,179 @@
   call assert_beeps("normal \<C-W>2gt")
 endfunc
 
+" Test for adjusting the window width when a window is closed with some
+" windows using 'winfixwidth'
+func Test_window_width_adjust()
+  only
+  " Three vertical windows. Windows 1 and 2 have 'winfixwidth' set and close
+  " window 2.
+  wincmd v
+  vert resize 10
+  set winfixwidth
+  wincmd v
+  set winfixwidth
+  wincmd c
+  call assert_inrange(10, 12, winwidth(1))
+  " Three vertical windows. Windows 2 and 3 have 'winfixwidth' set and close
+  " window 3.
+  only
+  set winfixwidth
+  wincmd v
+  vert resize 10
+  set winfixwidth
+  wincmd v
+  set nowinfixwidth
+  wincmd b
+  wincmd c
+  call assert_inrange(10, 12, winwidth(2))
+
+  new | only
+endfunc
+
+" Test for jumping to a vertical/horizontal neighbor window based on the
+" current cursor position
+func Test_window_goto_neightbor()
+  %bw!
+
+  " Vertical window movement
+
+  " create the following window layout:
+  "     +--+--+
+  "     |w1|w3|
+  "     +--+  |
+  "     |w2|  |
+  "     +--+--+
+  "     |w4   |
+  "     +-----+
+  new
+  vsplit
+  split
+  " vertically jump from w4
+  wincmd b
+  call setline(1, repeat(' ', &columns))
+  call cursor(1, 1)
+  wincmd k
+  call assert_equal(2, winnr())
+  wincmd b
+  call cursor(1, &columns)
+  redraw!
+  wincmd k
+  call assert_equal(3, winnr())
+  %bw!
+
+  " create the following window layout:
+  "     +--+--+--+
+  "     |w1|w2|w3|
+  "     +--+--+--+
+  "     |w4      |
+  "     +--------+
+  new
+  vsplit
+  vsplit
+  wincmd b
+  call setline(1, repeat(' ', &columns))
+  call cursor(1, 1)
+  wincmd k
+  call assert_equal(1, winnr())
+  wincmd b
+  call cursor(1, &columns / 2)
+  redraw!
+  wincmd k
+  call assert_equal(2, winnr())
+  wincmd b
+  call cursor(1, &columns)
+  redraw!
+  wincmd k
+  call assert_equal(3, winnr())
+  %bw!
+
+  " Horizontal window movement
+
+  " create the following window layout:
+  "     +--+--+--+
+  "     |w1|w2|w4|
+  "     +--+--+  |
+  "     |w3   |  |
+  "     +-----+--+
+  vsplit
+  split
+  vsplit
+  4wincmd l
+  call setline(1, repeat([' '], &lines))
+  call cursor(1, 1)
+  redraw!
+  wincmd h
+  call assert_equal(2, winnr())
+  4wincmd l
+  call cursor(&lines, 1)
+  redraw!
+  wincmd h
+  call assert_equal(3, winnr())
+  %bw!
+
+  " create the following window layout:
+  "     +--+--+
+  "     |w1|w4|
+  "     +--+  +
+  "     |w2|  |
+  "     +--+  +
+  "     |w3|  |
+  "     +--+--+
+  vsplit
+  split
+  split
+  wincmd l
+  call setline(1, repeat([' '], &lines))
+  call cursor(1, 1)
+  redraw!
+  wincmd h
+  call assert_equal(1, winnr())
+  wincmd l
+  call cursor(&lines / 2, 1)
+  redraw!
+  wincmd h
+  call assert_equal(2, winnr())
+  wincmd l
+  call cursor(&lines, 1)
+  redraw!
+  wincmd h
+  call assert_equal(3, winnr())
+  %bw!
+endfunc
+
+" Test for an autocmd closing the destination window when jumping from one
+" window to another.
+func Test_close_dest_window()
+  split
+  edit Xfile
+
+  " Test for BufLeave
+  augroup T1
+    au!
+    au BufLeave Xfile $wincmd c
+  augroup END
+  wincmd b
+  call assert_equal(1, winnr('$'))
+  call assert_equal('Xfile', @%)
+  augroup T1
+    au!
+  augroup END
+
+  " Test for WinLeave
+  new
+  wincmd p
+  augroup T1
+    au!
+    au WinLeave * 1wincmd c
+  augroup END
+  wincmd t
+  call assert_equal(1, winnr('$'))
+  call assert_equal('Xfile', @%)
+  augroup T1
+    au!
+  augroup END
+  augroup! T1
+  %bw!
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab