snip_cli/helpers/
is_fuzzy_match.rs

1pub fn is_fuzzy_match(text: &str, pattern: &str) -> bool {
2    let mut pattern_chars = pattern.chars().peekable();
3    for ch in text.chars() {
4        if let Some(&next_pattern_char) = pattern_chars.peek() {
5            if ch == next_pattern_char {
6                pattern_chars.next();
7            }
8        }
9    }
10    pattern_chars.peek().is_none()
11}
12
13#[cfg(test)]
14mod tests {
15    use super::*;
16
17    #[test]
18    fn test_is_fuzzy_match() {
19        assert!(!is_fuzzy_match("moon", "bd"));
20        assert!(!is_fuzzy_match("moon", "mp"));
21        assert!(is_fuzzy_match("moon", "mn"));
22        assert!(is_fuzzy_match("moon", "oon"));
23    }
24}