mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:8.1.1206: user command parsing and listing not properly tested
Problem: User command parsing and listing not properly tested.
Solution: Add more tests. (Dominique Pelle, closes vim/vim#4296)
d1f90bbcab
This commit is contained in:
parent
ff104e197d
commit
41cfdba22b
@ -398,3 +398,143 @@ func Test_addr_all()
|
|||||||
|
|
||||||
delcommand DoSomething
|
delcommand DoSomething
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_command_list()
|
||||||
|
command! DoCmd :
|
||||||
|
call assert_equal("\n Name Args Address Complete Definition"
|
||||||
|
\ .. "\n DoCmd 0 :",
|
||||||
|
\ execute('command DoCmd'))
|
||||||
|
|
||||||
|
" Test with various -range= and -count= argument values.
|
||||||
|
command! -range DoCmd :
|
||||||
|
call assert_equal("\n Name Args Address Complete Definition"
|
||||||
|
\ .. "\n DoCmd 0 . :",
|
||||||
|
\ execute('command DoCmd'))
|
||||||
|
command! -range=% DoCmd :
|
||||||
|
call assert_equal("\n Name Args Address Complete Definition"
|
||||||
|
\ .. "\n DoCmd 0 % :",
|
||||||
|
\ execute('command! DoCmd'))
|
||||||
|
command! -range=2 DoCmd :
|
||||||
|
call assert_equal("\n Name Args Address Complete Definition"
|
||||||
|
\ .. "\n DoCmd 0 2 :",
|
||||||
|
\ execute('command DoCmd'))
|
||||||
|
command! -count=2 DoCmd :
|
||||||
|
call assert_equal("\n Name Args Address Complete Definition"
|
||||||
|
\ .. "\n DoCmd 0 2c :",
|
||||||
|
\ execute('command DoCmd'))
|
||||||
|
|
||||||
|
" Test with various -addr= argument values.
|
||||||
|
command! -addr=lines DoCmd :
|
||||||
|
call assert_equal("\n Name Args Address Complete Definition"
|
||||||
|
\ .. "\n DoCmd 0 . :",
|
||||||
|
\ execute('command DoCmd'))
|
||||||
|
command! -addr=arguments DoCmd :
|
||||||
|
call assert_equal("\n Name Args Address Complete Definition"
|
||||||
|
\ .. "\n DoCmd 0 . arg :",
|
||||||
|
\ execute('command DoCmd'))
|
||||||
|
command! -addr=buffers DoCmd :
|
||||||
|
call assert_equal("\n Name Args Address Complete Definition"
|
||||||
|
\ .. "\n DoCmd 0 . buf :",
|
||||||
|
\ execute('command DoCmd'))
|
||||||
|
command! -addr=loaded_buffers DoCmd :
|
||||||
|
call assert_equal("\n Name Args Address Complete Definition"
|
||||||
|
\ .. "\n DoCmd 0 . load :",
|
||||||
|
\ execute('command DoCmd'))
|
||||||
|
command! -addr=windows DoCmd :
|
||||||
|
call assert_equal("\n Name Args Address Complete Definition"
|
||||||
|
\ .. "\n DoCmd 0 . win :",
|
||||||
|
\ execute('command DoCmd'))
|
||||||
|
command! -addr=tabs DoCmd :
|
||||||
|
call assert_equal("\n Name Args Address Complete Definition"
|
||||||
|
\ .. "\n DoCmd 0 . tab :",
|
||||||
|
\ execute('command DoCmd'))
|
||||||
|
command! -addr=other DoCmd :
|
||||||
|
call assert_equal("\n Name Args Address Complete Definition"
|
||||||
|
\ .. "\n DoCmd 0 . ? :",
|
||||||
|
\ execute('command DoCmd'))
|
||||||
|
|
||||||
|
" Test with various -complete= argument values (non-exhaustive list)
|
||||||
|
command! -complete=arglist DoCmd :
|
||||||
|
call assert_equal("\n Name Args Address Complete Definition"
|
||||||
|
\ .. "\n DoCmd 0 arglist :",
|
||||||
|
\ execute('command DoCmd'))
|
||||||
|
command! -complete=augroup DoCmd :
|
||||||
|
call assert_equal("\n Name Args Address Complete Definition"
|
||||||
|
\ .. "\n DoCmd 0 augroup :",
|
||||||
|
\ execute('command DoCmd'))
|
||||||
|
command! -complete=custom,CustomComplete DoCmd :
|
||||||
|
call assert_equal("\n Name Args Address Complete Definition"
|
||||||
|
\ .. "\n DoCmd 0 custom :",
|
||||||
|
\ execute('command DoCmd'))
|
||||||
|
command! -complete=customlist,CustomComplete DoCmd :
|
||||||
|
call assert_equal("\n Name Args Address Complete Definition"
|
||||||
|
\ .. "\n DoCmd 0 customlist :",
|
||||||
|
\ execute('command DoCmd'))
|
||||||
|
|
||||||
|
" Test with various -narg= argument values.
|
||||||
|
command! -nargs=0 DoCmd :
|
||||||
|
call assert_equal("\n Name Args Address Complete Definition"
|
||||||
|
\ .. "\n DoCmd 0 :",
|
||||||
|
\ execute('command DoCmd'))
|
||||||
|
command! -nargs=1 DoCmd :
|
||||||
|
call assert_equal("\n Name Args Address Complete Definition"
|
||||||
|
\ .. "\n DoCmd 1 :",
|
||||||
|
\ execute('command DoCmd'))
|
||||||
|
command! -nargs=* DoCmd :
|
||||||
|
call assert_equal("\n Name Args Address Complete Definition"
|
||||||
|
\ .. "\n DoCmd * :",
|
||||||
|
\ execute('command DoCmd'))
|
||||||
|
command! -nargs=? DoCmd :
|
||||||
|
call assert_equal("\n Name Args Address Complete Definition"
|
||||||
|
\ .. "\n DoCmd ? :",
|
||||||
|
\ execute('command DoCmd'))
|
||||||
|
command! -nargs=+ DoCmd :
|
||||||
|
call assert_equal("\n Name Args Address Complete Definition"
|
||||||
|
\ .. "\n DoCmd + :",
|
||||||
|
\ execute('command DoCmd'))
|
||||||
|
|
||||||
|
" Test with other arguments.
|
||||||
|
command! -bang DoCmd :
|
||||||
|
call assert_equal("\n Name Args Address Complete Definition"
|
||||||
|
\ .. "\n! DoCmd 0 :",
|
||||||
|
\ execute('command DoCmd'))
|
||||||
|
command! -bar DoCmd :
|
||||||
|
call assert_equal("\n Name Args Address Complete Definition"
|
||||||
|
\ .. "\n| DoCmd 0 :",
|
||||||
|
\ execute('command DoCmd'))
|
||||||
|
command! -register DoCmd :
|
||||||
|
call assert_equal("\n Name Args Address Complete Definition"
|
||||||
|
\ .. "\n\" DoCmd 0 :",
|
||||||
|
\ execute('command DoCmd'))
|
||||||
|
command! -buffer DoCmd :
|
||||||
|
call assert_equal("\n Name Args Address Complete Definition"
|
||||||
|
\ .. "\nb DoCmd 0 :"
|
||||||
|
\ .. "\n\" DoCmd 0 :",
|
||||||
|
\ execute('command DoCmd'))
|
||||||
|
comclear
|
||||||
|
|
||||||
|
" Test with many args.
|
||||||
|
command! -bang -bar -register -buffer -nargs=+ -complete=environment -addr=windows -count=3 DoCmd :
|
||||||
|
call assert_equal("\n Name Args Address Complete Definition"
|
||||||
|
\ .. "\n!\"b|DoCmd + 3c win environment :",
|
||||||
|
\ execute('command DoCmd'))
|
||||||
|
comclear
|
||||||
|
|
||||||
|
" Test with special characters in command definition.
|
||||||
|
command! DoCmd :<cr><tab><c-d>
|
||||||
|
call assert_equal("\n Name Args Address Complete Definition"
|
||||||
|
\ .. "\n DoCmd 0 :<CR><Tab><C-D>",
|
||||||
|
\ execute('command DoCmd'))
|
||||||
|
|
||||||
|
" Test output in verbose mode.
|
||||||
|
command! DoCmd :
|
||||||
|
call assert_match("^\n"
|
||||||
|
\ .. " Name Args Address Complete Definition\n"
|
||||||
|
\ .. " DoCmd 0 :\n"
|
||||||
|
\ .. "\tLast set from .*/test_usercommands.vim line \\d\\+$",
|
||||||
|
\ execute('verbose command DoCmd'))
|
||||||
|
|
||||||
|
comclear
|
||||||
|
call assert_equal("\nNo user-defined commands found", execute(':command Xxx'))
|
||||||
|
call assert_equal("\nNo user-defined commands found", execute('command'))
|
||||||
|
endfunc
|
||||||
|
Loading…
Reference in New Issue
Block a user