blob: 489926dfbd2fe0a9b14ed40f7f2b95f491f65790 [file] [log] [blame]
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01001" Tests for Vim buffer
2
Bram Moolenaarb7e24832020-06-24 13:37:35 +02003source check.vim
4
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01005" Test for the :bunload command with an offset
6func Test_bunload_with_offset()
7 %bwipe!
Bram Moolenaar34112652022-09-05 21:40:44 +01008 call writefile(['B1'], 'Xb1', 'D')
9 call writefile(['B2'], 'Xb2', 'D')
10 call writefile(['B3'], 'Xb3', 'D')
11 call writefile(['B4'], 'Xb4', 'D')
Bram Moolenaar9f6277b2020-02-11 22:04:02 +010012
13 " Load four buffers. Unload the second and third buffers and then
14 " execute .+3bunload to unload the last buffer.
Bram Moolenaar34112652022-09-05 21:40:44 +010015 edit Xb1
16 new Xb2
17 new Xb3
18 new Xb4
Bram Moolenaar9f6277b2020-02-11 22:04:02 +010019
Bram Moolenaar34112652022-09-05 21:40:44 +010020 bunload Xb2
21 bunload Xb3
22 exe bufwinnr('Xb1') . 'wincmd w'
Bram Moolenaar9f6277b2020-02-11 22:04:02 +010023 .+3bunload
Bram Moolenaar34112652022-09-05 21:40:44 +010024 call assert_equal(0, getbufinfo('Xb4')[0].loaded)
25 call assert_equal('Xb1',
Bram Moolenaar9f6277b2020-02-11 22:04:02 +010026 \ fnamemodify(getbufinfo({'bufloaded' : 1})[0].name, ':t'))
27
28 " Load four buffers. Unload the third and fourth buffers. Execute .+3bunload
29 " and check whether the second buffer is unloaded.
30 ball
Bram Moolenaar34112652022-09-05 21:40:44 +010031 bunload Xb3
32 bunload Xb4
33 exe bufwinnr('Xb1') . 'wincmd w'
Bram Moolenaar9f6277b2020-02-11 22:04:02 +010034 .+3bunload
Bram Moolenaar34112652022-09-05 21:40:44 +010035 call assert_equal(0, getbufinfo('Xb2')[0].loaded)
36 call assert_equal('Xb1',
Bram Moolenaar9f6277b2020-02-11 22:04:02 +010037 \ fnamemodify(getbufinfo({'bufloaded' : 1})[0].name, ':t'))
38
39 " Load four buffers. Unload the second and third buffers and from the last
40 " buffer execute .-3bunload to unload the first buffer.
41 ball
Bram Moolenaar34112652022-09-05 21:40:44 +010042 bunload Xb2
43 bunload Xb3
44 exe bufwinnr('Xb4') . 'wincmd w'
Bram Moolenaar9f6277b2020-02-11 22:04:02 +010045 .-3bunload
Bram Moolenaar34112652022-09-05 21:40:44 +010046 call assert_equal(0, getbufinfo('Xb1')[0].loaded)
47 call assert_equal('Xb4',
Bram Moolenaar9f6277b2020-02-11 22:04:02 +010048 \ fnamemodify(getbufinfo({'bufloaded' : 1})[0].name, ':t'))
49
50 " Load four buffers. Unload the first and second buffers. Execute .-3bunload
51 " from the last buffer and check whether the third buffer is unloaded.
52 ball
Bram Moolenaar34112652022-09-05 21:40:44 +010053 bunload Xb1
54 bunload Xb2
55 exe bufwinnr('Xb4') . 'wincmd w'
Bram Moolenaar9f6277b2020-02-11 22:04:02 +010056 .-3bunload
Bram Moolenaar34112652022-09-05 21:40:44 +010057 call assert_equal(0, getbufinfo('Xb3')[0].loaded)
58 call assert_equal('Xb4',
Bram Moolenaar9f6277b2020-02-11 22:04:02 +010059 \ fnamemodify(getbufinfo({'bufloaded' : 1})[0].name, ':t'))
60
61 %bwipe!
Bram Moolenaarf0cee192020-02-16 13:33:56 +010062
63 call assert_fails('1,4bunload', 'E16:')
64 call assert_fails(',100bunload', 'E16:')
65
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +020066 call assert_fails('$bunload', 'E90:')
Bram Moolenaarf0cee192020-02-16 13:33:56 +010067endfunc
68
69" Test for :buffer, :bnext, :bprevious, :brewind, :blast and :bmodified
70" commands
71func Test_buflist_browse()
72 %bwipe!
73 call assert_fails('buffer 1000', 'E86:')
74
Bram Moolenaar34112652022-09-05 21:40:44 +010075 call writefile(['foo1', 'foo2', 'foo3', 'foo4'], 'Xbrowse1', 'D')
76 call writefile(['bar1', 'bar2', 'bar3', 'bar4'], 'Xbrowse2', 'D')
77 call writefile(['baz1', 'baz2', 'baz3', 'baz4'], 'Xbrowse3', 'D')
Bram Moolenaare7cda972022-08-29 11:02:59 +010078 edit Xbrowse1
Bram Moolenaarf0cee192020-02-16 13:33:56 +010079 let b1 = bufnr()
Bram Moolenaare7cda972022-08-29 11:02:59 +010080 edit Xbrowse2
Bram Moolenaarf0cee192020-02-16 13:33:56 +010081 let b2 = bufnr()
Bram Moolenaare7cda972022-08-29 11:02:59 +010082 edit +/baz4 Xbrowse3
Bram Moolenaarf0cee192020-02-16 13:33:56 +010083 let b3 = bufnr()
84
85 call assert_fails('buffer ' .. b1 .. ' abc', 'E488:')
86 call assert_equal(b3, bufnr())
87 call assert_equal(4, line('.'))
88 exe 'buffer +/bar2 ' .. b2
89 call assert_equal(b2, bufnr())
90 call assert_equal(2, line('.'))
91 exe 'buffer +/bar1'
92 call assert_equal(b2, bufnr())
93 call assert_equal(1, line('.'))
94
Bram Moolenaarbc2b71d2020-02-17 21:33:30 +010095 brewind +
Bram Moolenaarf0cee192020-02-16 13:33:56 +010096 call assert_equal(b1, bufnr())
Bram Moolenaarbc2b71d2020-02-17 21:33:30 +010097 call assert_equal(4, line('.'))
Bram Moolenaarf0cee192020-02-16 13:33:56 +010098
99 blast +/baz2
100 call assert_equal(b3, bufnr())
101 call assert_equal(2, line('.'))
102
103 bprevious +/bar4
104 call assert_equal(b2, bufnr())
105 call assert_equal(4, line('.'))
106
107 bnext +/baz3
108 call assert_equal(b3, bufnr())
109 call assert_equal(3, line('.'))
110
111 call assert_fails('bmodified', 'E84:')
112 call setbufvar(b2, '&modified', 1)
113 exe 'bmodified +/bar3'
114 call assert_equal(b2, bufnr())
115 call assert_equal(3, line('.'))
116
117 " With no listed buffers in the list, :bnext and :bprev should fail
118 %bwipe!
119 set nobuflisted
120 call assert_fails('bnext', 'E85:')
121 call assert_fails('bprev', 'E85:')
122 set buflisted
123
124 call assert_fails('sandbox bnext', 'E48:')
125
Bram Moolenaarf0cee192020-02-16 13:33:56 +0100126 %bwipe!
127endfunc
128
129" Test for :bdelete
130func Test_bdelete_cmd()
131 %bwipe!
132 call assert_fails('bdelete 5', 'E516:')
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100133 call assert_fails('1,1bdelete 1 2', 'E488:')
Bram Moolenaar531be472020-09-23 22:38:05 +0200134 call assert_fails('bdelete \)', 'E55:')
Bram Moolenaarf0cee192020-02-16 13:33:56 +0100135
136 " Deleting a unlisted and unloaded buffer
Bram Moolenaar61abe7d2022-08-30 21:46:08 +0100137 edit Xbdelfile1
Bram Moolenaarf0cee192020-02-16 13:33:56 +0100138 let bnr = bufnr()
139 set nobuflisted
140 enew
141 call assert_fails('bdelete ' .. bnr, 'E516:')
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200142
143 " Deleting more than one buffer
144 new Xbuf1
145 new Xbuf2
146 exe 'bdel ' .. bufnr('Xbuf2') .. ' ' .. bufnr('Xbuf1')
147 call assert_equal(1, winnr('$'))
148 call assert_equal(0, getbufinfo('Xbuf1')[0].loaded)
149 call assert_equal(0, getbufinfo('Xbuf2')[0].loaded)
150
151 " Deleting more than one buffer and an invalid buffer
152 new Xbuf1
153 new Xbuf2
154 let cmd = "exe 'bdel ' .. bufnr('Xbuf2') .. ' xxx ' .. bufnr('Xbuf1')"
155 call assert_fails(cmd, 'E94:')
156 call assert_equal(2, winnr('$'))
157 call assert_equal(1, getbufinfo('Xbuf1')[0].loaded)
158 call assert_equal(0, getbufinfo('Xbuf2')[0].loaded)
159
Bram Moolenaarf0cee192020-02-16 13:33:56 +0100160 %bwipe!
Bram Moolenaar9f6277b2020-02-11 22:04:02 +0100161endfunc
162
Bram Moolenaar067297e2020-04-13 19:55:50 +0200163func Test_buffer_error()
164 new foo1
165 new foo2
166
167 call assert_fails('buffer foo', 'E93:')
168 call assert_fails('buffer bar', 'E94:')
169 call assert_fails('buffer 0', 'E939:')
170
171 %bwipe
172endfunc
173
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200174" Test for the status messages displayed when unloading, deleting or wiping
175" out buffers
176func Test_buffer_statusmsg()
177 CheckEnglish
178 set report=1
179 new Xbuf1
180 new Xbuf2
181 let bnr = bufnr()
182 exe "normal 2\<C-G>"
183 call assert_match('buf ' .. bnr .. ':', v:statusmsg)
184 bunload Xbuf1 Xbuf2
185 call assert_equal('2 buffers unloaded', v:statusmsg)
186 bdel Xbuf1 Xbuf2
187 call assert_equal('2 buffers deleted', v:statusmsg)
188 bwipe Xbuf1 Xbuf2
189 call assert_equal('2 buffers wiped out', v:statusmsg)
190 set report&
191endfunc
192
193" Test for quitting the 'swapfile exists' dialog with the split buffer
194" command.
195func Test_buffer_sbuf_cleanup()
Bram Moolenaar34112652022-09-05 21:40:44 +0100196 call writefile([], 'XsplitCleanup', 'D')
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200197 " first open the file in a buffer
Bram Moolenaare7cda972022-08-29 11:02:59 +0100198 new XsplitCleanup
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200199 let bnr = bufnr()
200 close
201 " create the swap file
Bram Moolenaar34112652022-09-05 21:40:44 +0100202 call writefile([], '.XsplitCleanup.swp', 'D')
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200203 " Remove the catch-all that runtest.vim adds
204 au! SwapExists
205 augroup BufTest
206 au!
Bram Moolenaare7cda972022-08-29 11:02:59 +0100207 autocmd SwapExists XsplitCleanup let v:swapchoice='q'
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200208 augroup END
209 exe 'sbuf ' . bnr
210 call assert_equal(1, winnr('$'))
Bram Moolenaare7cda972022-08-29 11:02:59 +0100211 call assert_equal(0, getbufinfo('XsplitCleanup')[0].loaded)
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200212
213 " test for :sball
214 sball
215 call assert_equal(1, winnr('$'))
Bram Moolenaare7cda972022-08-29 11:02:59 +0100216 call assert_equal(0, getbufinfo('XsplitCleanup')[0].loaded)
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200217
218 %bw!
219 set shortmess+=F
220 let v:statusmsg = ''
Bram Moolenaare7cda972022-08-29 11:02:59 +0100221 edit XsplitCleanup
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200222 call assert_equal('', v:statusmsg)
223 call assert_equal(1, winnr('$'))
Bram Moolenaare7cda972022-08-29 11:02:59 +0100224 call assert_equal(0, getbufinfo('XsplitCleanup')[0].loaded)
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200225 set shortmess&
226
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200227 augroup BufTest
228 au!
229 augroup END
230 augroup! BufTest
231endfunc
232
233" Test for deleting a modified buffer with :confirm
234func Test_bdel_with_confirm()
235 CheckUnix
236 CheckNotGui
237 CheckFeature dialog_con
238 new
239 call setline(1, 'test')
240 call assert_fails('bdel', 'E89:')
241 call feedkeys('c', 'L')
242 confirm bdel
243 call assert_equal(2, winnr('$'))
244 call assert_equal(1, &modified)
245 call feedkeys('n', 'L')
246 confirm bdel
247 call assert_equal(1, winnr('$'))
248endfunc
249
250" Test for editing another buffer from a modified buffer with :confirm
251func Test_goto_buf_with_confirm()
252 CheckUnix
253 CheckNotGui
254 CheckFeature dialog_con
Bram Moolenaare7cda972022-08-29 11:02:59 +0100255 new XgotoConf
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200256 enew
257 call setline(1, 'test')
Bram Moolenaare7cda972022-08-29 11:02:59 +0100258 call assert_fails('b XgotoConf', 'E37:')
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200259 call feedkeys('c', 'L')
Bram Moolenaare7cda972022-08-29 11:02:59 +0100260 call assert_fails('confirm b XgotoConf', 'E37:')
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200261 call assert_equal(1, &modified)
262 call assert_equal('', @%)
263 call feedkeys('y', 'L')
Bram Moolenaare7cda972022-08-29 11:02:59 +0100264 call assert_fails('confirm b XgotoConf', ['', 'E37:'])
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200265 call assert_equal(1, &modified)
266 call assert_equal('', @%)
267 call feedkeys('n', 'L')
Bram Moolenaare7cda972022-08-29 11:02:59 +0100268 confirm b XgotoConf
269 call assert_equal('XgotoConf', @%)
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200270 close!
271endfunc
272
273" Test for splitting buffer with 'switchbuf'
274func Test_buffer_switchbuf()
Bram Moolenaare7cda972022-08-29 11:02:59 +0100275 new Xswitchbuf
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200276 wincmd w
277 set switchbuf=useopen
Bram Moolenaare7cda972022-08-29 11:02:59 +0100278 sbuf Xswitchbuf
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200279 call assert_equal(1, winnr())
280 call assert_equal(2, winnr('$'))
281 set switchbuf=usetab
282 tabnew
Bram Moolenaare7cda972022-08-29 11:02:59 +0100283 sbuf Xswitchbuf
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200284 call assert_equal(1, tabpagenr())
285 call assert_equal(2, tabpagenr('$'))
286 set switchbuf&
287 %bw
288endfunc
289
290" Test for BufAdd autocommand wiping out the buffer
291func Test_bufadd_autocmd_bwipe()
292 %bw!
293 augroup BufAdd_Wipe
294 au!
Bram Moolenaare7cda972022-08-29 11:02:59 +0100295 autocmd BufAdd Xbwipe %bw!
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200296 augroup END
Bram Moolenaare7cda972022-08-29 11:02:59 +0100297 edit Xbwipe
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200298 call assert_equal('', @%)
Bram Moolenaare7cda972022-08-29 11:02:59 +0100299 call assert_equal(0, bufexists('Xbwipe'))
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200300 augroup BufAdd_Wipe
301 au!
302 augroup END
303 augroup! BufAdd_Wipe
304endfunc
305
306" Test for trying to load a buffer with text locked
307" <C-\>e in the command line is used to lock the text
308func Test_load_buf_with_text_locked()
Bram Moolenaar61abe7d2022-08-30 21:46:08 +0100309 new Xlockfile1
310 edit Xlockfile2
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200311 let cmd = ":\<C-\>eexecute(\"normal \<C-O>\")\<CR>\<C-C>"
312 call assert_fails("call feedkeys(cmd, 'xt')", 'E565:')
313 %bw!
314endfunc
315
316" Test for using CTRL-^ to edit the alternative file keeping the cursor
317" position with 'nostartofline'. Also test using the 'buf' command.
318func Test_buffer_edit_altfile()
Bram Moolenaar34112652022-09-05 21:40:44 +0100319 call writefile(repeat(['one two'], 50), 'Xaltfile1', 'D')
320 call writefile(repeat(['five six'], 50), 'Xaltfile2', 'D')
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200321 set nosol
Bram Moolenaare7cda972022-08-29 11:02:59 +0100322 edit Xaltfile1
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200323 call cursor(25, 5)
Bram Moolenaare7cda972022-08-29 11:02:59 +0100324 edit Xaltfile2
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200325 call cursor(30, 4)
326 exe "normal \<C-^>"
327 call assert_equal([0, 25, 5, 0], getpos('.'))
328 exe "normal \<C-^>"
329 call assert_equal([0, 30, 4, 0], getpos('.'))
Bram Moolenaare7cda972022-08-29 11:02:59 +0100330 buf Xaltfile1
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200331 call assert_equal([0, 25, 5, 0], getpos('.'))
Bram Moolenaare7cda972022-08-29 11:02:59 +0100332 buf Xaltfile2
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200333 call assert_equal([0, 30, 4, 0], getpos('.'))
334 set sol&
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200335endfunc
336
337" Test for running the :sball command with a maximum window count and a
338" modified buffer
339func Test_sball_with_count()
340 %bw!
Bram Moolenaare7cda972022-08-29 11:02:59 +0100341 edit Xcountfile1
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200342 call setline(1, ['abc'])
Bram Moolenaare7cda972022-08-29 11:02:59 +0100343 new Xcountfile2
344 new Xcountfile3
345 new Xcountfile4
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200346 2sball
Bram Moolenaare7cda972022-08-29 11:02:59 +0100347 call assert_equal(bufnr('Xcountfile4'), winbufnr(1))
348 call assert_equal(bufnr('Xcountfile1'), winbufnr(2))
349 call assert_equal(0, getbufinfo('Xcountfile2')[0].loaded)
350 call assert_equal(0, getbufinfo('Xcountfile3')[0].loaded)
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200351 %bw!
352endfunc
353
Bram Moolenaare974fa72020-10-25 15:02:51 +0100354func Test_badd_options()
355 new SomeNewBuffer
Bram Moolenaar37e4e032020-10-25 16:18:26 +0100356 setlocal numberwidth=3
Bram Moolenaare974fa72020-10-25 15:02:51 +0100357 wincmd p
Bram Moolenaar89b693e2020-10-25 17:09:50 +0100358 badd +1 SomeNewBuffer
Bram Moolenaare974fa72020-10-25 15:02:51 +0100359 new SomeNewBuffer
Bram Moolenaar37e4e032020-10-25 16:18:26 +0100360 call assert_equal(3, &numberwidth)
Bram Moolenaare974fa72020-10-25 15:02:51 +0100361 close
362 close
363 bwipe! SomeNewBuffer
364endfunc
365
Bram Moolenaar59d8e562020-11-07 18:41:10 +0100366func Test_balt()
367 new SomeNewBuffer
368 balt +3 OtherBuffer
369 e #
370 call assert_equal('OtherBuffer', bufname())
371endfunc
372
Tsuyoshi CHO7b7a1182021-07-11 21:51:17 +0200373" Test for buffer match URL(scheme) check
374" scheme is alpha and inner hyphen only.
375func Test_buffer_scheme()
376 CheckMSWindows
377
378 set noshellslash
379 %bwipe!
380 let bufnames = [
Bram Moolenaarf8bc0ce2021-12-02 12:30:22 +0000381 \ #{id: 'ssb0', name: 'test://xyz/foo/ssb0' , match: 1},
382 \ #{id: 'ssb1', name: 'test+abc://xyz/foo/ssb1', match: 0},
383 \ #{id: 'ssb2', name: 'test_abc://xyz/foo/ssb2', match: 0},
384 \ #{id: 'ssb3', name: 'test-abc://xyz/foo/ssb3', match: 1},
385 \ #{id: 'ssb4', name: '-test://xyz/foo/ssb4' , match: 0},
386 \ #{id: 'ssb5', name: 'test-://xyz/foo/ssb5' , match: 0},
Tsuyoshi CHO7b7a1182021-07-11 21:51:17 +0200387 \]
388 for buf in bufnames
389 new `=buf.name`
390 if buf.match
391 call assert_equal(buf.name, getbufinfo(buf.id)[0].name)
392 else
393 " slashes will have become backslashes
394 call assert_notequal(buf.name, getbufinfo(buf.id)[0].name)
395 endif
396 bwipe
397 endfor
398
399 set shellslash&
400endfunc
401
Bram Moolenaar8e4b76d2022-05-07 11:28:06 +0100402" this was using a NULL pointer after failing to use the pattern
403func Test_buf_pattern_invalid()
404 vsplit 0000000
405 silent! buf [0--]\&\zs*\zs*e
406 bwipe!
Bram Moolenaara59f2df2022-05-11 11:42:28 +0100407
408 vsplit 00000000000000000000000000
409 silent! buf [0--]\&\zs*\zs*e
410 bwipe!
Bram Moolenaarb62dc5e2022-05-15 14:50:12 +0100411
412 " similar case with different code path
413 split 0
414 edit ΓΏ
415 silent! buf [0--]\&\zs*\zs*0
416 bwipe!
Bram Moolenaar8e4b76d2022-05-07 11:28:06 +0100417endfunc
418
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +0200419" Test for the 'maxmem' and 'maxmemtot' options
420func Test_buffer_maxmem()
421 " use 1KB per buffer and 2KB for all the buffers
422 set maxmem=1 maxmemtot=2
423 new
424 let v:errmsg = ''
425 " try opening some files
426 edit test_arglist.vim
427 call assert_equal('test_arglist.vim', bufname())
428 edit test_eval_stuff.vim
429 call assert_equal('test_eval_stuff.vim', bufname())
430 b test_arglist.vim
431 call assert_equal('test_arglist.vim', bufname())
432 b test_eval_stuff.vim
433 call assert_equal('test_eval_stuff.vim', bufname())
434 close
435 call assert_equal('', v:errmsg)
436 set maxmem& maxmemtot&
437endfunc
438
Yegappan Lakshmanan72bb47e2022-04-03 11:22:38 +0100439" Test for buffer allocation failure
Yegappan Lakshmanan0dac1ab2022-04-02 21:46:19 +0100440func Test_buflist_alloc_failure()
441 %bw!
442
Bram Moolenaare7cda972022-08-29 11:02:59 +0100443 edit XallocFail1
Yegappan Lakshmanan72bb47e2022-04-03 11:22:38 +0100444 call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
Bram Moolenaare7cda972022-08-29 11:02:59 +0100445 call assert_fails('edit XallocFail2', 'E342:')
Yegappan Lakshmanan0dac1ab2022-04-02 21:46:19 +0100446
447 " test for bufadd()
Yegappan Lakshmanan72bb47e2022-04-03 11:22:38 +0100448 call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
Yegappan Lakshmanan0dac1ab2022-04-02 21:46:19 +0100449 call assert_fails('call bufadd("Xbuffer")', 'E342:')
450
451 " test for setting the arglist
Bram Moolenaare7cda972022-08-29 11:02:59 +0100452 edit XallocFail2
Yegappan Lakshmanan72bb47e2022-04-03 11:22:38 +0100453 call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
Bram Moolenaare7cda972022-08-29 11:02:59 +0100454 call assert_fails('next XallocFail3', 'E342:')
Yegappan Lakshmanan0dac1ab2022-04-02 21:46:19 +0100455
456 " test for setting the alternate buffer name when writing a file
Yegappan Lakshmanan72bb47e2022-04-03 11:22:38 +0100457 call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
Yegappan Lakshmanan0dac1ab2022-04-02 21:46:19 +0100458 call assert_fails('write Xother', 'E342:')
459 call delete('Xother')
460
461 " test for creating a buffer using bufnr()
Yegappan Lakshmanan72bb47e2022-04-03 11:22:38 +0100462 call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
Yegappan Lakshmanan0dac1ab2022-04-02 21:46:19 +0100463 call assert_fails("call bufnr('Xnewbuf', v:true)", 'E342:')
464
465 " test for renaming buffer using :file
Yegappan Lakshmanan72bb47e2022-04-03 11:22:38 +0100466 call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
Yegappan Lakshmanan0dac1ab2022-04-02 21:46:19 +0100467 call assert_fails('file Xnewfile', 'E342:')
468
469 " test for creating a buffer for a popup window
Yegappan Lakshmanan72bb47e2022-04-03 11:22:38 +0100470 call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
Yegappan Lakshmanan0dac1ab2022-04-02 21:46:19 +0100471 call assert_fails('call popup_create("mypop", {})', 'E342:')
472
473 if has('terminal')
474 " test for creating a buffer for a terminal window
Yegappan Lakshmanan72bb47e2022-04-03 11:22:38 +0100475 call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
Yegappan Lakshmanan0dac1ab2022-04-02 21:46:19 +0100476 call assert_fails('call term_start(&shell)', 'E342:')
477 %bw!
478 endif
479
480 " test for loading a new buffer after wiping out all the buffers
Bram Moolenaare7cda972022-08-29 11:02:59 +0100481 edit XallocFail4
Yegappan Lakshmanan72bb47e2022-04-03 11:22:38 +0100482 call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
Yegappan Lakshmanan0dac1ab2022-04-02 21:46:19 +0100483 call assert_fails('%bw!', 'E342:')
484
485 " test for :checktime loading the buffer
Bram Moolenaar34112652022-09-05 21:40:44 +0100486 call writefile(['one'], 'XallocFail5', 'D')
Yegappan Lakshmanan0dac1ab2022-04-02 21:46:19 +0100487 if has('unix')
Bram Moolenaare7cda972022-08-29 11:02:59 +0100488 edit XallocFail5
Yegappan Lakshmanan0dac1ab2022-04-02 21:46:19 +0100489 " sleep for some time to make sure the timestamp is different
490 sleep 200m
Bram Moolenaare7cda972022-08-29 11:02:59 +0100491 call writefile(['two'], 'XallocFail5')
Yegappan Lakshmanan0dac1ab2022-04-02 21:46:19 +0100492 set autoread
Yegappan Lakshmanan72bb47e2022-04-03 11:22:38 +0100493 call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
Yegappan Lakshmanan0dac1ab2022-04-02 21:46:19 +0100494 call assert_fails('checktime', 'E342:')
495 set autoread&
496 bw!
497 endif
498
499 " test for :vimgrep loading a dummy buffer
Yegappan Lakshmanan72bb47e2022-04-03 11:22:38 +0100500 call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
Bram Moolenaare7cda972022-08-29 11:02:59 +0100501 call assert_fails('vimgrep two XallocFail5', 'E342:')
Yegappan Lakshmanan0dac1ab2022-04-02 21:46:19 +0100502
503 " test for quickfix command loading a buffer
Yegappan Lakshmanan72bb47e2022-04-03 11:22:38 +0100504 call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
Bram Moolenaare7cda972022-08-29 11:02:59 +0100505 call assert_fails('cexpr "XallocFail6:10:Line10"', 'E342:')
Yegappan Lakshmanan0dac1ab2022-04-02 21:46:19 +0100506endfunc
507
Bram Moolenaar9f6277b2020-02-11 22:04:02 +0100508" vim: shiftwidth=2 sts=2 expandtab