From 66e29d7112e437b2b50efe1f82c7e892736d23e4 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Sat, 20 Aug 2016 16:57:02 +0200 Subject: patch 7.4.2230 Problem: There is no equivalent of 'smartcase' for a tag search. Solution: Add value "followscs" and "smart" to 'tagcase'. (Christian Brabandt, closes #712) Turn tagcase test into new style. --- src/Makefile | 2 +- src/option.h | 4 ++- src/proto/search.pro | 1 + src/search.c | 13 ++++++-- src/tag.c | 8 +++-- src/testdir/Make_all.mak | 1 - src/testdir/test_alot.vim | 1 + src/testdir/test_tagcase.in | 57 --------------------------------- src/testdir/test_tagcase.ok | 76 -------------------------------------------- src/testdir/test_tagcase.vim | 73 ++++++++++++++++++++++++++++++++++++++++++ src/version.c | 2 ++ 11 files changed, 97 insertions(+), 141 deletions(-) delete mode 100644 src/testdir/test_tagcase.in delete mode 100644 src/testdir/test_tagcase.ok create mode 100644 src/testdir/test_tagcase.vim (limited to 'src') diff --git a/src/Makefile b/src/Makefile index 5d895f1367..690e08ab36 100644 --- a/src/Makefile +++ b/src/Makefile @@ -2031,7 +2031,6 @@ test1 \ test_marks \ test_nested_function \ test_search_mbyte \ - test_tagcase \ test_utf8 \ test_wordcount \ test_writefile \ @@ -2123,6 +2122,7 @@ test_arglist \ test_syntax \ test_tabline \ test_tabpage \ + test_tagcase \ test_tagjump \ test_textobjects \ test_timers \ diff --git a/src/option.h b/src/option.h index bee6442c05..c86550fb11 100644 --- a/src/option.h +++ b/src/option.h @@ -822,11 +822,13 @@ EXTERN int p_tbs; /* 'tagbsearch' */ EXTERN char_u *p_tc; /* 'tagcase' */ EXTERN unsigned tc_flags; /* flags from 'tagcase' */ #ifdef IN_OPTION_C -static char *(p_tc_values[]) = {"followic", "ignore", "match", NULL}; +static char *(p_tc_values[]) = {"followic", "ignore", "match", "followscs", "smart", NULL}; #endif #define TC_FOLLOWIC 0x01 #define TC_IGNORE 0x02 #define TC_MATCH 0x04 +#define TC_FOLLOWSCS 0x08 +#define TC_SMART 0x10 EXTERN long p_tl; /* 'taglength' */ EXTERN int p_tr; /* 'tagrelative' */ EXTERN char_u *p_tags; /* 'tags' */ diff --git a/src/proto/search.pro b/src/proto/search.pro index 339aa34625..3b9ca5c74a 100644 --- a/src/proto/search.pro +++ b/src/proto/search.pro @@ -7,6 +7,7 @@ void save_search_patterns(void); void restore_search_patterns(void); void free_search_patterns(void); int ignorecase(char_u *pat); +int ignorecase_opt(char_u *pat, int ic_in, int scs); int pat_has_uppercase(char_u *pat); char_u *last_csearch(void); int last_csearch_forward(void); diff --git a/src/search.c b/src/search.c index 1f1ba6a3fd..6e3850d4a6 100644 --- a/src/search.c +++ b/src/search.c @@ -367,9 +367,18 @@ free_search_patterns(void) int ignorecase(char_u *pat) { - int ic = p_ic; + return ignorecase_opt(pat, p_ic, p_scs); +} + +/* + * As ignorecase() put pass the "ic" and "scs" flags. + */ + int +ignorecase_opt(char_u *pat, int ic_in, int scs) +{ + int ic = ic_in; - if (ic && !no_smartcase && p_scs + if (ic && !no_smartcase && scs #ifdef FEAT_INS_EXPAND && !(ctrl_x_mode && curbuf->b_p_inf) #endif diff --git a/src/tag.c b/src/tag.c index e388a438c3..8fe213d6d5 100644 --- a/src/tag.c +++ b/src/tag.c @@ -1385,9 +1385,11 @@ find_tags( */ switch (curbuf->b_tc_flags ? curbuf->b_tc_flags : tc_flags) { - case TC_FOLLOWIC: break; - case TC_IGNORE: p_ic = TRUE; break; - case TC_MATCH: p_ic = FALSE; break; + case TC_FOLLOWIC: break; + case TC_IGNORE: p_ic = TRUE; break; + case TC_MATCH: p_ic = FALSE; break; + case TC_FOLLOWSCS: p_ic = ignorecase(pat); break; + case TC_SMART: p_ic = ignorecase_opt(pat, TRUE, TRUE); break; } help_save = curbuf->b_help; diff --git a/src/testdir/Make_all.mak b/src/testdir/Make_all.mak index 19973d5425..3a0742d64c 100644 --- a/src/testdir/Make_all.mak +++ b/src/testdir/Make_all.mak @@ -100,7 +100,6 @@ SCRIPTS_ALL = \ test_marks.out \ test_nested_function.out \ test_search_mbyte.out \ - test_tagcase.out \ test_utf8.out \ test_wordcount.out \ test_writefile.out diff --git a/src/testdir/test_alot.vim b/src/testdir/test_alot.vim index daf5b0ad04..b89d4b0db4 100644 --- a/src/testdir/test_alot.vim +++ b/src/testdir/test_alot.vim @@ -35,6 +35,7 @@ source test_statusline.vim source test_syn_attr.vim source test_tabline.vim source test_tabpage.vim +source test_tagcase.vim source test_tagjump.vim source test_timers.vim source test_true_false.vim diff --git a/src/testdir/test_tagcase.in b/src/testdir/test_tagcase.in deleted file mode 100644 index d76dbab997..0000000000 --- a/src/testdir/test_tagcase.in +++ /dev/null @@ -1,57 +0,0 @@ -Tests for 'tagcase' option - -STARTTEST -:so small.vim -:lang mess C -:/^start text$/+1,/^end text$/w! Xtext -:/^start tags$/+1,/^end tags$/-1w! Xtags -:set tags=Xtags -:e Xtext -:" -:" Verify default values. -:set ic& | setg tc& | setl tc& -:call append('$', "ic=".&ic." g:tc=".&g:tc." l:tc=".&l:tc." tc=".&tc) -:" -:" Verify that the local setting accepts but that the global setting -:" does not. The first of these (setting the local value to ) should -:" succeed; the other two should fail. -:let v:errmsg = "" -:setl tc= -:call append('$', v:errmsg) -:let v:errmsg = "" -:setg tc= -:call append('$', v:errmsg) -:let v:errmsg = "" -:set tc= -:call append('$', v:errmsg) -:" -:" Verify that the correct number of matching tags is found for all values of -:" 'ignorecase' and global and local values 'tagcase', in all combinations. -:for &ic in [0, 1] -: for &g:tc in ["followic", "ignore", "match"] -: for &l:tc in ["", "followic", "ignore", "match"] -: call append('$', "ic=".&ic." g:tc=".&g:tc." l:tc=".&l:tc." tc=".&tc) -: call append('$', len(taglist("^foo$"))) -: call append('$', len(taglist("^Foo$"))) -: endfor -: endfor -:endfor -:" -:1,/^end text$/d -:w! test.out -:qa! -ENDTEST - -start text - -Foo -Bar -foo - -end text - -start tags -Bar Xtext 3 -Foo Xtext 2 -foo Xtext 4 -end tags diff --git a/src/testdir/test_tagcase.ok b/src/testdir/test_tagcase.ok deleted file mode 100644 index fe161cf387..0000000000 --- a/src/testdir/test_tagcase.ok +++ /dev/null @@ -1,76 +0,0 @@ -ic=0 g:tc=followic l:tc=followic tc=followic - -E474: Invalid argument: tc= -E474: Invalid argument: tc= -ic=0 g:tc=followic l:tc= tc=followic -1 -1 -ic=0 g:tc=followic l:tc=followic tc=followic -1 -1 -ic=0 g:tc=followic l:tc=ignore tc=ignore -2 -2 -ic=0 g:tc=followic l:tc=match tc=match -1 -1 -ic=0 g:tc=ignore l:tc= tc=ignore -2 -2 -ic=0 g:tc=ignore l:tc=followic tc=followic -1 -1 -ic=0 g:tc=ignore l:tc=ignore tc=ignore -2 -2 -ic=0 g:tc=ignore l:tc=match tc=match -1 -1 -ic=0 g:tc=match l:tc= tc=match -1 -1 -ic=0 g:tc=match l:tc=followic tc=followic -1 -1 -ic=0 g:tc=match l:tc=ignore tc=ignore -2 -2 -ic=0 g:tc=match l:tc=match tc=match -1 -1 -ic=1 g:tc=followic l:tc= tc=followic -2 -2 -ic=1 g:tc=followic l:tc=followic tc=followic -2 -2 -ic=1 g:tc=followic l:tc=ignore tc=ignore -2 -2 -ic=1 g:tc=followic l:tc=match tc=match -1 -1 -ic=1 g:tc=ignore l:tc= tc=ignore -2 -2 -ic=1 g:tc=ignore l:tc=followic tc=followic -2 -2 -ic=1 g:tc=ignore l:tc=ignore tc=ignore -2 -2 -ic=1 g:tc=ignore l:tc=match tc=match -1 -1 -ic=1 g:tc=match l:tc= tc=match -1 -1 -ic=1 g:tc=match l:tc=followic tc=followic -2 -2 -ic=1 g:tc=match l:tc=ignore tc=ignore -2 -2 -ic=1 g:tc=match l:tc=match tc=match -1 -1 diff --git a/src/testdir/test_tagcase.vim b/src/testdir/test_tagcase.vim new file mode 100644 index 0000000000..83e532822d --- /dev/null +++ b/src/testdir/test_tagcase.vim @@ -0,0 +1,73 @@ +" test 'tagcase' option + +func Test_tagcase() + call writefile(["Bar\tXtext\t3", "Foo\tXtext\t2", "foo\tXtext\t4"], 'Xtags') + set tags=Xtags + e Xtext + + for &ic in [0, 1] + for &scs in [0, 1] + for &g:tc in ["followic", "ignore", "match", "followscs", "smart"] + for &l:tc in ["", "followic", "ignore", "match", "followscs", "smart"] + let smart = 0 + if &l:tc != '' + let tc = &l:tc + else + let tc = &g:tc + endif + if tc == 'followic' + let ic = &ic + elseif tc == 'ignore' + let ic = 1 + elseif tc == 'followscs' + let ic = &ic + let smart = &scs + elseif tc == 'smart' + let ic = 1 + let smart = 1 + else + let ic = 0 + endif + if ic && smart + call assert_equal(['foo', 'Foo'], map(taglist("^foo$"), {i, v -> v.name})) + call assert_equal(['Foo'], map(taglist("^Foo$"), {i, v -> v.name})) + elseif ic + call assert_equal(['foo', 'Foo'], map(taglist("^foo$"), {i, v -> v.name})) + call assert_equal(['Foo', 'foo'], map(taglist("^Foo$"), {i, v -> v.name})) + else + call assert_equal(['foo'], map(taglist("^foo$"), {i, v -> v.name})) + call assert_equal(['Foo'], map(taglist("^Foo$"), {i, v -> v.name})) + endif + endfor + endfor + endfor + endfor + + call delete('Xtags') + set ic& + setg tc& + setl tc& + set scs& +endfunc + +func Test_set_tagcase() + " Verify default values. + set ic& + setg tc& + setl tc& + call assert_equal(0, &ic) + call assert_equal('followic', &g:tc) + call assert_equal('followic', &l:tc) + call assert_equal('followic', &tc) + + " Verify that the local setting accepts but that the global setting + " does not. The first of these (setting the local value to ) should + " succeed; the other two should fail. + setl tc= + call assert_fails('setg tc=', 'E474:') + call assert_fails('set tc=', 'E474:') + + set ic& + setg tc& + setl tc& +endfunc diff --git a/src/version.c b/src/version.c index 2f832706e4..e892a95daf 100644 --- a/src/version.c +++ b/src/version.c @@ -763,6 +763,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 2230, /**/ 2229, /**/ -- cgit v1.2.3