]> git.proxmox.com Git - pathpatterns.git/commitdiff
tests for relative and absolute, anchored and unanchored mixes
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 11 Nov 2020 12:56:04 +0000 (13:56 +0100)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 11 Nov 2020 12:56:23 +0000 (13:56 +0100)
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
src/match_list.rs

index fb8a422f7791d5a1852ee62b4c7acf0ffe4e0078..59bfd7c360de4db3b84feade5248cfcb80a01281 100644 (file)
@@ -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);
+}