Skip to content

Commit

Permalink
api: add is_empty to RegexSet
Browse files Browse the repository at this point in the history
This adheres to standard conventions for collections of things.

Closes #687
  • Loading branch information
HammockSunburn authored and BurntSushi committed Oct 12, 2020
1 parent 0e21edc commit f0263cc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/re_set.rs
Expand Up @@ -207,6 +207,11 @@ impl RegexSet {
self.0.regex_strings().len()
}

/// Returns `true` if this set contains no regular expressions.
pub fn is_empty(&self) -> bool {
self.0.regex_strings().is_empty()
}

/// Returns the patterns that this set will match on.
///
/// This function can be used to determine the pattern for a match. The
Expand Down
11 changes: 11 additions & 0 deletions tests/set.rs
Expand Up @@ -54,3 +54,14 @@ fn get_set_patterns() {
let set = regex_set!(&["a", "b"]);
assert_eq!(vec!["a", "b"], set.patterns());
}

#[test]
fn len_and_empty() {
let empty = regex_set!(&[""; 0]);
assert_eq!(empty.len(), 0);
assert!(empty.is_empty());

let not_empty = regex_set!(&["ab", "b"]);
assert_eq!(not_empty.len(), 2);
assert!(!not_empty.is_empty());
}

0 comments on commit f0263cc

Please sign in to comment.