@@ -77,11 +77,49 @@ function Test_autocmd_bufunload_with_tabnext()
7777 quit
7878 call assert_equal (2 , tabpagenr (' $' ))
7979
80+ autocmd ! test_autocmd_bufunload_with_tabnext_group
8081 augroup ! test_autocmd_bufunload_with_tabnext_group
8182 tablast
8283 quit
8384endfunc
8485
86+ " SEGV occurs in older versions. (At least 7.4.2321 or older)
87+ function Test_autocmd_bufunload_avoiding_SEGV_01 ()
88+ split aa.txt
89+ let lastbuf = bufnr (' $' )
90+
91+ augroup test_autocmd_bufunload
92+ autocmd !
93+ exe ' autocmd BufUnload <buffer> ' . (lastbuf + 1 ) . ' bwipeout!'
94+ augroup END
95+
96+ call assert_fails (' edit bb.txt' , ' E937:' )
97+
98+ autocmd ! test_autocmd_bufunload
99+ augroup ! test_autocmd_bufunload
100+ bwipe! aa.txt
101+ bwipe! bb.txt
102+ endfunc
103+
104+ " SEGV occurs in older versions. (At least 7.4.2321 or older)
105+ function Test_autocmd_bufunload_avoiding_SEGV_02 ()
106+ setlocal buftype = nowrite
107+ let lastbuf = bufnr (' $' )
108+
109+ augroup test_autocmd_bufunload
110+ autocmd !
111+ exe ' autocmd BufUnload <buffer> ' . (lastbuf + 1 ) . ' bwipeout!'
112+ augroup END
113+
114+ normal ! i1
115+ call assert_fails (' edit a.txt' , ' E517:' )
116+ call feedkeys (" \<CR> " )
117+
118+ autocmd ! test_autocmd_bufunload
119+ augroup ! test_autocmd_bufunload
120+ bwipe! a .txt
121+ endfunc
122+
85123func Test_win_tab_autocmd ()
86124 let g: record = []
87125
@@ -196,3 +234,63 @@ func Test_augroup_deleted()
196234 au ! VimEnter
197235endfunc
198236
237+ " Tests for autocommands on :close command.
238+ " This used to be in test13.
239+ func Test_three_windows ()
240+ " Write three files and open them, each in a window.
241+ " Then go to next window, with autocommand that deletes the previous one.
242+ " Do this twice, writing the file.
243+ e ! Xtestje1
244+ call setline (1 , ' testje1' )
245+ w
246+ sp Xtestje2
247+ call setline (1 , ' testje2' )
248+ w
249+ sp Xtestje3
250+ call setline (1 , ' testje3' )
251+ w
252+ wincmd w
253+ au WinLeave Xtestje2 bwipe
254+ wincmd w
255+ call assert_equal (' Xtestje1' , expand (' %' ))
256+
257+ au WinLeave Xtestje1 bwipe Xtestje3
258+ close
259+ call assert_equal (' Xtestje1' , expand (' %' ))
260+
261+ " Test deleting the buffer on a Unload event. If this goes wrong there
262+ " will be the ATTENTION prompt.
263+ e Xtestje1
264+ au !
265+ au ! BufUnload Xtestje1 bwipe
266+ call assert_fails (' e Xtestje3' , ' E937:' )
267+ call assert_equal (' Xtestje3' , expand (' %' ))
268+
269+ e Xtestje2
270+ sp Xtestje1
271+ call assert_fails (' e' , ' E937:' )
272+ call assert_equal (' Xtestje2' , expand (' %' ))
273+
274+ " Test changing buffers in a BufWipeout autocommand. If this goes wrong
275+ " there are ml_line errors and/or a Crash.
276+ au !
277+ only
278+ e Xanother
279+ e Xtestje1
280+ bwipe Xtestje2
281+ bwipe Xtestje3
282+ au BufWipeout Xtestje1 buf Xtestje1
283+ bwipe
284+ call assert_equal (' Xanother' , expand (' %' ))
285+
286+ only
287+ help
288+ wincmd w
289+ 1 quit
290+ call assert_equal (' Xanother' , expand (' %' ))
291+
292+ au !
293+ call delete (' Xtestje1' )
294+ call delete (' Xtestje2' )
295+ call delete (' Xtestje3' )
296+ endfunc
0 commit comments