History

more tests for early exit in case no-wildcard prefix doesn't match (#301)

This also allows means 70 out of 150ish test cases still fail.

Sebastian Thiel committed 4 years ago

Commit 1ff348c1 parent 45c62592 files · +44 −1Browse files

Unified · Split

2 files
  1. git-glob/src/pattern.rs +15 −1
  2. git-glob/tests/matching/mod.rs +29 −0
git-glob/src/pattern.rs+15−1
@@ -136,7 +136,21 @@ impl Pattern { · 135 unmodified lines
136136 value.ends_with(text.as_ref())
137137 }
138138 }
139− Some(_pos) => todo!("actual wildcards for basename: {}", _pos),
139+ Some(pos) => {
140+ if options.contains(MatchOptions::IGNORE_CASE) {
141+ if !value
142+ .get(..pos)
143+ .map_or(false, |value| value.eq_ignore_ascii_case(&self.text[..pos]))
144+ {
145+ return false;
146+ }
147+ } else {
148+ if !value.starts_with(&self.text[..pos]) {
149+ return false;
150+ }
151+ }
152+ todo!("actual wildcard match for '{}' ~= '{}'", self.text, value)
153+ }
140154 None => {
141155 if options.contains(MatchOptions::IGNORE_CASE) {
142156 self.text.eq_ignore_ascii_case(value)
git-glob/tests/matching/mod.rs+29−0
@@ -174,6 +174,35 @@ fn absolute_path_matches_only_from_beginning() { · 173 unmodified lines
174174 assert!(!match_file(pat, "base/bar/Foo", Case::Sensitive));
175175 }
176176
177+#[test]
178+fn absolute_path_with_recursive_glob_detects_mismatches_quickly() {
179+ let mut pattern = pat("/bar/foo/**");
180+ let pat = &pattern;
181+ assert!(!match_file(pat, "FoO", Case::Fold));
182+ assert!(!match_file(pat, "bar/Fooo", Case::Fold));
183+ assert!(!match_file(pat, "baz/bar/Foo", Case::Fold));
184+
185+ pattern = pattern.with_base("base/");
186+ let pat = &pattern;
187+ assert!(!match_file(pat, "base/FoO", Case::Fold));
188+ assert!(!match_file(pat, "base/bar/Fooo", Case::Fold));
189+ assert!(!match_file(pat, "base/baz/bar/foo", Case::Sensitive));
190+}
191+
192+#[test]
193+#[ignore]
194+fn absolute_path_with_recursive_glob_can_do_case_insensitive_prefix_search() {
195+ let mut pattern = pat("/bar/foo/**");
196+ let pat = &pattern;
197+ assert!(!match_file(pat, "bar/Foo/match", Case::Sensitive));
198+ assert!(match_file(pat, "bar/Foo/match", Case::Fold));
199+
200+ pattern = pattern.with_base("base/");
201+ let pat = &pattern;
202+ assert!(!match_file(pat, "base/bar/Foo/match", Case::Sensitive));
203+ assert!(match_file(pat, "base/bar/Foo/match", Case::Fold));
204+}
205+
177206 #[test]
178207 fn relative_path_does_not_match_from_end() {
179208 let pattern = &pat("bar/foo");

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t