comparison src/testdir/test_usercommands.vim @ 16403:250420b35b10 v8.1.1206

patch 8.1.1206: user command parsing and listing not properly tested commit https://github.com/vim/vim/commit/d1f90bbcab0ad934d3f48a717a916807b57269ab Author: Bram Moolenaar <Bram@vim.org> Date: Thu Apr 25 22:42:07 2019 +0200 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 https://github.com/vim/vim/issues/4296)
author Bram Moolenaar <Bram@vim.org>
date Thu, 25 Apr 2019 22:45:05 +0200
parents b101b193d5ff
children 4734d601ebdd
comparison
equal deleted inserted replaced
16402:3c96b3ebc76d 16403:250420b35b10
302 DoSomething 302 DoSomething
303 call assert_fails('%DoSomething') 303 call assert_fails('%DoSomething')
304 304
305 delcommand DoSomething 305 delcommand DoSomething
306 endfunc 306 endfunc
307
308 func Test_command_list()
309 command! DoCmd :
310 call assert_equal("\n Name Args Address Complete Definition"
311 \ .. "\n DoCmd 0 :",
312 \ execute('command DoCmd'))
313
314 " Test with various -range= and -count= argument values.
315 command! -range DoCmd :
316 call assert_equal("\n Name Args Address Complete Definition"
317 \ .. "\n DoCmd 0 . :",
318 \ execute('command DoCmd'))
319 command! -range=% DoCmd :
320 call assert_equal("\n Name Args Address Complete Definition"
321 \ .. "\n DoCmd 0 % :",
322 \ execute('command! DoCmd'))
323 command! -range=2 DoCmd :
324 call assert_equal("\n Name Args Address Complete Definition"
325 \ .. "\n DoCmd 0 2 :",
326 \ execute('command DoCmd'))
327 command! -count=2 DoCmd :
328 call assert_equal("\n Name Args Address Complete Definition"
329 \ .. "\n DoCmd 0 2c :",
330 \ execute('command DoCmd'))
331
332 " Test with various -addr= argument values.
333 command! -addr=lines DoCmd :
334 call assert_equal("\n Name Args Address Complete Definition"
335 \ .. "\n DoCmd 0 . :",
336 \ execute('command DoCmd'))
337 command! -addr=arguments DoCmd :
338 call assert_equal("\n Name Args Address Complete Definition"
339 \ .. "\n DoCmd 0 . arg :",
340 \ execute('command DoCmd'))
341 command! -addr=buffers DoCmd :
342 call assert_equal("\n Name Args Address Complete Definition"
343 \ .. "\n DoCmd 0 . buf :",
344 \ execute('command DoCmd'))
345 command! -addr=loaded_buffers DoCmd :
346 call assert_equal("\n Name Args Address Complete Definition"
347 \ .. "\n DoCmd 0 . load :",
348 \ execute('command DoCmd'))
349 command! -addr=windows DoCmd :
350 call assert_equal("\n Name Args Address Complete Definition"
351 \ .. "\n DoCmd 0 . win :",
352 \ execute('command DoCmd'))
353 command! -addr=tabs DoCmd :
354 call assert_equal("\n Name Args Address Complete Definition"
355 \ .. "\n DoCmd 0 . tab :",
356 \ execute('command DoCmd'))
357 command! -addr=other DoCmd :
358 call assert_equal("\n Name Args Address Complete Definition"
359 \ .. "\n DoCmd 0 . ? :",
360 \ execute('command DoCmd'))
361
362 " Test with various -complete= argument values (non-exhaustive list)
363 command! -complete=arglist DoCmd :
364 call assert_equal("\n Name Args Address Complete Definition"
365 \ .. "\n DoCmd 0 arglist :",
366 \ execute('command DoCmd'))
367 command! -complete=augroup DoCmd :
368 call assert_equal("\n Name Args Address Complete Definition"
369 \ .. "\n DoCmd 0 augroup :",
370 \ execute('command DoCmd'))
371 command! -complete=custom,CustomComplete DoCmd :
372 call assert_equal("\n Name Args Address Complete Definition"
373 \ .. "\n DoCmd 0 custom :",
374 \ execute('command DoCmd'))
375 command! -complete=customlist,CustomComplete DoCmd :
376 call assert_equal("\n Name Args Address Complete Definition"
377 \ .. "\n DoCmd 0 customlist :",
378 \ execute('command DoCmd'))
379
380 " Test with various -narg= argument values.
381 command! -nargs=0 DoCmd :
382 call assert_equal("\n Name Args Address Complete Definition"
383 \ .. "\n DoCmd 0 :",
384 \ execute('command DoCmd'))
385 command! -nargs=1 DoCmd :
386 call assert_equal("\n Name Args Address Complete Definition"
387 \ .. "\n DoCmd 1 :",
388 \ execute('command DoCmd'))
389 command! -nargs=* DoCmd :
390 call assert_equal("\n Name Args Address Complete Definition"
391 \ .. "\n DoCmd * :",
392 \ execute('command DoCmd'))
393 command! -nargs=? DoCmd :
394 call assert_equal("\n Name Args Address Complete Definition"
395 \ .. "\n DoCmd ? :",
396 \ execute('command DoCmd'))
397 command! -nargs=+ DoCmd :
398 call assert_equal("\n Name Args Address Complete Definition"
399 \ .. "\n DoCmd + :",
400 \ execute('command DoCmd'))
401
402 " Test with other arguments.
403 command! -bang DoCmd :
404 call assert_equal("\n Name Args Address Complete Definition"
405 \ .. "\n! DoCmd 0 :",
406 \ execute('command DoCmd'))
407 command! -bar DoCmd :
408 call assert_equal("\n Name Args Address Complete Definition"
409 \ .. "\n| DoCmd 0 :",
410 \ execute('command DoCmd'))
411 command! -register DoCmd :
412 call assert_equal("\n Name Args Address Complete Definition"
413 \ .. "\n\" DoCmd 0 :",
414 \ execute('command DoCmd'))
415 command! -buffer DoCmd :
416 call assert_equal("\n Name Args Address Complete Definition"
417 \ .. "\nb DoCmd 0 :"
418 \ .. "\n\" DoCmd 0 :",
419 \ execute('command DoCmd'))
420 comclear
421
422 " Test with many args.
423 command! -bang -bar -register -buffer -nargs=+ -complete=environment -addr=windows -count=3 DoCmd :
424 call assert_equal("\n Name Args Address Complete Definition"
425 \ .. "\n!\"b|DoCmd + 3c win environment :",
426 \ execute('command DoCmd'))
427 comclear
428
429 " Test with special characters in command definition.
430 command! DoCmd :<cr><tab><c-d>
431 call assert_equal("\n Name Args Address Complete Definition"
432 \ .. "\n DoCmd 0 :<CR><Tab><C-D>",
433 \ execute('command DoCmd'))
434
435 " Test output in verbose mode.
436 command! DoCmd :
437 call assert_match("^\n"
438 \ .. " Name Args Address Complete Definition\n"
439 \ .. " DoCmd 0 :\n"
440 \ .. "\tLast set from .*/test_usercommands.vim line \\d\\+$",
441 \ execute('verbose command DoCmd'))
442
443 comclear
444 call assert_equal("\nNo user-defined commands found", execute(':command Xxx'))
445 call assert_equal("\nNo user-defined commands found", execute('command'))
446 endfunc