]> granicus.if.org Git - vim/commitdiff
patch 8.2.0212: missing search/substitute pattern hardly tested v8.2.0212
authorBram Moolenaar <Bram@vim.org>
Wed, 5 Feb 2020 19:38:22 +0000 (20:38 +0100)
committerBram Moolenaar <Bram@vim.org>
Wed, 5 Feb 2020 19:38:22 +0000 (20:38 +0100)
Problem:    Missing search/substitute pattern hardly tested.
Solution:   Add test_clear_search_pat() and tests. (Yegappan Lakshmanan,
            closes #5579)

15 files changed:
runtime/doc/eval.txt
runtime/doc/testing.txt
runtime/doc/usr_41.txt
src/evalfunc.c
src/proto/regexp.pro
src/proto/search.pro
src/proto/testing.pro
src/regexp.c
src/search.c
src/testdir/test_quickfix.vim
src/testdir/test_search.vim
src/testdir/test_sort.vim
src/testdir/test_substitute.vim
src/testing.c
src/version.c

index 1d282d286b84f963ce94a81833c74fd5b1905ed2..26e7d12de4a64f91eb85b136cffb501233e9e458 100644 (file)
@@ -2848,6 +2848,7 @@ term_wait({buf} [, {time}])       Number  wait for screen to be updated
 test_alloc_fail({id}, {countdown}, {repeat})
                                none    make memory allocation fail
 test_autochdir()               none    enable 'autochdir' during startup
+test_clear_search_pat()                none    clears the last used search pattern
 test_feedinput({string})       none    add key sequence to input buffer
 test_garbagecollect_now()      none    free memory right now for testing
 test_garbagecollect_soon()     none    free memory soon for testing
index c5fa2e83ccdd964a3677d57cecb2dd9e776f83ba..7fb24e63079f034f6599ef0b581869661c358c6a 100644 (file)
@@ -52,6 +52,11 @@ test_autochdir()                                     *test_autochdir()*
                startup has finished.
 
 
+test_clear_search_pat()                                *test_clear_search_pat()*
+               Clears the last used search pattern (|/|) and the substitute
+               pattern (|:s|). This is useful for testing conditions where
+               these patterns are not set previously.
+
 test_feedinput({string})                               *test_feedinput()*
                Characters in {string} are queued for processing as if they
                were typed by the user. This uses a low level input buffer.
index 1bed01f418e87a4cc762ed6c62cf18a41173144c..316eebcaea05312d9368b44d3a1b4b81b0a6df96 100644 (file)
@@ -963,6 +963,7 @@ Testing:                                *test-functions*
        assert_report()         report a test failure
        test_alloc_fail()       make memory allocation fail
        test_autochdir()        enable 'autochdir' during startup
+       test_clear_search_pat() clears the last used search pattern
        test_override()         test with Vim internal overrides
        test_garbagecollect_now()   free memory right now
        test_getvalue()         get value of an internal variable
index a79cc8932998177502358b9312c10fa94e62b24d..aac8ee9058e5fb76dbafd72ad0a335e3c183605a 100644 (file)
@@ -810,6 +810,7 @@ static funcentry_T global_functions[] =
 #endif
     {"test_alloc_fail",        3, 3, FEARG_1,    &t_void,      f_test_alloc_fail},
     {"test_autochdir", 0, 0, 0,          &t_void,      f_test_autochdir},
+    {"test_clear_search_pat",  0, 0, 0,  &t_void,      f_test_clear_search_pat},
     {"test_feedinput", 1, 1, FEARG_1,    &t_void,      f_test_feedinput},
     {"test_garbagecollect_now",        0, 0, 0,  &t_void,      f_test_garbagecollect_now},
     {"test_garbagecollect_soon", 0, 0, 0, &t_void,     f_test_garbagecollect_soon},
index 01f1fff0d7e8430182e2f94350c672b58f9d50ee..5e8e1a58a628cb87b89adea02ba181bd2fcdefa7 100644 (file)
@@ -12,6 +12,7 @@ int vim_regcomp_had_eol(void);
 regprog_T *vim_regcomp(char_u *expr_arg, int re_flags);
 void vim_regfree(regprog_T *prog);
 void free_regexp_stuff(void);
+void free_regexp_prev_sub(void);
 int regprog_in_use(regprog_T *prog);
 int vim_regexec_prog(regprog_T **prog, int ignore_case, char_u *line, colnr_T col);
 int vim_regexec(regmatch_T *rmp, char_u *line, colnr_T col);
index e6ac11b2cb2e549fe6736905d08e1a1b2a7a9168..3b46c0662cd36c4c9ff573119c7d0926db91518a 100644 (file)
@@ -9,6 +9,7 @@ void free_search_patterns(void);
 void save_last_search_pattern(void);
 void restore_last_search_pattern(void);
 char_u *last_search_pattern(void);
+void free_last_pat(int idx);
 int ignorecase(char_u *pat);
 int ignorecase_opt(char_u *pat, int ic_in, int scs);
 int pat_has_uppercase(char_u *pat);
index 2b001a543a6abeb2848e1dfc965da12685960f96..209abf3486176ad907ec1bd7befa5042b308a564 100644 (file)
@@ -13,6 +13,7 @@ void f_assert_report(typval_T *argvars, typval_T *rettv);
 void f_assert_true(typval_T *argvars, typval_T *rettv);
 void f_test_alloc_fail(typval_T *argvars, typval_T *rettv);
 void f_test_autochdir(typval_T *argvars, typval_T *rettv);
+void f_test_clear_search_pat(typval_T *argvars, typval_T *rettv);
 void f_test_feedinput(typval_T *argvars, typval_T *rettv);
 void f_test_getvalue(typval_T *argvars, typval_T *rettv);
 void f_test_option_not_set(typval_T *argvars, typval_T *rettv);
index ef3896c0a4d7a97ae35bfd29454196345da617d4..7aeddb83cd5f06e7f1cbc2d2500e6dea5a423b92 100644 (file)
@@ -2663,6 +2663,15 @@ free_regexp_stuff(void)
 }
 #endif
 
