sweet_test/_matchers/common/
matcher_vec.rs1use super::*;
2use std::fmt::Debug;
3
4impl<T: Debug> Matcher<&Vec<T>> {
5 pub fn to_be_empty(&self) {
6 let result = self.value.is_empty();
7 let expected = format!("to be empty");
8 self.assert_correct(result, &expected);
9 }
10 pub fn any(&self, func: impl FnMut(&T) -> bool) {
11 let result = self.value.iter().any(func);
12 let expected = format!("any to match predicate");
13 self.assert_correct(result, &expected);
14 }
15}
16
17impl<T: Debug + PartialEq> Matcher<&Vec<T>> {
18 pub fn to_contain_element(&self, other: &T) -> &Self {
19 let result = self.value.contains(other);
20 let expected = format!("to contain {:?}", other);
21 self.assert_correct(result, &expected);
22 self
23 }
24}
25
26
27#[cfg(test)]
28mod test {
29 use crate::prelude::*;
30
31 #[test]
32 fn vec() {
33 expect(&vec![1, 2, 3]).to_contain_element(&2);
34 expect(&vec![1, 2, 3]).not().to_contain_element(&4);
35 expect(&vec![1, 2, 3]).any(|val| val == &2);
36 expect(&vec![1, 2, 3]).not().any(|val| val == &4);
37 }
38}