1" Test for commands that close windows and/or buffers: 2" :quit 3" :close 4" :hide 5" :only 6" :sall 7" :all 8" :ball 9" :buf 10" :edit 11" 12func Test_winbuf_close() 13 enew | only 14 15 call writefile(['testtext 1'], 'Xtest1') 16 call writefile(['testtext 2'], 'Xtest2') 17 call writefile(['testtext 3'], 'Xtest3') 18 19 next! Xtest1 Xtest2 20 call setline(1, 'testtext 1 1') 21 22 " test for working :n when hidden set 23 set hidden 24 next 25 call assert_equal('Xtest2', bufname('%')) 26 27 " test for failing :rew when hidden not set 28 set nohidden 29 call setline(1, 'testtext 2 2') 30 call assert_fails('rewind', 'E37:') 31 call assert_equal('Xtest2', bufname('%')) 32 call assert_equal('testtext 2 2', getline(1)) 33 34 " test for working :rew when hidden set 35 set hidden 36 rewind 37 call assert_equal('Xtest1', bufname('%')) 38 call assert_equal('testtext 1 1', getline(1)) 39 40 " test for :all keeping a buffer when it's modified 41 set nohidden 42 call setline(1, 'testtext 1 1 1') 43 split 44 next Xtest2 Xtest3 45 all 46 1wincmd w 47 call assert_equal('Xtest1', bufname('%')) 48 call assert_equal('testtext 1 1 1', getline(1)) 49 50 " test abandoning changed buffer, should be unloaded even when 'hidden' set 51 set hidden 52 call setline(1, 'testtext 1 1 1 1') 53 quit! 54 call assert_equal('Xtest2', bufname('%')) 55 call assert_equal('testtext 2 2', getline(1)) 56 unhide 57 call assert_equal('Xtest2', bufname('%')) 58 call assert_equal('testtext 2 2', getline(1)) 59 60 " test ":hide" hides anyway when 'hidden' not set 61 set nohidden 62 call setline(1, 'testtext 2 2 2') 63 hide 64 call assert_equal('Xtest3', bufname('%')) 65 call assert_equal('testtext 3', getline(1)) 66 67 " test ":edit" failing in modified buffer when 'hidden' not set 68 call setline(1, 'testtext 3 3') 69 call assert_fails('edit Xtest1', 'E37:') 70 call assert_equal('Xtest3', bufname('%')) 71 call assert_equal('testtext 3 3', getline(1)) 72 73 " test ":edit" working in modified buffer when 'hidden' set 74 set hidden 75 edit Xtest1 76 call assert_equal('Xtest1', bufname('%')) 77 call assert_equal('testtext 1', getline(1)) 78 79 " test ":close" not hiding when 'hidden' not set in modified buffer 80 split Xtest3 81 set nohidden 82 call setline(1, 'testtext 3 3 3') 83 call assert_fails('close', 'E37:') 84 call assert_equal('Xtest3', bufname('%')) 85 call assert_equal('testtext 3 3 3', getline(1)) 86 87 " test ":close!" does hide when 'hidden' not set in modified buffer; 88 call setline(1, 'testtext 3 3 3 3') 89 close! 90 call assert_equal('Xtest1', bufname('%')) 91 call assert_equal('testtext 1', getline(1)) 92 93 set nohidden 94 95 " test ":all!" hides changed buffer 96 split Xtest4 97 call setline(1, 'testtext 4') 98 all! 99 1wincmd w 100 call assert_equal('Xtest2', bufname('%')) 101 call assert_equal('testtext 2 2 2', getline(1)) 102 103 " test ":q!" and hidden buffer. 104 bwipe! Xtest1 Xtest2 Xtest3 Xtest4 105 split Xtest1 106 wincmd w 107 bwipe! 108 set modified 109 bot split Xtest2 110 set modified 111 bot split Xtest3 112 set modified 113 wincmd t 114 hide 115 call assert_equal('Xtest2', bufname('%')) 116 quit! 117 call assert_equal('Xtest3', bufname('%')) 118 call assert_fails('silent! quit!', 'E37:') 119 call assert_equal('Xtest1', bufname('%')) 120 121 call delete('Xtest1') 122 call delete('Xtest2') 123 call delete('Xtest3') 124endfunc 125 126" Test that ":close" will respect 'winfixheight' when possible. 127func Test_winfixheight_on_close() 128 set nosplitbelow nosplitright 129 130 split | split | vsplit 131 132 $wincmd w 133 setlocal winfixheight 134 let l:height = winheight(0) 135 136 3close 137 138 call assert_equal(l:height, winheight(0)) 139 140 %bwipeout! 141 setlocal nowinfixheight splitbelow& splitright& 142endfunc 143 144" Test that ":close" will respect 'winfixwidth' when possible. 145func Test_winfixwidth_on_close() 146 set nosplitbelow nosplitright 147 148 vsplit | vsplit | split 149 150 $wincmd w 151 setlocal winfixwidth 152 let l:width = winwidth(0) 153 154 3close 155 156 call assert_equal(l:width, winwidth(0)) 157 158 %bwipeout! 159 setlocal nowinfixwidth splitbelow& splitright& 160endfunction 161 162" Test that 'winfixheight' will be respected even there is non-leaf frame 163func Test_winfixheight_non_leaf_frame() 164 vsplit 165 botright 11new 166 let l:wid = win_getid() 167 setlocal winfixheight 168 call assert_equal(11, winheight(l:wid)) 169 botright new 170 bwipe! 171 call assert_equal(11, winheight(l:wid)) 172 %bwipe! 173endf 174 175" Test that 'winfixwidth' will be respected even there is non-leaf frame 176func Test_winfixwidth_non_leaf_frame() 177 split 178 topleft 11vnew 179 let l:wid = win_getid() 180 setlocal winfixwidth 181 call assert_equal(11, winwidth(l:wid)) 182 topleft new 183 bwipe! 184 call assert_equal(11, winwidth(l:wid)) 185 %bwipe! 186endf 187 188func Test_tabwin_close() 189 enew 190 let l:wid = win_getid() 191 tabedit 192 call win_execute(l:wid, 'close') 193 " Should not crash. 194 call assert_true(v:true) 195 196 " This tests closing a window in another tab, while leaving the tab open 197 " i.e. two windows in another tab. 198 tabedit 199 let w:this_win = 42 200 new 201 let othertab_wid = win_getid() 202 tabprevious 203 call win_execute(othertab_wid, 'q') 204 " drawing the tabline helps check that the other tab's windows and buffers 205 " are still valid 206 redrawtabline 207 " but to be certain, ensure we can focus the other tab too 208 tabnext 209 call assert_equal(42, w:this_win) 210 211 bwipe! 212endfunc 213 214" Test when closing a split window (above/below) restores space to the window 215" below when 'noequalalways' and 'splitright' are set. 216func Test_window_close_splitright_noequalalways() 217 set noequalalways 218 set splitright 219 new 220 let w1 = win_getid() 221 new 222 let w2 = win_getid() 223 execute "normal \<c-w>b" 224 let h = winheight(0) 225 let w = win_getid() 226 new 227 q 228 call assert_equal(h, winheight(0), "Window height does not match eight before opening and closing another window") 229 call assert_equal(w, win_getid(), "Did not return to original window after opening and closing a window") 230endfunc 231 232" vim: shiftwidth=2 sts=2 expandtab 233