Hi,

On Sun, Jan 31, 2016 at 2:53 PM, Yegappan Lakshmanan
<[email protected]> wrote:
> Hi all,
>
> There is a bug in the clr_history() function when deleting entries
> from the command history.
>
> When walking through the elements in the history array, the hisptr
> is not updated.
>
> The attached patch fixes this problem.
>

The attached patch adds a new test for the history functions
(histadd, histdel, histget and histnr).

- Yegappan

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.
diff --git a/src/ex_getln.c b/src/ex_getln.c
index 1512b03..6151994 100644
--- a/src/ex_getln.c
+++ b/src/ex_getln.c
@@ -5730,6 +5730,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 */
diff --git a/src/testdir/Make_all.mak b/src/testdir/Make_all.mak
index d7a06ee..2c15af8 100644
--- a/src/testdir/Make_all.mak
+++ b/src/testdir/Make_all.mak
@@ -172,6 +172,7 @@ NEW_TESTS = test_arglist.res \
            test_assert.res \
            test_cdo.res \
            test_hardcopy.res \
+           test_history.res \
            test_increment.res \
            test_langmap.res \
            test_perl.res \
diff --git a/src/testdir/test_history.vim b/src/testdir/test_history.vim
new file mode 100644
index 0000000..ee6acff
--- /dev/null
+++ b/src/testdir/test_history.vim
@@ -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

Raspunde prin e-mail lui