blob: c7dd1368838f5e5ec13d25537cd0146971cf34bf [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!
8 call writefile(['B1'], 'b1')
9 call writefile(['B2'], 'b2')
10 call writefile(['B3'], 'b3')
11 call writefile(['B4'], 'b4')
12
13 " Load four buffers. Unload the second and third buffers and then
14 " execute .+3bunload to unload the last buffer.
15 edit b1
16 new b2
17 new b3
18 new b4
19
20 bunload b2
21 bunload b3
22 exe bufwinnr('b1') . 'wincmd w'
23 .+3bunload
24 call assert_equal(0, getbufinfo('b4')[0].loaded)
25 call assert_equal('b1',
26 \ 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
31 bunload b3
32 bunload b4
33 exe bufwinnr('b1') . 'wincmd w'
34 .+3bunload
35 call assert_equal(0, getbufinfo('b2')[0].loaded)
36 call assert_equal('b1',
37 \ 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
42 bunload b2
43 bunload b3
44 exe bufwinnr('b4') . 'wincmd w'
45 .-3bunload
46 call assert_equal(0, getbufinfo('b1')[0].loaded)
47 call assert_equal('b4',
48 \ 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
53 bunload b1
54 bunload b2
55 exe bufwinnr('b4') . 'wincmd w'
56 .-3bunload
57 call assert_equal(0, getbufinfo('b3')[0].loaded)
58 call assert_equal('b4',
59 \ fnamemodify(getbufinfo({'bufloaded' : 1})[0].name, ':t'))
60
61 %bwipe!
62 call delete('b1')
63 call delete('b2')
64 call delete('b3')
65 call delete('b4')
Bram Moolenaarf0cee192020-02-16 13:33:56 +010066
67 call assert_fails('1,4bunload', 'E16:')
68 call assert_fails(',100bunload', 'E16:')
69
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +020070 call assert_fails('$bunload', 'E90:')
Bram Moolenaarf0cee192020-02-16 13:33:56 +010071endfunc
72
73" Test for :buffer, :bnext, :bprevious, :brewind, :blast and :bmodified
74" commands
75func Test_buflist_browse()
76 %bwipe!
77 call assert_fails('buffer 1000', 'E86:')
78
Bram Moolenaare7cda972022-08-29 11:02:59 +010079 call writefile(['foo1', 'foo2', 'foo3', 'foo4'], 'Xbrowse1')
80 call writefile(['bar1', 'bar2', 'bar3', 'bar4'], 'Xbrowse2')
81 call writefile(['baz1', 'baz2', 'baz3', 'baz4'], 'Xbrowse3')
82 edit Xbrowse1
Bram Moolenaarf0cee192020-02-16 13:33:56 +010083 let b1 = bufnr()
Bram Moolenaare7cda972022-08-29 11:02:59 +010084 edit Xbrowse2
Bram Moolenaarf0cee192020-02-16 13:33:56 +010085 let b2 = bufnr()
Bram Moolenaare7cda972022-08-29 11:02:59 +010086 edit +/baz4 Xbrowse3
Bram Moolenaarf0cee192020-02-16 13:33:56 +010087 let b3 = bufnr()
88
89 call assert_fails('buffer ' .. b1 .. ' abc', 'E488:')
90 call assert_equal(b3, bufnr())
91 call assert_equal(4, line('.'))
92 exe 'buffer +/bar2 ' .. b2
93 call assert_equal(b2, bufnr())
94 call assert_equal(2, line('.'))
95 exe 'buffer +/bar1'
96 call assert_equal(b2, bufnr())
97 call assert_equal(1, line('.'))
98
Bram Moolenaarbc2b71d2020-02-17 21:33:30 +010099 brewind +
Bram Moolenaarf0cee192020-02-16 13:33:56 +0100100 call assert_equal(b1, bufnr())
Bram Moolenaarbc2b71d2020-02-17 21:33:30 +0100101 call assert_equal(4, line('.'))
Bram Moolenaarf0cee192020-02-16 13:33:56 +0100102
103 blast +/baz2
104 call assert_equal(b3, bufnr())
105 call assert_equal(2, line('.'))
106
107 bprevious +/bar4
108 call assert_equal(b2, bufnr())
109 call assert_equal(4, line('.'))
110
111 bnext +/baz3
112 call assert_equal(b3, bufnr())
113 call assert_equal(3, line('.'))
114
115 call assert_fails('bmodified', 'E84:')
116 call setbufvar(b2, '&modified', 1)
117 exe 'bmodified +/bar3'
118 call assert_equal(b2, bufnr())
119 call assert_equal(3, line('.'))
120
121 " With no listed buffers in the list, :bnext and :bprev should fail
122 %bwipe!
123 set nobuflisted
124 call assert_fails('bnext', 'E85:')
125 call assert_fails('bprev', 'E85:')
126 set buflisted
127
128 call assert_fails('sandbox bnext', 'E48:')
129
Bram Moolenaare7cda972022-08-29 11:02:59 +0100130 call delete('Xbrowse1')
131 call delete('Xbrowse2')
132 call delete('Xbrowse3')
Bram Moolenaarf0cee192020-02-16 13:33:56 +0100133 %bwipe!
134endfunc
135
136" Test for :bdelete
137func Test_bdelete_cmd()
138 %bwipe!
139 call assert_fails('bdelete 5', 'E516:')
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100140 call assert_fails('1,1bdelete 1 2', 'E488:')
Bram Moolenaar531be472020-09-23 22:38:05 +0200141 call assert_fails('bdelete \)', 'E55:')
Bram Moolenaarf0cee192020-02-16 13:33:56 +0100142
143 " Deleting a unlisted and unloaded buffer
144 edit Xfile1
145 let bnr = bufnr()
146 set nobuflisted
147 enew
148 call assert_fails('bdelete ' .. bnr, 'E516:')
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200149
150 " Deleting more than one buffer
151 new Xbuf1
152 new Xbuf2
153 exe 'bdel ' .. bufnr('Xbuf2') .. ' ' .. bufnr('Xbuf1')
154 call assert_equal(1, winnr('$'))
155 call assert_equal(0, getbufinfo('Xbuf1')[0].loaded)
156 call assert_equal(0, getbufinfo('Xbuf2')[0].loaded)
157
158 " Deleting more than one buffer and an invalid buffer
159 new Xbuf1
160 new Xbuf2
161 let cmd = "exe 'bdel ' .. bufnr('Xbuf2') .. ' xxx ' .. bufnr('Xbuf1')"
162 call assert_fails(cmd, 'E94:')
163 call assert_equal(2, winnr('$'))
164 call assert_equal(1, getbufinfo('Xbuf1')[0].loaded)
165 call assert_equal(0, getbufinfo('Xbuf2')[0].loaded)
166
Bram Moolenaarf0cee192020-02-16 13:33:56 +0100167 %bwipe!
Bram Moolenaar9f6277b2020-02-11 22:04:02 +0100168endfunc
169
Bram Moolenaar067297e2020-04-13 19:55:50 +0200170func Test_buffer_error()
171 new foo1
172 new foo2
173
174 call assert_fails('buffer foo', 'E93:')
175 call assert_fails('buffer bar', 'E94:')
176 call assert_fails('buffer 0', 'E939:')
177
178 %bwipe
179endfunc
180
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200181" Test for the status messages displayed when unloading, deleting or wiping
182" out buffers
183func Test_buffer_statusmsg()
184 CheckEnglish
185 set report=1
186 new Xbuf1
187 new Xbuf2
188 let bnr = bufnr()
189 exe "normal 2\<C-G>"
190 call assert_match('buf ' .. bnr .. ':', v:statusmsg)
191 bunload Xbuf1 Xbuf2
192 call assert_equal('2 buffers unloaded', v:statusmsg)
193 bdel Xbuf1 Xbuf2
194 call assert_equal('2 buffers deleted', v:statusmsg)
195 bwipe Xbuf1 Xbuf2
196 call assert_equal('2 buffers wiped out', v:statusmsg)
197 set report&
198endfunc
199
200" Test for quitting the 'swapfile exists' dialog with the split buffer
201" command.
202func Test_buffer_sbuf_cleanup()
Bram Moolenaare7cda972022-08-29 11:02:59 +0100203 call writefile([], 'XsplitCleanup')
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200204 " first open the file in a buffer
Bram Moolenaare7cda972022-08-29 11:02:59 +0100205 new XsplitCleanup
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200206 let bnr = bufnr()
207 close
208 " create the swap file
Bram Moolenaare7cda972022-08-29 11:02:59 +0100209 call writefile([], '.XsplitCleanup.swp')
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200210 " Remove the catch-all that runtest.vim adds
211 au! SwapExists
212 augroup BufTest
213 au!
Bram Moolenaare7cda972022-08-29 11:02:59 +0100214 autocmd SwapExists XsplitCleanup let v:swapchoice='q'
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200215 augroup END
216 exe 'sbuf ' . bnr
217 call assert_equal(1, winnr('$'))
Bram Moolenaare7cda972022-08-29 11:02:59 +0100218 call assert_equal(0, getbufinfo('XsplitCleanup')[0].loaded)
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200219
220 " test for :sball
221 sball
222 call assert_equal(1, winnr('$'))
Bram Moolenaare7cda972022-08-29 11:02:59 +0100223 call assert_equal(0, getbufinfo('XsplitCleanup')[0].loaded)
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200224
225 %bw!
226 set shortmess+=F
227 let v:statusmsg = ''
Bram Moolenaare7cda972022-08-29 11:02:59 +0100228 edit XsplitCleanup
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200229 call assert_equal('', v:statusmsg)
230 call assert_equal(1, winnr('$'))
Bram Moolenaare7cda972022-08-29 11:02:59 +0100231 call assert_equal(0, getbufinfo('XsplitCleanup')[0].loaded)
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200232 set shortmess&
233
Bram Moolenaare7cda972022-08-29 11:02:59 +0100234 call delete('XsplitCleanup')
235 call delete('.XsplitCleanup.swp')
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200236 augroup BufTest
237 au!
238 augroup END
239 augroup! BufTest
240endfunc
241
242" Test for deleting a modified buffer with :confirm
243func Test_bdel_with_confirm()
244 CheckUnix
245 CheckNotGui
246 CheckFeature dialog_con
247 new
248 call setline(1, 'test')
249 call assert_fails('bdel', 'E89:')
250 call feedkeys('c', 'L')
251 confirm bdel
252 call assert_equal(2, winnr('$'))
253 call assert_equal(1, &modified)
254 call feedkeys('n', 'L')
255 confirm bdel
256 call assert_equal(1, winnr('$'))
257endfunc
258
259" Test for editing another buffer from a modified buffer with :confirm
260func Test_goto_buf_with_confirm()
261 CheckUnix
262 CheckNotGui
263 CheckFeature dialog_con
Bram Moolenaare7cda972022-08-29 11:02:59 +0100264 new XgotoConf
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200265 enew
266 call setline(1, 'test')
Bram Moolenaare7cda972022-08-29 11:02:59 +0100267 call assert_fails('b XgotoConf', 'E37:')
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200268 call feedkeys('c', 'L')
Bram Moolenaare7cda972022-08-29 11:02:59 +0100269 call assert_fails('confirm b XgotoConf', 'E37:')
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200270 call assert_equal(1, &modified)
271 call assert_equal('', @%)
272 call feedkeys('y', 'L')
Bram Moolenaare7cda972022-08-29 11:02:59 +0100273 call assert_fails('confirm b XgotoConf', ['', 'E37:'])
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200274 call assert_equal(1, &modified)
275 call assert_equal('', @%)
276 call feedkeys('n', 'L')
Bram Moolenaare7cda972022-08-29 11:02:59 +0100277 confirm b XgotoConf
278 call assert_equal('XgotoConf', @%)
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200279 close!
280endfunc
281
282" Test for splitting buffer with 'switchbuf'
283func Test_buffer_switchbuf()
Bram Moolenaare7cda972022-08-29 11:02:59 +0100284 new Xswitchbuf
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200285 wincmd w
286 set switchbuf=useopen
Bram Moolenaare7cda972022-08-29 11:02:59 +0100287 sbuf Xswitchbuf
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200288 call assert_equal(1, winnr())
289 call assert_equal(2, winnr('$'))
290 set switchbuf=usetab
291 tabnew
Bram Moolenaare7cda972022-08-29 11:02:59 +0100292 sbuf Xswitchbuf
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200293 call assert_equal(1, tabpagenr())
294 call assert_equal(2, tabpagenr('$'))
295 set switchbuf&
296 %bw
297endfunc
298
299" Test for BufAdd autocommand wiping out the buffer
300func Test_bufadd_autocmd_bwipe()
301 %bw!
302 augroup BufAdd_Wipe
303 au!
Bram Moolenaare7cda972022-08-29 11:02:59 +0100304 autocmd BufAdd Xbwipe %bw!
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200305 augroup END
Bram Moolenaare7cda972022-08-29 11:02:59 +0100306 edit Xbwipe
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200307 call assert_equal('', @%)
Bram Moolenaare7cda972022-08-29 11:02:59 +0100308 call assert_equal(0, bufexists('Xbwipe'))
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200309 augroup BufAdd_Wipe
310 au!
311 augroup END
312 augroup! BufAdd_Wipe
313endfunc
314
315" Test for trying to load a buffer with text locked
316" <C-\>e in the command line is used to lock the text
317func Test_load_buf_with_text_locked()
318 new Xfile1
319 edit Xfile2
320 let cmd = ":\<C-\>eexecute(\"normal \<C-O>\")\<CR>\<C-C>"
321 call assert_fails("call feedkeys(cmd, 'xt')", 'E565:')
322 %bw!
323endfunc
324
325" Test for using CTRL-^ to edit the alternative file keeping the cursor
326" position with 'nostartofline'. Also test using the 'buf' command.
327func Test_buffer_edit_altfile()
Bram Moolenaare7cda972022-08-29 11:02:59 +0100328 call writefile(repeat(['one two'], 50), 'Xaltfile1')
329 call writefile(repeat(['five six'], 50), 'Xaltfile2')
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200330 set nosol
Bram Moolenaare7cda972022-08-29 11:02:59 +0100331 edit Xaltfile1
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200332 call cursor(25, 5)
Bram Moolenaare7cda972022-08-29 11:02:59 +0100333 edit Xaltfile2
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200334 call cursor(30, 4)
335 exe "normal \<C-^>"
336 call assert_equal([0, 25, 5, 0], getpos('.'))
337 exe "normal \<C-^>"
338 call assert_equal([0, 30, 4, 0], getpos('.'))
Bram Moolenaare7cda972022-08-29 11:02:59 +0100339 buf Xaltfile1
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200340 call assert_equal([0, 25, 5, 0], getpos('.'))
Bram Moolenaare7cda972022-08-29 11:02:59 +0100341 buf Xaltfile2
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200342 call assert_equal([0, 30, 4, 0], getpos('.'))
343 set sol&
Bram Moolenaare7cda972022-08-29 11:02:59 +0100344 call delete('Xaltfile1')
345 call delete('Xaltfile2')
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200346endfunc
347
348" Test for running the :sball command with a maximum window count and a
349" modified buffer
350func Test_sball_with_count()
351 %bw!
Bram Moolenaare7cda972022-08-29 11:02:59 +0100352 edit Xcountfile1
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200353 call setline(1, ['abc'])
Bram Moolenaare7cda972022-08-29 11:02:59 +0100354 new Xcountfile2
355 new Xcountfile3
356 new Xcountfile4
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200357 2sball
Bram Moolenaare7cda972022-08-29 11:02:59 +0100358 call assert_equal(bufnr('Xcountfile4'), winbufnr(1))
359 call assert_equal(bufnr('Xcountfile1'), winbufnr(2))
360 call assert_equal(0, getbufinfo('Xcountfile2')[0].loaded)
361 call assert_equal(0, getbufinfo('Xcountfile3')[0].loaded)
Bram Moolenaarb7e24832020-06-24 13:37:35 +0200362 %bw!
363endfunc
364
Bram Moolenaare974fa72020-10-25 15:02:51 +0100365func Test_badd_options()
366 new SomeNewBuffer
Bram Moolenaar37e4e032020-10-25 16:18:26 +0100367 setlocal numberwidth=3
Bram Moolenaare974fa72020-10-25 15:02:51 +0100368 wincmd p
Bram Moolenaar89b693e2020-10-25 17:09:50 +0100369 badd +1 SomeNewBuffer
Bram Moolenaare974fa72020-10-25 15:02:51 +0100370 new SomeNewBuffer
Bram Moolenaar37e4e032020-10-25 16:18:26 +0100371 call assert_equal(3, &numberwidth)
Bram Moolenaare974fa72020-10-25 15:02:51 +0100372 close
373 close
374 bwipe! SomeNewBuffer
375endfunc
376
Bram Moolenaar59d8e562020-11-07 18:41:10 +0100377func Test_balt()
378 new SomeNewBuffer
379 balt +3 OtherBuffer
380 e #
381 call assert_equal('OtherBuffer', bufname())
382endfunc
383
Tsuyoshi CHO7b7a1182021-07-11 21:51:17 +0200384" Test for buffer match URL(scheme) check
385" scheme is alpha and inner hyphen only.
386func Test_buffer_scheme()
387 CheckMSWindows
388
389 set noshellslash
390 %bwipe!
391 let bufnames = [
Bram Moolenaarf8bc0ce2021-12-02 12:30:22 +0000392 \ #{id: 'ssb0', name: 'test://xyz/foo/ssb0' , match: 1},
393 \ #{id: 'ssb1', name: 'test+abc://xyz/foo/ssb1', match: 0},
394 \ #{id: 'ssb2', name: 'test_abc://xyz/foo/ssb2', match: 0},
395 \ #{id: 'ssb3', name: 'test-abc://xyz/foo/ssb3', match: 1},
396 \ #{id: 'ssb4', name: '-test://xyz/foo/ssb4' , match: 0},
397 \ #{id: 'ssb5', name: 'test-://xyz/foo/ssb5' , match: 0},
Tsuyoshi CHO7b7a1182021-07-11 21:51:17 +0200398 \]
399 for buf in bufnames
400 new `=buf.name`
401 if buf.match
402 call assert_equal(buf.name, getbufinfo(buf.id)[0].name)
403 else
404 " slashes will have become backslashes
405 call assert_notequal(buf.name, getbufinfo(buf.id)[0].name)
406 endif
407 bwipe
408 endfor
409
410 set shellslash&
411endfunc
412
Bram Moolenaar8e4b76d2022-05-07 11:28:06 +0100413" this was using a NULL pointer after failing to use the pattern
414func Test_buf_pattern_invalid()
415 vsplit 0000000
416 silent! buf [0--]\&\zs*\zs*e
417 bwipe!
Bram Moolenaara59f2df2022-05-11 11:42:28 +0100418
419 vsplit 00000000000000000000000000
420 silent! buf [0--]\&\zs*\zs*e
421 bwipe!
Bram Moolenaarb62dc5e2022-05-15 14:50:12 +0100422
423 " similar case with different code path
424 split 0
425 edit ΓΏ
426 silent! buf [0--]\&\zs*\zs*0
427 bwipe!
Bram Moolenaar8e4b76d2022-05-07 11:28:06 +0100428endfunc
429
Yegappan Lakshmanan46aa6f92021-05-19 17:15:04 +0200430" Test for the 'maxmem' and 'maxmemtot' options
431func Test_buffer_maxmem()
432 " use 1KB per buffer and 2KB for all the buffers
433 set maxmem=1 maxmemtot=2
434 new
435 let v:errmsg = ''
436 " try opening some files
437 edit test_arglist.vim
438 call assert_equal('test_arglist.vim', bufname())
439 edit test_eval_stuff.vim
440 call assert_equal('test_eval_stuff.vim', bufname())
441 b test_arglist.vim
442 call assert_equal('test_arglist.vim', bufname())
443 b test_eval_stuff.vim
444 call assert_equal('test_eval_stuff.vim', bufname())
445 close
446 call assert_equal('', v:errmsg)
447 set maxmem& maxmemtot&
448endfunc
449
Yegappan Lakshmanan72bb47e2022-04-03 11:22:38 +0100450" Test for buffer allocation failure
Yegappan Lakshmanan0dac1ab2022-04-02 21:46:19 +0100451func Test_buflist_alloc_failure()
452 %bw!
453
Bram Moolenaare7cda972022-08-29 11:02:59 +0100454 edit XallocFail1
Yegappan Lakshmanan72bb47e2022-04-03 11:22:38 +0100455 call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
Bram Moolenaare7cda972022-08-29 11:02:59 +0100456 call assert_fails('edit XallocFail2', 'E342:')
Yegappan Lakshmanan0dac1ab2022-04-02 21:46:19 +0100457
458 " test for bufadd()
Yegappan Lakshmanan72bb47e2022-04-03 11:22:38 +0100459 call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
Yegappan Lakshmanan0dac1ab2022-04-02 21:46:19 +0100460 call assert_fails('call bufadd("Xbuffer")', 'E342:')
461
462 " test for setting the arglist
Bram Moolenaare7cda972022-08-29 11:02:59 +0100463 edit XallocFail2
Yegappan Lakshmanan72bb47e2022-04-03 11:22:38 +0100464 call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
Bram Moolenaare7cda972022-08-29 11:02:59 +0100465 call assert_fails('next XallocFail3', 'E342:')
Yegappan Lakshmanan0dac1ab2022-04-02 21:46:19 +0100466
467 " test for setting the alternate buffer name when writing a file
Yegappan Lakshmanan72bb47e2022-04-03 11:22:38 +0100468 call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
Yegappan Lakshmanan0dac1ab2022-04-02 21:46:19 +0100469 call assert_fails('write Xother', 'E342:')
470 call delete('Xother')
471
472 " test for creating a buffer using bufnr()
Yegappan Lakshmanan72bb47e2022-04-03 11:22:38 +0100473 call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
Yegappan Lakshmanan0dac1ab2022-04-02 21:46:19 +0100474 call assert_fails("call bufnr('Xnewbuf', v:true)", 'E342:')
475
476 " test for renaming buffer using :file
Yegappan Lakshmanan72bb47e2022-04-03 11:22:38 +0100477 call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
Yegappan Lakshmanan0dac1ab2022-04-02 21:46:19 +0100478 call assert_fails('file Xnewfile', 'E342:')
479
480 " test for creating a buffer for a popup window
Yegappan Lakshmanan72bb47e2022-04-03 11:22:38 +0100481 call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
Yegappan Lakshmanan0dac1ab2022-04-02 21:46:19 +0100482 call assert_fails('call popup_create("mypop", {})', 'E342:')
483
484 if has('terminal')
485 " test for creating a buffer for a terminal window
Yegappan Lakshmanan72bb47e2022-04-03 11:22:38 +0100486 call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
Yegappan Lakshmanan0dac1ab2022-04-02 21:46:19 +0100487 call assert_fails('call term_start(&shell)', 'E342:')
488 %bw!
489 endif
490
491 " test for loading a new buffer after wiping out all the buffers
Bram Moolenaare7cda972022-08-29 11:02:59 +0100492 edit XallocFail4
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('%bw!', 'E342:')
495
496 " test for :checktime loading the buffer
Bram Moolenaare7cda972022-08-29 11:02:59 +0100497 call writefile(['one'], 'XallocFail5')
Yegappan Lakshmanan0dac1ab2022-04-02 21:46:19 +0100498 if has('unix')
Bram Moolenaare7cda972022-08-29 11:02:59 +0100499 edit XallocFail5
Yegappan Lakshmanan0dac1ab2022-04-02 21:46:19 +0100500 " sleep for some time to make sure the timestamp is different
501 sleep 200m
Bram Moolenaare7cda972022-08-29 11:02:59 +0100502 call writefile(['two'], 'XallocFail5')
Yegappan Lakshmanan0dac1ab2022-04-02 21:46:19 +0100503 set autoread
Yegappan Lakshmanan72bb47e2022-04-03 11:22:38 +0100504 call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
Yegappan Lakshmanan0dac1ab2022-04-02 21:46:19 +0100505 call assert_fails('checktime', 'E342:')
506 set autoread&
507 bw!
508 endif
509
510 " test for :vimgrep loading a dummy buffer
Yegappan Lakshmanan72bb47e2022-04-03 11:22:38 +0100511 call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
Bram Moolenaare7cda972022-08-29 11:02:59 +0100512 call assert_fails('vimgrep two XallocFail5', 'E342:')
513 call delete('XallocFail5')
Yegappan Lakshmanan0dac1ab2022-04-02 21:46:19 +0100514
515 " test for quickfix command loading a buffer
Yegappan Lakshmanan72bb47e2022-04-03 11:22:38 +0100516 call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
Bram Moolenaare7cda972022-08-29 11:02:59 +0100517 call assert_fails('cexpr "XallocFail6:10:Line10"', 'E342:')
Yegappan Lakshmanan0dac1ab2022-04-02 21:46:19 +0100518endfunc
519
Bram Moolenaar9f6277b2020-02-11 22:04:02 +0100520" vim: shiftwidth=2 sts=2 expandtab