Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvinou01 committed Aug 30, 2024
1 parent e4a8b60 commit 44fe794
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion crates/rattler_conda_types/src/match_spec/matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,33 @@ mod tests {
}

#[test]
fn test_string_matcher_matches() {
fn test_string_matcher_matches_basic() {
assert!(StringMatcher::from_str("foo").unwrap().matches("foo"));
assert!(!StringMatcher::from_str("foo").unwrap().matches("bar"));
}

#[test]
fn test_string_matcher_matches_glob() {
assert!(StringMatcher::from_str("foo*").unwrap().matches("foobar"));
assert!(StringMatcher::from_str("*oo").unwrap().matches("foo"));
assert!(!StringMatcher::from_str("*oo").unwrap().matches("foobar"));
assert!(StringMatcher::from_str("*oo*").unwrap().matches("foobar"));

// Conda's glob doesn't care about escaping
assert!(StringMatcher::from_str("foo\\*bar")
.unwrap()
.matches("foo\\bazbar"));
assert!(!StringMatcher::from_str("foo\\*bar")
.unwrap()
.matches("foobazbar"));

// Or any keywords other than '*'
assert!(!StringMatcher::from_str("foo[a-z]").unwrap().matches("fooa"));
assert!(!StringMatcher::from_str("foo[abc]").unwrap().matches("fooa"));
}

#[test]
fn test_string_matcher_matches_regex() {
assert!(StringMatcher::from_str("^foo.*$")
.unwrap()
.matches("foobar"));
Expand All @@ -151,6 +171,12 @@ mod tests {
assert!(!StringMatcher::from_str("^[not].*$")
.unwrap()
.matches("foobar"));
assert!(StringMatcher::from_str("^foo\\[bar\\].*$")
.unwrap()
.matches("foo[bar]"));
assert!(!StringMatcher::from_str("^foo\\[bar\\].*$")
.unwrap()
.matches("foobar"));
}

#[test]
Expand Down Expand Up @@ -184,4 +210,14 @@ mod tests {
})
);
}

#[test]
fn test_empty_strings() {
assert!(StringMatcher::from_str("").unwrap().matches(""));
assert!(!StringMatcher::from_str("").unwrap().matches("foo"));

assert!(!StringMatcher::from_str("foo").unwrap().matches(""));
assert!(StringMatcher::from_str("^$").unwrap().matches(""));
assert!(StringMatcher::from_str("*").unwrap().matches(""));
}
}

0 comments on commit 44fe794

Please sign in to comment.