From 9f6277bdde97b7767ded43a0b5a2023eb601b3b7 Mon Sep 17 00:00:00 2001
From: Bram Moolenaar <Bram@vim.org>
Date: Tue, 11 Feb 2020 22:04:02 +0100
Subject: [PATCH] patch 8.2.0243: insufficient code coverage for ex_docmd.c
 functions

Problem:    Insufficient code coverage for ex_docmd.c functions.
Solution:   Add more tests. (Yegappan Lakshmanan, closes #5618)
---
 src/testdir/Make_all.mak    |  2 ++
 src/testdir/test_buffer.vim | 66 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 68 insertions(+)
 create mode 100644 src/testdir/test_buffer.vim

diff --git a/src/testdir/Make_all.mak b/src/testdir/Make_all.mak
index 05e7a2c..e608b92 100644
--- a/src/testdir/Make_all.mak
+++ b/src/testdir/Make_all.mak
@@ -65,6 +65,7 @@ NEW_TESTS = \
 	test_blob \
 	test_blockedit \
 	test_breakindent \
+	test_buffer \
 	test_bufline \
 	test_bufwintabinfo \
 	test_cd \
@@ -307,6 +308,7 @@ NEW_TESTS_RES = \
 	test_blob.res \
 	test_blockedit.res \
 	test_breakindent.res \
+        test_buffer.res \
 	test_bufwintabinfo.res \
 	test_cdo.res \
 	test_changelist.res \
diff --git a/src/testdir/test_buffer.vim b/src/testdir/test_buffer.vim
new file mode 100644
index 0000000..dc35bb4
--- /dev/null
+++ b/src/testdir/test_buffer.vim
@@ -0,0 +1,66 @@
+" Tests for Vim buffer
+
+" Test for the :bunload command with an offset
+func Test_bunload_with_offset()
+  %bwipe!
+  call writefile(['B1'], 'b1')
+  call writefile(['B2'], 'b2')
+  call writefile(['B3'], 'b3')
+  call writefile(['B4'], 'b4')
+
+  " Load four buffers. Unload the second and third buffers and then
+  " execute .+3bunload to unload the last buffer.
+  edit b1
+  new b2
+  new b3
+  new b4
+
+  bunload b2
+  bunload b3
+  exe bufwinnr('b1') . 'wincmd w'
+  .+3bunload
+  call assert_equal(0, getbufinfo('b4')[0].loaded)
+  call assert_equal('b1',
+        \ fnamemodify(getbufinfo({'bufloaded' : 1})[0].name, ':t'))
+
+  " Load four buffers. Unload the third and fourth buffers. Execute .+3bunload
+  " and check whether the second buffer is unloaded.
+  ball
+  bunload b3
+  bunload b4
+  exe bufwinnr('b1') . 'wincmd w'
+  .+3bunload
+  call assert_equal(0, getbufinfo('b2')[0].loaded)
+  call assert_equal('b1',
+        \ fnamemodify(getbufinfo({'bufloaded' : 1})[0].name, ':t'))
+
+  " Load four buffers. Unload the second and third buffers and from the last
+  " buffer execute .-3bunload to unload the first buffer.
+  ball
+  bunload b2
+  bunload b3
+  exe bufwinnr('b4') . 'wincmd w'
+  .-3bunload
+  call assert_equal(0, getbufinfo('b1')[0].loaded)
+  call assert_equal('b4',
+        \ fnamemodify(getbufinfo({'bufloaded' : 1})[0].name, ':t'))
+
+  " Load four buffers. Unload the first and second buffers. Execute .-3bunload
+  " from the last buffer and check whether the third buffer is unloaded.
+  ball
+  bunload b1
+  bunload b2
+  exe bufwinnr('b4') . 'wincmd w'
+  .-3bunload
+  call assert_equal(0, getbufinfo('b3')[0].loaded)
+  call assert_equal('b4',
+        \ fnamemodify(getbufinfo({'bufloaded' : 1})[0].name, ':t'))
+
+  %bwipe!
+  call delete('b1')
+  call delete('b2')
+  call delete('b3')
+  call delete('b4')
+endfunc
+
+" vim: shiftwidth=2 sts=2 expandtab
-- 
1.8.3.1

