blob: ee6acfffc3c7810e271f972633d420a0da98d8d9 [file] [log] [blame]
Bram Moolenaar119d4692016-03-05 21:21:24 +01001" Tests for the history functions
2
3if !has('cmdline_hist')
4 finish
5endif
6
7set history=7
8
9function History_Tests(hist)
10 " First clear the history
11 call histadd(a:hist, 'dummy')
12 call assert_true(histdel(a:hist))
13 call assert_equal(-1, histnr(a:hist))
14 call assert_equal('', histget(a:hist))
15
16 call assert_true(histadd(a:hist, 'ls'))
17 call assert_true(histadd(a:hist, 'buffers'))
18 call assert_equal('buffers', histget(a:hist))
19 call assert_equal('ls', histget(a:hist, -2))
20 call assert_equal('ls', histget(a:hist, 1))
21 call assert_equal('', histget(a:hist, 5))
22 call assert_equal('', histget(a:hist, -5))
23 call assert_equal(2, histnr(a:hist))
24 call assert_true(histdel(a:hist, 2))
25 call assert_false(histdel(a:hist, 7))
26 call assert_equal(1, histnr(a:hist))
27 call assert_equal('ls', histget(a:hist, -1))
28
29 call assert_true(histadd(a:hist, 'buffers'))
30 call assert_true(histadd(a:hist, 'ls'))
31 call assert_equal('ls', histget(a:hist, -1))
32 call assert_equal(4, histnr(a:hist))
33
34 " Test for removing entries matching a pattern
35 for i in range(1, 3)
36 call histadd(a:hist, 'text_' . i)
37 endfor
38 call assert_true(histdel(a:hist, 'text_\d\+'))
39 call assert_equal('ls', histget(a:hist, -1))
40
41 " Test for freeing the entire history list
42 for i in range(1, 7)
43 call histadd(a:hist, 'text_' . i)
44 endfor
45 call histdel(a:hist)
46 for i in range(1, 7)
47 call assert_equal('', histget(a:hist, i))
48 call assert_equal('', histget(a:hist, i - 7 - 1))
49 endfor
50endfunction
51
52function Test_History()
53 for h in ['cmd', ':', '', 'search', '/', '?', 'expr', '=', 'input', '@', 'debug', '>']
54 call History_Tests(h)
55 endfor
56
57 " Negative tests
58 call assert_false(histdel('abc'))
59 call assert_equal('', histget('abc'))
60 call assert_fails('call histdel([])', 'E730:')
61 call assert_equal('', histget(10))
62 call assert_fails('call histget([])', 'E730:')
63 call assert_equal(-1, histnr('abc'))
64 call assert_fails('call histnr([])', 'E730:')
65endfunction