rust-matchers: fix behavior of `IncludeMatcher` with multiple includes
This change adds a test for this fix as well as an additional test case that
was useful in debugging this behavior.
--- a/rust/hg-core/src/matchers.rs Tue Aug 30 10:52:32 2022 +0100
+++ b/rust/hg-core/src/matchers.rs Mon Aug 29 16:09:30 2022 +0200
@@ -791,7 +791,7 @@
dirs,
parents,
} = roots_dirs_and_parents(&ignore_patterns)?;
- let prefix = ignore_patterns.iter().any(|k| match k.syntax {
+ let prefix = ignore_patterns.iter().all(|k| match k.syntax {
PatternSyntax::Path | PatternSyntax::RelPath => true,
_ => false,
});
@@ -1094,6 +1094,31 @@
matcher.visit_children_set(HgPath::new(b"dir/subdir/x")),
VisitChildrenSet::This
);
+
+ // Test multiple patterns
+ let matcher = IncludeMatcher::new(vec![
+ IgnorePattern::new(PatternSyntax::RelPath, b"foo", Path::new("")),
+ IgnorePattern::new(PatternSyntax::Glob, b"g*", Path::new("")),
+ ])
+ .unwrap();
+
+ assert_eq!(
+ matcher.visit_children_set(HgPath::new(b"")),
+ VisitChildrenSet::This
+ );
+
+ // Test multiple patterns
+ let matcher = IncludeMatcher::new(vec![IgnorePattern::new(
+ PatternSyntax::Glob,
+ b"**/*.exe",
+ Path::new(""),
+ )])
+ .unwrap();
+
+ assert_eq!(
+ matcher.visit_children_set(HgPath::new(b"")),
+ VisitChildrenSet::This
+ );
}
#[test]