Patch 8.2.0212
Problem:    Missing search/substitute pattern hardly tested.
Solution:   Add test_clear_search_pat() and tests. (Yegappan Lakshmanan,
            closes #5579)
Files:      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


*** ../vim-8.2.0211/runtime/doc/eval.txt        2020-01-26 15:52:33.011833294 
+0100
--- runtime/doc/eval.txt        2020-02-05 20:14:30.082087884 +0100
***************
*** 2846,2851 ****
--- 2848,2854 ----
  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
*** ../vim-8.2.0211/runtime/doc/testing.txt     2019-12-12 12:49:06.000000000 
+0100
--- runtime/doc/testing.txt     2020-02-05 20:14:30.082087884 +0100
***************
*** 52,57 ****
--- 52,62 ----
                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.
*** ../vim-8.2.0211/runtime/doc/usr_41.txt      2019-12-17 21:27:14.690319902 
+0100
--- runtime/doc/usr_41.txt      2020-02-05 20:14:30.082087884 +0100
***************
*** 963,968 ****
--- 963,969 ----
        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
*** ../vim-8.2.0211/src/evalfunc.c      2020-01-31 20:10:46.754021052 +0100
--- src/evalfunc.c      2020-02-05 20:14:30.086087866 +0100
***************
*** 810,815 ****
--- 810,816 ----
  #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},
*** ../vim-8.2.0211/src/proto/regexp.pro        2019-12-12 12:55:31.000000000 
+0100
--- src/proto/regexp.pro        2020-02-05 20:14:30.086087866 +0100
***************
*** 12,17 ****
--- 12,18 ----
  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);
*** ../vim-8.2.0211/src/proto/search.pro        2019-12-12 12:55:32.000000000 
+0100
--- src/proto/search.pro        2020-02-05 20:14:30.086087866 +0100
***************
*** 9,14 ****
--- 9,15 ----
  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);
*** ../vim-8.2.0211/src/proto/testing.pro       2019-12-12 12:55:35.000000000 
+0100
--- src/proto/testing.pro       2020-02-05 20:14:30.086087866 +0100
***************
*** 13,18 ****
--- 13,19 ----
  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);
*** ../vim-8.2.0211/src/regexp.c        2019-12-23 22:59:14.264820697 +0100
--- src/regexp.c        2020-02-05 20:14:30.086087866 +0100
***************
*** 2663,2668 ****
--- 2663,2677 ----
  }
  #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)
*** ../vim-8.2.0211/src/search.c        2019-12-23 22:59:14.264820697 +0100
--- src/search.c        2020-02-05 20:14:30.086087866 +0100
***************
*** 380,385 ****
--- 380,391 ----
  }
  #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.
*** ../vim-8.2.0211/src/testdir/test_quickfix.vim       2020-01-26 
21:59:25.632718110 +0100
--- src/testdir/test_quickfix.vim       2020-02-05 20:14:30.086087866 +0100
***************
*** 2718,2723 ****
--- 2718,2727 ----
    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
*** ../vim-8.2.0211/src/testdir/test_search.vim 2020-01-20 21:12:16.503205709 
+0100
--- src/testdir/test_search.vim 2020-02-05 20:14:30.086087866 +0100
***************
*** 1455,1457 ****
--- 1455,1498 ----
    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
*** ../vim-8.2.0211/src/testdir/test_sort.vim   2020-01-30 18:24:47.001204003 
+0100
--- src/testdir/test_sort.vim   2020-02-05 20:14:30.086087866 +0100
***************
*** 1383,1388 ****
--- 1383,1390 ----
    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
  
*** ../vim-8.2.0211/src/testdir/test_substitute.vim     2020-02-02 
15:32:09.967762406 +0100
--- src/testdir/test_substitute.vim     2020-02-05 20:14:30.086087866 +0100
***************
*** 803,806 ****
--- 803,821 ----
    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
*** ../vim-8.2.0211/src/testing.c       2020-01-28 20:49:02.288376955 +0100
--- src/testing.c       2020-02-05 20:14:30.086087866 +0100
***************
*** 632,637 ****
--- 632,650 ----
  }
  
  /*
+  * "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()"
   */
      void
*** ../vim-8.2.0211/src/version.c       2020-02-05 20:10:30.639158668 +0100
--- src/version.c       2020-02-05 20:16:31.901542752 +0100
***************
*** 744,745 ****
--- 744,747 ----
  {   /* Add new patch number below this line */
+ /**/
+     212,
  /**/

-- 
Due knot trussed yore spell chequer two fined awl miss steaks.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/202002051945.015Jj2eP030680%40masaka.moolenaar.net.

Raspunde prin e-mail lui