]> granicus.if.org Git - vim/commitdiff
patch 8.2.5049: insufficient tests for autocommands v8.2.5049
authorYegappan Lakshmanan <yegappan@yahoo.com>
Wed, 1 Jun 2022 11:31:53 +0000 (12:31 +0100)
committerBram Moolenaar <Bram@vim.org>
Wed, 1 Jun 2022 11:31:53 +0000 (12:31 +0100)
Problem:    Insufficient tests for autocommands.
Solution:   Add a few more tests. (Yegappan Lakshmanan, closes #10507)

src/autocmd.c
src/testdir/gen_opt_test.vim
src/testdir/test_autocmd.vim
src/testdir/test_cmdline.vim
src/version.c

index 143891c9b89115df464e9b98edff899af6422b26..2050da6640310b0c936010eae387404af0065c55 100644 (file)
@@ -3161,33 +3161,23 @@ f_autocmd_get(typval_T *argvars, typval_T *rettv)
            for (ac = ap->cmds; ac != NULL; ac = ac->next)
            {
                event_dict = dict_alloc();
-               if (event_dict == NULL)
+               if (event_dict == NULL
+                       || list_append_dict(event_list, event_dict) == FAIL)
                    return;
 
-               if (list_append_dict(event_list, event_dict) == FAIL)
-                   return;
-
-               if (dict_add_string(event_dict, "event", event_name) == FAIL)
-                   return;
-
-               if (dict_add_string(event_dict, "group", group_name == NULL
-                           ? (char_u *)"" : group_name) == FAIL)
-                   return;
-
-               if (ap->buflocal_nr != 0)
-                   if (dict_add_number(event_dict, "bufnr", ap->buflocal_nr)
-                                                                      == FAIL)
-                       return;
-
-               if (dict_add_string(event_dict, "pattern", ap->pat) == FAIL)
-                   return;
-
-               if (dict_add_string(event_dict, "cmd", ac->cmd) == FAIL)
-                   return;
-
-               if (dict_add_bool(event_dict, "once", ac->once) == FAIL)
-                   return;
-               if (dict_add_bool(event_dict, "nested", ac->nested) == FAIL)
+               if (dict_add_string(event_dict, "event", event_name) == FAIL
+                       || dict_add_string(event_dict, "group",
+                                       group_name == NULL ? (char_u *)""
+                                                         : group_name) == FAIL
+                       || (ap->buflocal_nr != 0
+                               && (dict_add_number(event_dict, "bufnr",
+                                                   ap->buflocal_nr) == FAIL))
+                       || dict_add_string(event_dict, "pattern",
+                                                             ap->pat) == FAIL
+                       || dict_add_string(event_dict, "cmd", ac->cmd) == FAIL
+                       || dict_add_bool(event_dict, "once", ac->once) == FAIL
+                       || dict_add_bool(event_dict, "nested",
+                                                          ac->nested) == FAIL)
                    return;
            }
        }
index c37631c66c93df81973542005c28365838afdcc6..83f43f7b57f60a5b624de87eb5e362873d26083b 100644 (file)
@@ -90,7 +90,7 @@ let test_values = {
       \ 'display': [['', 'lastline', 'lastline,uhex'], ['xxx']],
       \ 'eadirection': [['', 'both', 'ver'], ['xxx', 'ver,hor']],
       \ 'encoding': [['latin1'], ['xxx', '']],
-      \ 'eventignore': [['', 'WinEnter', 'WinLeave,winenter'], ['xxx']],
+      \ 'eventignore': [['', 'WinEnter', 'WinLeave,winenter', 'all,WinEnter'], ['xxx']],
       \ 'fileencoding': [['', 'latin1', 'xxx'], []],
       \ 'fileformat': [['', 'dos', 'unix'], ['xxx']],
       \ 'fileformats': [['', 'dos', 'dos,unix'], ['xxx']],
index 0aaa968c88bf22f393831b5866584f972e1848b5..1a4ed1a624cbff7bf02e2143589de632e110c507 100644 (file)
@@ -3384,6 +3384,12 @@ func Test_autocmd_add()
   let l = [#{group: 'TestAcSet', event: 'BufAdd', bufnr: 9999,
         \ cmd: 'echo "bufadd"'}]
   call assert_fails("echo autocmd_add(l)", 'E680:')
+  let l = [#{group: 'TestAcSet', event: 'BufAdd', bufnr: 9999,
+        \ pattern: '*.py', cmd: 'echo "bufadd"'}]
+  call assert_fails("echo autocmd_add(l)", 'E680:')
+  let l = [#{group: 'TestAcSet', event: 'BufAdd', bufnr: 9999,
+        \ pattern: ['*.py', '*.c'], cmd: 'echo "bufadd"'}]
+  call assert_fails("echo autocmd_add(l)", 'E680:')
   let l = [#{group: 'TestAcSet', event: 'BufRead', bufnr: [],
         \ cmd: 'echo "bufread"'}]
   call assert_fails("echo autocmd_add(l)", 'E745:')
@@ -3479,6 +3485,7 @@ func Test_autocmd_add()
   " Test for invalid values for 'pattern' item
   let l = [#{group: 'TestAcSet', event: "BufEnter",
         \ pattern: test_null_string(), cmd: 'echo "bufcmds"'}]
+  call assert_fails('call autocmd_add(l)', 'E928:')
   let l = [#{group: 'TestAcSet', event: "BufEnter",
         \ pattern: test_null_list(), cmd: 'echo "bufcmds"'}]
   call assert_fails('call autocmd_add(l)', 'E714:')
@@ -3555,6 +3562,9 @@ func Test_autocmd_delete()
   " Delete a non-existing autocmd pattern
   let l = [#{group: 'TestAcSet', event: 'BufAdd', pat: 'abc'}]
   call assert_true(autocmd_delete(l))
+  " Delete an autocmd for a non-existing buffer
+  let l = [#{event: '*', bufnr: 9999, cmd: 'echo "x"'}]
+  call assert_fails('call autocmd_delete(l)', 'E680:')
 
   " Delete an autocmd group
   augroup TestAcSet
index cc7fe54d606734701c1506507d6ff96b5dcecbf2..77965b3f65a3a6414026a99a64b7e9a1351b5d5a 100644 (file)
@@ -1063,10 +1063,19 @@ func Test_cmdline_complete_various()
   augroup END
   call feedkeys(":augroup X\<C-A>\<C-B>\"\<CR>", 'xt')
   call assert_equal("\"augroup XTest.test", @:)
+
+  " group name completion in :autocmd
   call feedkeys(":au X\<C-A>\<C-B>\"\<CR>", 'xt')
   call assert_equal("\"au XTest.test", @:)
+  call feedkeys(":au XTest.test\<Tab>\<C-B>\"\<CR>", 'xt')
+  call assert_equal("\"au XTest.test", @:)
+
   augroup! XTest.test
 
+  " autocmd pattern completion
+  call feedkeys(":au BufEnter *.py\<Tab>\<C-B>\"\<CR>", 'xt')
+  call assert_equal("\"au BufEnter *.py\t", @:)
+
   " completion for the :unlet command
   call feedkeys(":unlet one two\<C-A>\<C-B>\"\<CR>", 'xt')
   call assert_equal("\"unlet one two", @:)
index ac335516b3e1024ddaad5b7d85d090ed096e8784..97ca8ce5cb40afa5f020edc3241d7db79a4f2ce1 100644 (file)
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    5049,
 /**/
     5048,
 /**/