Skip to content

Commit 07ada5f

Browse files
committed
patch 8.2.0212: missing search/substitute pattern hardly tested
Problem: Missing search/substitute pattern hardly tested. Solution: Add test_clear_search_pat() and tests. (Yegappan Lakshmanan, closes #5579)
1 parent 94255df commit 07ada5f

15 files changed

Lines changed: 103 additions & 0 deletions

runtime/doc/eval.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2848,6 +2848,7 @@ term_wait({buf} [, {time}]) Number wait for screen to be updated
28482848
test_alloc_fail({id}, {countdown}, {repeat})
28492849
none make memory allocation fail
28502850
test_autochdir() none enable 'autochdir' during startup
2851+
test_clear_search_pat() none clears the last used search pattern
28512852
test_feedinput({string}) none add key sequence to input buffer
28522853
test_garbagecollect_now() none free memory right now for testing
28532854
test_garbagecollect_soon() none free memory soon for testing

runtime/doc/testing.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ test_autochdir() *test_autochdir()*
5252
startup has finished.
5353

5454

55+
test_clear_search_pat() *test_clear_search_pat()*
56+
Clears the last used search pattern (|/|) and the substitute
57+
pattern (|:s|). This is useful for testing conditions where
58+
these patterns are not set previously.
59+
5560
test_feedinput({string}) *test_feedinput()*
5661
Characters in {string} are queued for processing as if they
5762
were typed by the user. This uses a low level input buffer.

runtime/doc/usr_41.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,7 @@ Testing: *test-functions*
963963
assert_report() report a test failure
964964
test_alloc_fail() make memory allocation fail
965965
test_autochdir() enable 'autochdir' during startup
966+
test_clear_search_pat() clears the last used search pattern
966967
test_override() test with Vim internal overrides
967968
test_garbagecollect_now() free memory right now
968969
test_getvalue() get value of an internal variable

src/evalfunc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,7 @@ static funcentry_T global_functions[] =
810810
#endif
811811
{"test_alloc_fail", 3, 3, FEARG_1, &t_void, f_test_alloc_fail},
812812
{"test_autochdir", 0, 0, 0, &t_void, f_test_autochdir},
813+
{"test_clear_search_pat", 0, 0, 0, &t_void, f_test_clear_search_pat},
813814
{"test_feedinput", 1, 1, FEARG_1, &t_void, f_test_feedinput},
814815
{"test_garbagecollect_now", 0, 0, 0, &t_void, f_test_garbagecollect_now},
815816
{"test_garbagecollect_soon", 0, 0, 0, &t_void, f_test_garbagecollect_soon},

src/proto/regexp.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ int vim_regcomp_had_eol(void);
1212
regprog_T *vim_regcomp(char_u *expr_arg, int re_flags);
1313
void vim_regfree(regprog_T *prog);
1414
void free_regexp_stuff(void);
15+
void free_regexp_prev_sub(void);
1516
int regprog_in_use(regprog_T *prog);
1617
int vim_regexec_prog(regprog_T **prog, int ignore_case, char_u *line, colnr_T col);
1718
int vim_regexec(regmatch_T *rmp, char_u *line, colnr_T col);

src/proto/search.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ void free_search_patterns(void);
99
void save_last_search_pattern(void);
1010
void restore_last_search_pattern(void);
1111
char_u *last_search_pattern(void);
12+
void free_last_pat(int idx);
1213
int ignorecase(char_u *pat);
1314
int ignorecase_opt(char_u *pat, int ic_in, int scs);
1415
int pat_has_uppercase(char_u *pat);

src/proto/testing.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ void f_assert_report(typval_T *argvars, typval_T *rettv);
1313
void f_assert_true(typval_T *argvars, typval_T *rettv);
1414
void f_test_alloc_fail(typval_T *argvars, typval_T *rettv);
1515
void f_test_autochdir(typval_T *argvars, typval_T *rettv);
16+
void f_test_clear_search_pat(typval_T *argvars, typval_T *rettv);
1617
void f_test_feedinput(typval_T *argvars, typval_T *rettv);
1718
void f_test_getvalue(typval_T *argvars, typval_T *rettv);
1819
void f_test_option_not_set(typval_T *argvars, typval_T *rettv);

src/regexp.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2663,6 +2663,15 @@ free_regexp_stuff(void)
26632663
}
26642664
#endif
26652665

2666+
/*
2667+
* Free the previously used substitute search pattern.
2668+
*/
2669+
void
2670+
free_regexp_prev_sub(void)
2671+
{
2672+
VIM_CLEAR(reg_prev_sub);
2673+
}
2674+
26662675
#ifdef FEAT_EVAL
26672676
static void
26682677
report_re_switch(char_u *pat)

src/search.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,12 @@ last_search_pattern(void)
380380
}
381381
#endif
382382

383+
void
384+
free_last_pat(int idx)
385+
{
386+
VIM_CLEAR(spats[idx].pat);
387+
}
388+
383389
/*
384390
* Return TRUE when case should be ignored for search pattern "pat".
385391
* Uses the 'ignorecase' and 'smartcase' options.

src/testdir/test_quickfix.vim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2718,6 +2718,10 @@ func XvimgrepTests(cchar)
27182718
call assert_equal(0, getbufinfo('Xtestfile1')[0].loaded)
27192719
call assert_equal([], getbufinfo('Xtestfile2'))
27202720

2721+
" Test with the last search pattern not set
2722+
call test_clear_search_pat()
2723+
call assert_fails('Xvimgrep // *', 'E35:')
2724+
27212725
call delete('Xtestfile1')
27222726
call delete('Xtestfile2')
27232727
endfunc

0 commit comments

Comments
 (0)