]> granicus.if.org Git - vim/commitdiff
patch 8.2.2694: when 'matchpairs' is empty every character beeps v8.2.2694
authorBram Moolenaar <Bram@vim.org>
Fri, 2 Apr 2021 16:55:57 +0000 (18:55 +0200)
committerBram Moolenaar <Bram@vim.org>
Fri, 2 Apr 2021 16:55:57 +0000 (18:55 +0200)
Problem:    When 'matchpairs' is empty every character beeps. (Marco Hinz)
Solution:   Bail out when no character in 'matchpairs' was found.
            (closes #8053)  Add assert_nobeep().

runtime/doc/eval.txt
runtime/doc/testing.txt
src/evalfunc.c
src/proto/testing.pro
src/search.c
src/testdir/test_textformat.vim
src/testing.c
src/version.c

index 57ab47e0ce678942a9b32ad68979a752b133ee42..97c968c748a6eef58b469ce9fa9f950ca67b5db4 100644 (file)
@@ -2440,6 +2440,7 @@ assert_inrange({lower}, {upper}, {actual} [, {msg}])
                                Number  assert {actual} is inside the range
 assert_match({pat}, {text} [, {msg}])
                                Number  assert {pat} matches {text}
+assert_nobeep({cmd})           Number  assert {cmd} does not cause a beep
 assert_notequal({exp}, {act} [, {msg}])
                                Number  assert {exp} is not equal {act}
 assert_notmatch({pat}, {text} [, {msg}])
index 4e4cff0c27ca40c7353e1ea110913516f3955780..5d85358d71595341b1b8bb34c45f348b7181c6dd 100644 (file)
@@ -243,7 +243,8 @@ test_srand_seed([seed])                                     *test_srand_seed()*
 assert_beeps({cmd})                                    *assert_beeps()*
                Run {cmd} and add an error message to |v:errors| if it does
                NOT produce a beep or visual bell.
-               Also see |assert_fails()| and |assert-return|.
+               Also see |assert_fails()|, |assert_nobeep()| and
+               |assert-return|.
 
                Can also be used as a |method|: >
                        GetCmd()->assert_beeps()
@@ -376,6 +377,14 @@ assert_match({pattern}, {actual} [, {msg}])
 
                Can also be used as a |method|: >
                        getFile()->assert_match('foo.*')
+<
+assert_nobeep({cmd})                                   *assert_nobeep()*
+               Run {cmd} and add an error message to |v:errors| if it
+               produces a beep or visual bell.
+               Also see |assert_beeps()|.
+
+               Can also be used as a |method|: >
+                       GetCmd()->assert_nobeep()
 <
                                                        *assert_notequal()*
 assert_notequal({expected}, {actual} [, {msg}])
index f83559dbbe04845e20652157549ca899439d1bc1..5383d098f4a5528777ab33bae51be0065c596ff2 100644 (file)
@@ -739,6 +739,8 @@ static funcentry_T global_functions[] =
                        ret_number_bool,    f_assert_inrange},
     {"assert_match",   2, 3, FEARG_2,      NULL,
                        ret_number_bool,    f_assert_match},
+    {"assert_nobeep",  1, 2, FEARG_1,      NULL,
+                       ret_number_bool,    f_assert_nobeep},
     {"assert_notequal",        2, 3, FEARG_2,      NULL,
                        ret_number_bool,    f_assert_notequal},
     {"assert_notmatch",        2, 3, FEARG_2,      NULL,
index b812c2a270ef21f0351a704fba92e3bd17623883..d229030cb503bff14d8cd01dcc7a01df0ee6690a 100644 (file)
@@ -1,5 +1,6 @@
 /* testing.c */
 void f_assert_beeps(typval_T *argvars, typval_T *rettv);
+void f_assert_nobeep(typval_T *argvars, typval_T *rettv);
 void f_assert_equal(typval_T *argvars, typval_T *rettv);
 void f_assert_equalfile(typval_T *argvars, typval_T *rettv);
 void f_assert_notequal(typval_T *argvars, typval_T *rettv);
index d8c21f43c739cc7232b49b968f9ef690139a733d..37ccc37e9c0436abb5d5920b6f1254979b1e3613 100644 (file)
@@ -2817,6 +2817,8 @@ showmatch(
        if (*p == NUL)
            return;
     }
+    if (*p == NUL)
+       return;
 
     if ((lpos = findmatch(NULL, NUL)) == NULL)     // no match, so beep
        vim_beep(BO_MATCH);
index 32ff3cc70b1ed979ae3288db58622a18a55c1383..0dc28c7307fa2690f424a3e1c2a4f88d951f1afd 100644 (file)
@@ -858,6 +858,14 @@ func Test_mps_latin1()
   close!
 endfunc
 
+func Test_empty_matchpairs()
+  split
+  set matchpairs= showmatch
+  call assert_nobeep('call feedkeys("ax\tx\t\<Esc>", "xt")')
+  set matchpairs& noshowmatch
+  bwipe!
+endfunc
+
 func Test_mps_error()
   let encoding_save = &encoding
 
index df19b9eb491a45c962d1bd61474f8244510fdea3..740923735c0d60bfb170fb2e66d457653707b1fd 100644 (file)
@@ -338,7 +338,7 @@ assert_append_cmd_or_arg(garray_T *gap, typval_T *argvars, char_u *cmd)
 }
 
     static int
-assert_beeps(typval_T *argvars)
+assert_beeps(typval_T *argvars, int no_beep)
 {
     char_u     *cmd = tv_get_string_chk(&argvars[0]);
     garray_T   ga;
@@ -348,10 +348,13 @@ assert_beeps(typval_T *argvars)
     suppress_errthrow = TRUE;
     emsg_silent = FALSE;
     do_cmdline_cmd(cmd);
-    if (!called_vim_beep)
+    if (no_beep ? called_vim_beep : !called_vim_beep)
     {
        prepare_assert_error(&ga);
-       ga_concat(&ga, (char_u *)"command did not beep: ");
+       if (no_beep)
+           ga_concat(&ga, (char_u *)"command did beep: ");
+       else
+           ga_concat(&ga, (char_u *)"command did not beep: ");
        ga_concat(&ga, cmd);
        assert_error(&ga);
        ga_clear(&ga);
@@ -369,7 +372,16 @@ assert_beeps(typval_T *argvars)
     void
 f_assert_beeps(typval_T *argvars, typval_T *rettv)
 {
-    rettv->vval.v_number = assert_beeps(argvars);
+    rettv->vval.v_number = assert_beeps(argvars, FALSE);
+}
+
+/*
+ * "assert_nobeep(cmd [, error])" function
+ */
+    void
+f_assert_nobeep(typval_T *argvars, typval_T *rettv)
+{
+    rettv->vval.v_number = assert_beeps(argvars, TRUE);
 }
 
 /*
index 760a0f48eb81f839df659a1de1d8b67259dba8aa..661a93cd8d60058804aceeabbd7add211e914eb5 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2694,
 /**/
     2693,
 /**/