comparison rust/hg-core/src/matchers.rs @ 49464:90512ca6a255 stable

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.
author Raphaël Gomès <rgomes@octobus.net>
date Mon, 29 Aug 2022 16:09:30 +0200
parents 97dcd6906e6f
children d8ce883ff1f4
comparison
equal deleted inserted replaced
49458:b10e4c19f8c5 49464:90512ca6a255
789 let RootsDirsAndParents { 789 let RootsDirsAndParents {
790 roots, 790 roots,
791 dirs, 791 dirs,
792 parents, 792 parents,
793 } = roots_dirs_and_parents(&ignore_patterns)?; 793 } = roots_dirs_and_parents(&ignore_patterns)?;
794 let prefix = ignore_patterns.iter().any(|k| match k.syntax { 794 let prefix = ignore_patterns.iter().all(|k| match k.syntax {
795 PatternSyntax::Path | PatternSyntax::RelPath => true, 795 PatternSyntax::Path | PatternSyntax::RelPath => true,
796 _ => false, 796 _ => false,
797 }); 797 });
798 let (patterns, match_fn) = build_match(ignore_patterns)?; 798 let (patterns, match_fn) = build_match(ignore_patterns)?;
799 799
1090 matcher.visit_children_set(HgPath::new(b"dir/subdir")), 1090 matcher.visit_children_set(HgPath::new(b"dir/subdir")),
1091 VisitChildrenSet::This 1091 VisitChildrenSet::This
1092 ); 1092 );
1093 assert_eq!( 1093 assert_eq!(
1094 matcher.visit_children_set(HgPath::new(b"dir/subdir/x")), 1094 matcher.visit_children_set(HgPath::new(b"dir/subdir/x")),
1095 VisitChildrenSet::This
1096 );
1097
1098 // Test multiple patterns
1099 let matcher = IncludeMatcher::new(vec![
1100 IgnorePattern::new(PatternSyntax::RelPath, b"foo", Path::new("")),
1101 IgnorePattern::new(PatternSyntax::Glob, b"g*", Path::new("")),
1102 ])
1103 .unwrap();
1104
1105 assert_eq!(
1106 matcher.visit_children_set(HgPath::new(b"")),
1107 VisitChildrenSet::This
1108 );
1109
1110 // Test multiple patterns
1111 let matcher = IncludeMatcher::new(vec![IgnorePattern::new(
1112 PatternSyntax::Glob,
1113 b"**/*.exe",
1114 Path::new(""),
1115 )])
1116 .unwrap();
1117
1118 assert_eq!(
1119 matcher.visit_children_set(HgPath::new(b"")),
1095 VisitChildrenSet::This 1120 VisitChildrenSet::This
1096 ); 1121 );
1097 } 1122 }
1098 1123
1099 #[test] 1124 #[test]