From 9e5f9c25d9955f8c0ab7de874cf3a40fc077458b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 17 Apr 2023 23:27:04 +0800 Subject: [PATCH] vim-patch:9.0.1460: insufficient testing for getcmdcompltype() (#23159) Problem: Insufficient testing for getcmdcompltype(). Solution: Add a few more test cases. (closes vim/vim#12268) https://github.com/vim/vim/commit/961b2e54bdbe1c06e4bf8ccf7a7e3deb129b45de --- src/nvim/ex_getln.c | 4 ++++ test/old/testdir/test_cmdline.vim | 21 ++++++++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index f3afbdcaaf..97343e468b 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -4096,6 +4096,10 @@ static char *get_cmdline_completion(void) } set_expand_context(p->xpc); + if (p->xpc->xp_context == EXPAND_UNSUCCESSFUL) { + return NULL; + } + char *cmd_compl = get_user_cmd_complete(p->xpc, p->xpc->xp_context); if (cmd_compl != NULL) { return xstrdup(cmd_compl); diff --git a/test/old/testdir/test_cmdline.vim b/test/old/testdir/test_cmdline.vim index 74dd7bf3c4..0c6464ae80 100644 --- a/test/old/testdir/test_cmdline.vim +++ b/test/old/testdir/test_cmdline.vim @@ -3476,16 +3476,23 @@ func Test_cmdline_complete_bang_cmd_argument() call assert_equal('"!vim test_cmdline.vim', @:) endfunc -func Check_completion() - call assert_equal('let a', getcmdline()) - call assert_equal(6, getcmdpos()) - call assert_equal(7, getcmdscreenpos()) - call assert_equal('var', getcmdcompltype()) - return '' +func Call_cmd_funcs() + return string([getcmdpos(), getcmdscreenpos(), getcmdcompltype()]) endfunc func Test_screenpos_and_completion() - call feedkeys(":let a\=Check_completion()\\", "xt") + call assert_equal(0, getcmdpos()) + call assert_equal(0, getcmdscreenpos()) + call assert_equal('', getcmdcompltype()) + + cnoremap string([getcmdpos(), getcmdscreenpos(), getcmdcompltype()]) + call feedkeys(":let a\\\"\", "xt") + call assert_equal("\"let a[6, 7, 'var']", @:) + call feedkeys(":quit \\\"\", "xt") + call assert_equal("\"quit [6, 7, '']", @:) + call feedkeys(":nosuchcommand \\\"\", "xt") + call assert_equal("\"nosuchcommand [15, 16, '']", @:) + cunmap endfunc func Test_recursive_register()