1 " Tests for the history functions
3 if !has('cmdline_hist')
9 function 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))
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))
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))
34 let a=execute('history ' . a:hist)
35 call assert_match("^\n # \\S* history\n 3 buffers\n> 4 ls$", a)
36 let a=execute('history all')
37 call assert_match("^\n # .* history\n 3 buffers\n> 4 ls", a)
40 let a=execute('history ' . a:hist . ' 2')
41 call assert_match("^\n # \\S* history$", a)
42 let a=execute('history ' . a:hist . ' 3')
43 call assert_match("^\n # \\S* history\n 3 buffers$", a)
44 let a=execute('history ' . a:hist . ' 4')
45 call assert_match("^\n # \\S* history\n> 4 ls$", a)
46 let a=execute('history ' . a:hist . ' 3,4')
47 call assert_match("^\n # \\S* history\n 3 buffers\n> 4 ls$", a)
48 let a=execute('history ' . a:hist . ' -1')
49 call assert_match("^\n # \\S* history\n> 4 ls$", a)
50 let a=execute('history ' . a:hist . ' -2')
51 call assert_match("^\n # \\S* history\n 3 buffers$", a)
52 let a=execute('history ' . a:hist . ' -2,')
53 call assert_match("^\n # \\S* history\n 3 buffers\n> 4 ls$", a)
54 let a=execute('history ' . a:hist . ' -3')
55 call assert_match("^\n # \\S* history$", a)
58 " Test for removing entries matching a pattern
60 call histadd(a:hist, 'text_' . i)
62 call assert_true(histdel(a:hist, 'text_\d\+'))
63 call assert_equal('ls', histget(a:hist, -1))
65 " Test for freeing the entire history list
67 call histadd(a:hist, 'text_' . i)
71 call assert_equal('', histget(a:hist, i))
72 call assert_equal('', histget(a:hist, i - 7 - 1))
76 function Test_History()
77 for h in ['cmd', ':', '', 'search', '/', '?', 'expr', '=', 'input', '@', 'debug', '>']
82 call assert_false(histdel('abc'))
83 call assert_equal('', histget('abc'))
84 call assert_fails('call histdel([])', 'E730:')
85 call assert_equal('', histget(10))
86 call assert_fails('call histget([])', 'E730:')
87 call assert_equal(-1, histnr('abc'))
88 call assert_fails('call histnr([])', 'E730:')
91 function Test_Search_history_window()
93 call setline(1, ['a', 'b', 'a', 'b'])
95 call feedkeys("/a\<CR>", 'xt')
96 call assert_equal('a', getline('.'))
98 call feedkeys("/b\<CR>", 'xt')
99 call assert_equal('b', getline('.'))
101 " select the previous /a command
102 call feedkeys("q/kk\<CR>", 'x!')
103 call assert_equal('a', getline('.'))
104 call assert_equal('a', @/)