From 2faab5045a15fec4b145c6a8da6611f490131d05 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Wed, 11 Nov 2020 13:56:04 +0100 Subject: [PATCH] tests for relative and absolute, anchored and unanchored mixes Signed-off-by: Wolfgang Bumiller --- src/match_list.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/match_list.rs b/src/match_list.rs index fb8a422..59bfd7c 100644 --- a/src/match_list.rs +++ b/src/match_list.rs @@ -488,3 +488,36 @@ fn test_literal_matches() { )]; 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); +} -- 2.39.5