tests for relative and absolute, anchored and unanchored mixes

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2020-11-11 13:56:04 +01:00
parent 51f5c11e2b
commit 2faab5045a

View File

@ -488,3 +488,36 @@ fn test_literal_matches() {
)]; )];
assert_eq!(matchlist.matches("/bin/mv", None), Some(MatchType::Include)); assert_eq!(matchlist.matches("/bin/mv", None), Some(MatchType::Include));
} }
#[test]
fn test_path_relativity() {
use crate::Pattern;
let matchlist = vec![
MatchEntry::new(Pattern::path("noslash").unwrap(), MatchType::Include),
MatchEntry::new(Pattern::path("noslash-a").unwrap(), MatchType::Include)
.flags(MatchFlag::ANCHORED),
MatchEntry::new(Pattern::path("/slash").unwrap(), MatchType::Include),
MatchEntry::new(Pattern::path("/slash-a").unwrap(), MatchType::Include)
.flags(MatchFlag::ANCHORED),
];
assert_eq!(matchlist.matches("noslash", None), Some(MatchType::Include));
assert_eq!(
matchlist.matches("noslash-a", None),
Some(MatchType::Include)
);
assert_eq!(matchlist.matches("slash", None), None);
assert_eq!(matchlist.matches("/slash", None), Some(MatchType::Include));
assert_eq!(matchlist.matches("slash-a", None), None);
assert_eq!(
matchlist.matches("/slash-a", None),
Some(MatchType::Include)
);
assert_eq!(
matchlist.matches("foo/noslash", None),
Some(MatchType::Include)
);
assert_eq!(matchlist.matches("foo/noslash-a", None), None);
assert_eq!(matchlist.matches("foo/slash", None), None);
assert_eq!(matchlist.matches("foo/slash-a", None), None);
}