vim-patch:8.2.2850: recalling commands from history is not tested

Problem:    Recalling commands from history is not tested.
Solution:   Add tests. (closes vim/vim#8194)
71c6f7a665
This commit is contained in:
Jan Edmund Lazo 2021-05-13 23:56:34 -04:00
parent 5110ef9171
commit 520b925627
No known key found for this signature in database
GPG Key ID: 64915E6E9F735B15

View File

@ -1072,4 +1072,52 @@ func Test_read_shellcmd()
endif
endfunc
" Test for recalling newer or older cmdline from history with <Up>, <Down>,
" <S-Up>, <S-Down>, <PageUp>, <PageDown>, <C-p>, or <C-n>.
func Test_recalling_cmdline()
CheckFeature cmdline_hist
let g:cmdlines = []
cnoremap <Plug>(save-cmdline) <Cmd>let g:cmdlines += [getcmdline()]<CR>
let histories = [
\ {'name': 'cmd', 'enter': ':', 'exit': "\<Esc>"},
\ {'name': 'search', 'enter': '/', 'exit': "\<Esc>"},
\ {'name': 'expr', 'enter': ":\<C-r>=", 'exit': "\<Esc>\<Esc>"},
\ {'name': 'input', 'enter': ":call input('')\<CR>", 'exit': "\<CR>"},
"\ TODO: {'name': 'debug', ...}
\]
let keypairs = [
\ {'older': "\<Up>", 'newer': "\<Down>", 'prefixmatch': v:true},
\ {'older': "\<S-Up>", 'newer': "\<S-Down>", 'prefixmatch': v:false},
\ {'older': "\<PageUp>", 'newer': "\<PageDown>", 'prefixmatch': v:false},
\ {'older': "\<C-p>", 'newer': "\<C-n>", 'prefixmatch': v:false},
\]
let prefix = 'vi'
for h in histories
call histadd(h.name, 'vim')
call histadd(h.name, 'virtue')
call histadd(h.name, 'Virgo')
call histadd(h.name, 'vogue')
call histadd(h.name, 'emacs')
for k in keypairs
let g:cmdlines = []
let keyseqs = h.enter
\ .. prefix
\ .. repeat(k.older .. "\<Plug>(save-cmdline)", 2)
\ .. repeat(k.newer .. "\<Plug>(save-cmdline)", 2)
\ .. h.exit
call feedkeys(keyseqs, 'xt')
call histdel(h.name, -1) " delete the history added by feedkeys above
let expect = k.prefixmatch
\ ? ['virtue', 'vim', 'virtue', prefix]
\ : ['emacs', 'vogue', 'emacs', prefix]
call assert_equal(expect, g:cmdlines)
endfor
endfor
unlet g:cmdlines
cunmap <Plug>(save-cmdline)
endfunc
" vim: shiftwidth=2 sts=2 expandtab