1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use crate::ValidateContains;

pub trait ValidateDoesNotContain {
    fn validate_does_not_contain(&self, needle: &str) -> bool;
}

impl<T> ValidateDoesNotContain for T
where
    T: ValidateContains,
{
    fn validate_does_not_contain(&self, needle: &str) -> bool {
        !self.validate_contains(needle)
    }
}

#[cfg(test)]
mod tests {
    use std::borrow::Cow;
    use std::collections::HashMap;

    use super::*;

    #[test]
    fn test_validate_does_not_contain_string() {
        assert!("hey".validate_does_not_contain("g"));
    }

    #[test]
    fn test_validate_does_not_contain_string_can_fail() {
        assert!(!"hey".validate_does_not_contain("e"));
    }

    #[test]
    fn test_validate_does_not_contain_hashmap_key() {
        let mut map = HashMap::new();
        map.insert("hey".to_string(), 1);
        assert!(map.validate_does_not_contain("bob"));
    }

    #[test]
    fn test_validate_does_not_contain_hashmap_key_can_fail() {
        let mut map = HashMap::new();
        map.insert("hey".to_string(), 1);
        assert!(!map.validate_does_not_contain("hey"));
    }

    #[test]
    fn test_validate_does_not_contain_cow() {
        let test: Cow<'static, str> = "hey".into();
        assert!(test.validate_does_not_contain("b"));
        let test: Cow<'static, str> = String::from("hey").into();
        assert!(test.validate_does_not_contain("b"));
    }

    #[test]
    fn test_validate_does_not_contain_cow_can_fail() {
        let test: Cow<'static, str> = "hey".into();
        assert!(!test.validate_does_not_contain("e"));
        let test: Cow<'static, str> = String::from("hey").into();
        assert!(!test.validate_does_not_contain("e"));
    }
}