]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 7.4.1494 v7.4.1494
authorBram Moolenaar <Bram@vim.org>
Sat, 5 Mar 2016 20:21:24 +0000 (21:21 +0100)
committerBram Moolenaar <Bram@vim.org>
Sat, 5 Mar 2016 20:21:24 +0000 (21:21 +0100)
Problem:    clr_history() does not work properly.
Solution:   Increment hisptr. Add a test. (Yegappan Lakshmanan)

src/ex_getln.c
src/testdir/Make_all.mak
src/testdir/test_history.vim [new file with mode: 0644]
src/version.c

index 96c3a8ceba56fef014475a0099c5e263a2ce11cf..f9791f58957548235fba4029278c17461fd086fd 100644 (file)
@@ -5783,6 +5783,7 @@ clr_history(int histype)
        {
            vim_free(hisptr->hisstr);
            clear_hist_entry(hisptr);
+           hisptr++;
        }
        hisidx[histype] = -1;   /* mark history as cleared */
        hisnum[histype] = 0;    /* reset identifier counter */
index 854220f0e074e588bb134364ef1746f8bb778075..5ad1718c6f49fbb0798b37b0eca3f4f2a8759e27 100644 (file)
@@ -175,6 +175,7 @@ NEW_TESTS = test_arglist.res \
            test_cdo.res \
            test_channel.res \
            test_hardcopy.res \
+           test_history.res \
            test_increment.res \
            test_json.res \
            test_langmap.res \
diff --git a/src/testdir/test_history.vim b/src/testdir/test_history.vim
new file mode 100644 (file)
index 0000000..ee6acff
--- /dev/null
@@ -0,0 +1,65 @@
+" Tests for the history functions
+
+if !has('cmdline_hist')
+  finish
+endif
+
+set history=7
+
+function History_Tests(hist)
+  " First clear the history
+  call histadd(a:hist, 'dummy')
+  call assert_true(histdel(a:hist))
+  call assert_equal(-1, histnr(a:hist))
+  call assert_equal('', histget(a:hist))
+
+  call assert_true(histadd(a:hist, 'ls'))
+  call assert_true(histadd(a:hist, 'buffers'))
+  call assert_equal('buffers', histget(a:hist))
+  call assert_equal('ls', histget(a:hist, -2))
+  call assert_equal('ls', histget(a:hist, 1))
+  call assert_equal('', histget(a:hist, 5))
+  call assert_equal('', histget(a:hist, -5))
+  call assert_equal(2, histnr(a:hist))
+  call assert_true(histdel(a:hist, 2))
+  call assert_false(histdel(a:hist, 7))
+  call assert_equal(1, histnr(a:hist))
+  call assert_equal('ls', histget(a:hist, -1))
+
+  call assert_true(histadd(a:hist, 'buffers'))
+  call assert_true(histadd(a:hist, 'ls'))
+  call assert_equal('ls', histget(a:hist, -1))
+  call assert_equal(4, histnr(a:hist))
+
+  " Test for removing entries matching a pattern
+  for i in range(1, 3)
+      call histadd(a:hist, 'text_' . i)
+  endfor
+  call assert_true(histdel(a:hist, 'text_\d\+'))
+  call assert_equal('ls', histget(a:hist, -1))
+
+  " Test for freeing the entire history list
+  for i in range(1, 7)
+      call histadd(a:hist, 'text_' . i)
+  endfor
+  call histdel(a:hist)
+  for i in range(1, 7)
+    call assert_equal('', histget(a:hist, i))
+    call assert_equal('', histget(a:hist, i - 7 - 1))
+  endfor
+endfunction
+
+function Test_History()
+  for h in ['cmd', ':', '', 'search', '/', '?', 'expr', '=', 'input', '@', 'debug', '>']
+    call History_Tests(h)
+  endfor
+
+  " Negative tests
+  call assert_false(histdel('abc'))
+  call assert_equal('', histget('abc'))
+  call assert_fails('call histdel([])', 'E730:')
+  call assert_equal('', histget(10))
+  call assert_fails('call histget([])', 'E730:')
+  call assert_equal(-1, histnr('abc'))
+  call assert_fails('call histnr([])', 'E730:')
+endfunction
index fe5d00edadf212b1b62bfa94f4b33f982c35a80f..ce21ae7f41aba580c64f83ff227625eedbaf4b16 100644 (file)
@@ -743,6 +743,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1494,
 /**/
     1493,
 /**/