+/*
+ * Free the previously used substitute search pattern.
+ */
+    void
+free_regexp_prev_sub(void)
+{
+    VIM_CLEAR(reg_prev_sub);
+}
+
 #ifdef FEAT_EVAL
     static void
 report_re_switch(char_u *pat)
index 3b310dc2a96b097e9ffc64e0964a0835dad4a9d6..08915578fc0efc8b9aaff832de3773dca9e947b2 100644 (file)
@@ -380,6 +380,12 @@ last_search_pattern(void)
 }
 #endif
 
+    void
+free_last_pat(int idx)
+{
+    VIM_CLEAR(spats[idx].pat);
+}
+
 /*
  * Return TRUE when case should be ignored for search pattern "pat".
  * Uses the 'ignorecase' and 'smartcase' options.
index 129b1cfccb2a5cc6111bccaaf2a16b81cfd49349..79ad82d2d6fcd9adf20ee987f636db574d888319 100644 (file)
@@ -2718,6 +2718,10 @@ func XvimgrepTests(cchar)
   call assert_equal(0, getbufinfo('Xtestfile1')[0].loaded)
   call assert_equal([], getbufinfo('Xtestfile2'))
 
+  " Test with the last search pattern not set
+  call test_clear_search_pat()
+  call assert_fails('Xvimgrep // *', 'E35:')
+
   call delete('Xtestfile1')
   call delete('Xtestfile2')
 endfunc
index 89ca6e1314c8e53c2adb02344f92452f110f7c47..69d007354ee5c32dfc0fe14d54da273b3e51f445 100644 (file)
@@ -1455,3 +1455,44 @@ func Test_search_special()
   set t_PE=
   exe "norm /\x80PS"
 endfunc
+
+" Test for command failures when the last search pattern is not set.
+func Test_search_with_no_last_pat()
+  call test_clear_search_pat()
+  call assert_fails("normal i\<C-R>/\e", 'E35:')
+  call assert_fails("exe '/'", 'E35:')
+  call assert_fails("exe '?'", 'E35:')
+  call assert_fails("/", 'E35:')
+  call assert_fails("?", 'E35:')
+  call assert_fails("normal n", 'E35:')
+  call assert_fails("normal N", 'E35:')
+  call assert_fails("normal gn", 'E35:')
+  call assert_fails("normal gN", 'E35:')
+  call assert_fails("normal cgn", 'E35:')
+  call assert_fails("normal cgN", 'E35:')
+  let p = []
+  let p = @/
+  call assert_equal('', p)
+  call assert_fails("normal :\<C-R>/", 'E35:')
+  call assert_fails("//p", 'E35:')
+  call assert_fails(";//p", 'E35:')
+  call assert_fails("??p", 'E35:')
+  call assert_fails(";??p", 'E35:')
+  call assert_fails('g//p', 'E476:')
+  call assert_fails('v//p', 'E476:')
+endfunc
+
+" Test for using tilde (~) atom in search. This should use the last used
+" substitute pattern
+func Test_search_tilde_pat()
+  call test_clear_search_pat()
+  set regexpengine=1
+  call assert_fails('exe "normal /~\<CR>"', 'E33:')
+  call assert_fails('exe "normal ?~\<CR>"', 'E33:')
+  set regexpengine=2
+  call assert_fails('exe "normal /~\<CR>"', 'E383:')
+  call assert_fails('exe "normal ?~\<CR>"', 'E383:')
+  set regexpengine&
+endfunc
+
+" vim: shiftwidth=2 sts=2 expandtab
index b7c68f072f1365919c6dcc66a0ce4b35aaa9f66f..f6ad87af187ad7b5f51eaca8ce53964930ea2040 100644 (file)
@@ -1383,6 +1383,8 @@ func Test_sort_last_search_pat()
   call setline(1, ['3b', '1c', '2a'])
   sort //
   call assert_equal(['2a', '3b', '1c'], getline(1, '$'))
+  call test_clear_search_pat()
+  call assert_fails('sort //', 'E35:')
   close!
 endfunc
 
index 4db7b3ea4cca0059bf069493bdd78062a906ab62..acc59cf5649c964877b0aec59ba2a43bcfc05941 100644 (file)
@@ -803,4 +803,19 @@ func Test_sub_expand_text()
   close!
 endfunc
 
+" Test for command failures when the last substitute pattern is not set.
+func Test_sub_with_no_last_pat()
+  call test_clear_search_pat()
+  call assert_fails('~', 'E33:')
+  call assert_fails('s//abc/g', 'E476:')
+  call assert_fails('s\/bar', 'E476:')
+  call assert_fails('s\&bar&', 'E476:')
+
+  call test_clear_search_pat()
+  let save_cpo = &cpo
+  set cpo+=/
+  call assert_fails('s/abc/%/', 'E33:')
+  let &cpo = save_cpo
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 5dacf073b344525fe782b75836a0bfcae128a938..c2b382b8b6da0e31466085febfbb052b2325a28c 100644 (file)
@@ -631,6 +631,19 @@ f_test_autochdir(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
 #endif
 }
 
+/*
+ * "test_clear_search_pat()"
+ * Free the last search and substitute patterns
+ */
+    void
+f_test_clear_search_pat(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
+{
+    free_last_pat(RE_SUBST);
+    free_last_pat(RE_SEARCH);
+    set_old_sub(NULL);
+    free_regexp_prev_sub();
+}
+
 /*
  * "test_feedinput()"
  */
index a482b034a603e25235d0a30e2a1bb7630b2d725e..af6ecdfda9cf05b9405ad55fb8327f6b596433bc 100644 (file)
@@ -742,6 +742,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    212,
 /**/
     211,
 /**/