fork of https://github.com/sourcegraph/zoekt
0

Configure Feed

Select the types of activity you want to include in your feed.

Honor regex flags for case-sensitivity (#767)

* Honor regex flags for case-sensitivity

* change

* add test

* pr comment

+48 -18
+14
.vscode/launch.json
··· 1 + { 2 + // Use IntelliSense to learn about possible attributes. 3 + // Hover to view descriptions of existing attributes. 4 + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 + "version": "0.2.0", 6 + "configurations": [ 7 + { 8 + "name": "Attach to Process (from list)", 9 + "type": "go", 10 + "request": "attach", 11 + "mode": "local" 12 + }, 13 + ] 14 + }
+2 -1
eval.go
··· 641 641 case syntax.OpLiteral: 642 642 s := string(r.Rune) 643 643 if len(s) >= minTextSize { 644 - mt, err := d.newSubstringMatchTree(&query.Substring{Pattern: s, FileName: fileName, CaseSensitive: caseSensitive}) 644 + ignoreCase := syntax.FoldCase == (r.Flags & syntax.FoldCase) 645 + mt, err := d.newSubstringMatchTree(&query.Substring{Pattern: s, FileName: fileName, CaseSensitive: !ignoreCase && caseSensitive}) 645 646 return mt, true, !strings.Contains(s, "\n"), err 646 647 } 647 648 case syntax.OpCapture:
+32 -17
eval_test.go
··· 59 59 } 60 60 } 61 61 62 + func caseSensitiveSubstrMT(pattern string) matchTree { 63 + d := &indexData{} 64 + mt, _ := d.newSubstringMatchTree(&query.Substring{ 65 + Pattern: pattern, 66 + CaseSensitive: true, 67 + }) 68 + return mt 69 + } 70 + 62 71 func substrMT(pattern string) matchTree { 63 72 d := &indexData{} 64 73 mt, _ := d.newSubstringMatchTree(&query.Substring{ 65 - Pattern: pattern, 74 + Pattern: pattern, 75 + CaseSensitive: false, 66 76 }) 67 77 return mt 68 78 } 69 79 70 80 func TestRegexpParse(t *testing.T) { 71 81 type testcase struct { 72 - in string 73 - query matchTree 74 - isEquivalent bool 82 + in string 83 + query matchTree 84 + isEquivalent bool 85 + caseSensitive bool 75 86 } 76 87 77 88 cases := []testcase{ 78 - {"(foo|)bar", substrMT("bar"), false}, 79 - {"(foo|)", &bruteForceMatchTree{}, false}, 89 + {"(foo|)bar", substrMT("bar"), false, false}, 90 + {"(foo|)", &bruteForceMatchTree{}, false, false}, 80 91 {"(foo|bar)baz.*bla", &andMatchTree{[]matchTree{ 81 92 &orMatchTree{[]matchTree{ 82 93 substrMT("foo"), ··· 84 95 }}, 85 96 substrMT("baz"), 86 97 substrMT("bla"), 87 - }}, false}, 98 + }}, false, false}, 88 99 { 89 100 "^[a-z](People)+barrabas$", 90 101 &andMatchTree{[]matchTree{ 91 102 substrMT("People"), 92 103 substrMT("barrabas"), 93 - }}, false, 104 + }}, false, false, 94 105 }, 95 - {"foo", substrMT("foo"), true}, 96 - {"^foo", substrMT("foo"), false}, 97 - {"(foo) (bar)", &andMatchTree{[]matchTree{substrMT("foo"), substrMT("bar")}}, false}, 106 + {"foo", substrMT("foo"), true, false}, 107 + {"foo", caseSensitiveSubstrMT("foo"), true, true}, 108 + {"(?i)foo", substrMT("FOO"), true, false}, 109 + {"(?i)foo", substrMT("FOO"), true, true}, 110 + {"^foo", substrMT("foo"), false, false}, 111 + {"(foo) (bar)", &andMatchTree{[]matchTree{substrMT("foo"), substrMT("bar")}}, false, false}, 98 112 {"(thread|needle|haystack)", &orMatchTree{[]matchTree{ 99 113 substrMT("thread"), 100 114 substrMT("needle"), 101 115 substrMT("haystack"), 102 - }}, true}, 116 + }}, true, false}, 103 117 {"(foo)(?-s:.)*?(bar)", &andLineMatchTree{andMatchTree{[]matchTree{ 104 118 substrMT("foo"), 105 119 substrMT("bar"), 106 - }}}, false}, 120 + }}}, false, false}, 107 121 {"(foo)(?-s:.)*?[[:space:]](?-s:.)*?(bar)", &andMatchTree{[]matchTree{ 108 122 substrMT("foo"), 109 123 substrMT("bar"), 110 - }}, false}, 111 - {"(foo){2,}", substrMT("foo"), false}, 112 - {"(...)(...)", &bruteForceMatchTree{}, false}, 124 + }}, false, false}, 125 + {"(foo){2,}", substrMT("foo"), false, false}, 126 + {"(...)(...)", &bruteForceMatchTree{}, false, false}, 113 127 } 114 128 115 129 for _, c := range cases { ··· 120 134 } 121 135 d := indexData{} 122 136 q := query.Regexp{ 123 - Regexp: r, 137 + Regexp: r, 138 + CaseSensitive: c.caseSensitive, 124 139 } 125 140 gotQuery, isEq, _, _ := d.regexpToMatchTreeRecursive(q.Regexp, 3, q.FileName, q.CaseSensitive) 126 141 if !reflect.DeepEqual(c.query, gotQuery) {