Mercurial > vim
comparison src/testdir/test_buffer.vim @ 20990:55b3849ded11 v8.2.1046
patch 8.2.1046: insufficient tests for src/buffer.c
Commit: https://github.com/vim/vim/commit/b7e2483655d9b68df0c7349918027d800051a28a
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Jun 24 13:37:35 2020 +0200
patch 8.2.1046: insufficient tests for src/buffer.c
Problem: Insufficient tests for src/buffer.c.
Solution: Add more tests. Move comments related tests to a separate file.
(Yegappan Lakshmanan, closes #6325)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 24 Jun 2020 13:45:06 +0200 |
parents | 3601e816a569 |
children | 6a4806e326dd |
comparison
equal
deleted
inserted
replaced
20989:c27f8e4ea9d7 | 20990:55b3849ded11 |
---|---|
1 " Tests for Vim buffer | 1 " Tests for Vim buffer |
2 | |
3 source check.vim | |
2 | 4 |
3 " Test for the :bunload command with an offset | 5 " Test for the :bunload command with an offset |
4 func Test_bunload_with_offset() | 6 func Test_bunload_with_offset() |
5 %bwipe! | 7 %bwipe! |
6 call writefile(['B1'], 'b1') | 8 call writefile(['B1'], 'b1') |
150 edit Xfile1 | 152 edit Xfile1 |
151 let bnr = bufnr() | 153 let bnr = bufnr() |
152 set nobuflisted | 154 set nobuflisted |
153 enew | 155 enew |
154 call assert_fails('bdelete ' .. bnr, 'E516:') | 156 call assert_fails('bdelete ' .. bnr, 'E516:') |
157 | |
158 " Deleting more than one buffer | |
159 new Xbuf1 | |
160 new Xbuf2 | |
161 exe 'bdel ' .. bufnr('Xbuf2') .. ' ' .. bufnr('Xbuf1') | |
162 call assert_equal(1, winnr('$')) | |
163 call assert_equal(0, getbufinfo('Xbuf1')[0].loaded) | |
164 call assert_equal(0, getbufinfo('Xbuf2')[0].loaded) | |
165 | |
166 " Deleting more than one buffer and an invalid buffer | |
167 new Xbuf1 | |
168 new Xbuf2 | |
169 let cmd = "exe 'bdel ' .. bufnr('Xbuf2') .. ' xxx ' .. bufnr('Xbuf1')" | |
170 call assert_fails(cmd, 'E94:') | |
171 call assert_equal(2, winnr('$')) | |
172 call assert_equal(1, getbufinfo('Xbuf1')[0].loaded) | |
173 call assert_equal(0, getbufinfo('Xbuf2')[0].loaded) | |
174 | |
155 %bwipe! | 175 %bwipe! |
156 endfunc | 176 endfunc |
157 | 177 |
158 func Test_buffer_error() | 178 func Test_buffer_error() |
159 new foo1 | 179 new foo1 |
164 call assert_fails('buffer 0', 'E939:') | 184 call assert_fails('buffer 0', 'E939:') |
165 | 185 |
166 %bwipe | 186 %bwipe |
167 endfunc | 187 endfunc |
168 | 188 |
189 " Test for the status messages displayed when unloading, deleting or wiping | |
190 " out buffers | |
191 func Test_buffer_statusmsg() | |
192 CheckEnglish | |
193 set report=1 | |
194 new Xbuf1 | |
195 new Xbuf2 | |
196 let bnr = bufnr() | |
197 exe "normal 2\<C-G>" | |
198 call assert_match('buf ' .. bnr .. ':', v:statusmsg) | |
199 bunload Xbuf1 Xbuf2 | |
200 call assert_equal('2 buffers unloaded', v:statusmsg) | |
201 bdel Xbuf1 Xbuf2 | |
202 call assert_equal('2 buffers deleted', v:statusmsg) | |
203 bwipe Xbuf1 Xbuf2 | |
204 call assert_equal('2 buffers wiped out', v:statusmsg) | |
205 set report& | |
206 endfunc | |
207 | |
208 " Test for quitting the 'swapfile exists' dialog with the split buffer | |
209 " command. | |
210 func Test_buffer_sbuf_cleanup() | |
211 call writefile([], 'Xfile') | |
212 " first open the file in a buffer | |
213 new Xfile | |
214 let bnr = bufnr() | |
215 close | |
216 " create the swap file | |
217 call writefile([], '.Xfile.swp') | |
218 " Remove the catch-all that runtest.vim adds | |
219 au! SwapExists | |
220 augroup BufTest | |
221 au! | |
222 autocmd SwapExists Xfile let v:swapchoice='q' | |
223 augroup END | |
224 exe 'sbuf ' . bnr | |
225 call assert_equal(1, winnr('$')) | |
226 call assert_equal(0, getbufinfo('Xfile')[0].loaded) | |
227 | |
228 " test for :sball | |
229 sball | |
230 call assert_equal(1, winnr('$')) | |
231 call assert_equal(0, getbufinfo('Xfile')[0].loaded) | |
232 | |
233 %bw! | |
234 set shortmess+=F | |
235 let v:statusmsg = '' | |
236 edit Xfile | |
237 call assert_equal('', v:statusmsg) | |
238 call assert_equal(1, winnr('$')) | |
239 call assert_equal(0, getbufinfo('Xfile')[0].loaded) | |
240 set shortmess& | |
241 | |
242 call delete('Xfile') | |
243 call delete('.Xfile.swp') | |
244 augroup BufTest | |
245 au! | |
246 augroup END | |
247 augroup! BufTest | |
248 endfunc | |
249 | |
250 " Test for deleting a modified buffer with :confirm | |
251 func Test_bdel_with_confirm() | |
252 CheckUnix | |
253 CheckNotGui | |
254 CheckFeature dialog_con | |
255 new | |
256 call setline(1, 'test') | |
257 call assert_fails('bdel', 'E89:') | |
258 call feedkeys('c', 'L') | |
259 confirm bdel | |
260 call assert_equal(2, winnr('$')) | |
261 call assert_equal(1, &modified) | |
262 call feedkeys('n', 'L') | |
263 confirm bdel | |
264 call assert_equal(1, winnr('$')) | |
265 endfunc | |
266 | |
267 " Test for editing another buffer from a modified buffer with :confirm | |
268 func Test_goto_buf_with_confirm() | |
269 CheckUnix | |
270 CheckNotGui | |
271 CheckFeature dialog_con | |
272 new Xfile | |
273 enew | |
274 call setline(1, 'test') | |
275 call assert_fails('b Xfile', 'E37:') | |
276 call feedkeys('c', 'L') | |
277 call assert_fails('confirm b Xfile', 'E37:') | |
278 call assert_equal(1, &modified) | |
279 call assert_equal('', @%) | |
280 call feedkeys('y', 'L') | |
281 call assert_fails('confirm b Xfile', 'E37:') | |
282 call assert_equal(1, &modified) | |
283 call assert_equal('', @%) | |
284 call feedkeys('n', 'L') | |
285 confirm b Xfile | |
286 call assert_equal('Xfile', @%) | |
287 close! | |
288 endfunc | |
289 | |
290 " Test for splitting buffer with 'switchbuf' | |
291 func Test_buffer_switchbuf() | |
292 new Xfile | |
293 wincmd w | |
294 set switchbuf=useopen | |
295 sbuf Xfile | |
296 call assert_equal(1, winnr()) | |
297 call assert_equal(2, winnr('$')) | |
298 set switchbuf=usetab | |
299 tabnew | |
300 sbuf Xfile | |
301 call assert_equal(1, tabpagenr()) | |
302 call assert_equal(2, tabpagenr('$')) | |
303 set switchbuf& | |
304 %bw | |
305 endfunc | |
306 | |
307 " Test for BufAdd autocommand wiping out the buffer | |
308 func Test_bufadd_autocmd_bwipe() | |
309 %bw! | |
310 augroup BufAdd_Wipe | |
311 au! | |
312 autocmd BufAdd Xfile %bw! | |
313 augroup END | |
314 edit Xfile | |
315 call assert_equal('', @%) | |
316 call assert_equal(0, bufexists('Xfile')) | |
317 augroup BufAdd_Wipe | |
318 au! | |
319 augroup END | |
320 augroup! BufAdd_Wipe | |
321 endfunc | |
322 | |
323 " Test for trying to load a buffer with text locked | |
324 " <C-\>e in the command line is used to lock the text | |
325 func Test_load_buf_with_text_locked() | |
326 new Xfile1 | |
327 edit Xfile2 | |
328 let cmd = ":\<C-\>eexecute(\"normal \<C-O>\")\<CR>\<C-C>" | |
329 call assert_fails("call feedkeys(cmd, 'xt')", 'E565:') | |
330 %bw! | |
331 endfunc | |
332 | |
333 " Test for using CTRL-^ to edit the alternative file keeping the cursor | |
334 " position with 'nostartofline'. Also test using the 'buf' command. | |
335 func Test_buffer_edit_altfile() | |
336 call writefile(repeat(['one two'], 50), 'Xfile1') | |
337 call writefile(repeat(['five six'], 50), 'Xfile2') | |
338 set nosol | |
339 edit Xfile1 | |
340 call cursor(25, 5) | |
341 edit Xfile2 | |
342 call cursor(30, 4) | |
343 exe "normal \<C-^>" | |
344 call assert_equal([0, 25, 5, 0], getpos('.')) | |
345 exe "normal \<C-^>" | |
346 call assert_equal([0, 30, 4, 0], getpos('.')) | |
347 buf Xfile1 | |
348 call assert_equal([0, 25, 5, 0], getpos('.')) | |
349 buf Xfile2 | |
350 call assert_equal([0, 30, 4, 0], getpos('.')) | |
351 set sol& | |
352 call delete('Xfile1') | |
353 call delete('Xfile2') | |
354 endfunc | |
355 | |
356 " Test for running the :sball command with a maximum window count and a | |
357 " modified buffer | |
358 func Test_sball_with_count() | |
359 %bw! | |
360 edit Xfile1 | |
361 call setline(1, ['abc']) | |
362 new Xfile2 | |
363 new Xfile3 | |
364 new Xfile4 | |
365 2sball | |
366 call assert_equal(bufnr('Xfile4'), winbufnr(1)) | |
367 call assert_equal(bufnr('Xfile1'), winbufnr(2)) | |
368 call assert_equal(0, getbufinfo('Xfile2')[0].loaded) | |
369 call assert_equal(0, getbufinfo('Xfile3')[0].loaded) | |
370 %bw! | |
371 endfunc | |
372 | |
169 " vim: shiftwidth=2 sts=2 expandtab | 373 " vim: shiftwidth=2 sts=2 expandtab |