rust-matchers: fix behavior of `IncludeMatcher` with multiple includes stable
authorRaphaël Gomès <rgomes@octobus.net>
Mon, 29 Aug 2022 16:09:30 +0200
branchstable
changeset 49464 90512ca6a255
parent 49458 b10e4c19f8c5
child 49465 6b4ad07b4d69
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.
rust/hg-core/src/matchers.rs
--- 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]