diff --git a/src/lib.rs b/src/lib.rs index 58688c9..739126e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -58,6 +58,8 @@ pub mod prelude { pub use matchers::regex::matches_regex as match_regex; pub use matchers::regex::matches_regex; pub use matchers::vecs::contains; + pub use matchers::vecs::contains_all_of; + pub use matchers::vecs::contains_all_of as contain_all_of; pub use matchers::vecs::of_len; pub use matchers::anything::anything; pub use matchers::type_of::type_of; diff --git a/src/matchers/vecs.rs b/src/matchers/vecs.rs index 19fff07..9de4352 100644 --- a/src/matchers/vecs.rs +++ b/src/matchers/vecs.rs @@ -123,7 +123,20 @@ fn is_next_index(current_index: &usize, previous_index: &Option) -> bool return true; } -pub fn contains(items: Vec) -> Contains { +/// Creates a matcher that checks if actual vector has all items of the given vector. +/// +/// # Examples +/// +/// ``` +/// #[macro_use] extern crate hamcrest; +/// use hamcrest::prelude::*; +/// +/// fn main() { +/// assert_that!(&vec![1, 2, 3, 4], contains_all_of(vec![1, 2, 3])); +/// assert_that!(&vec![1, 2, 3], does_not(contain_all_of(vec![1, 2, 4]))); +/// } +/// ``` +pub fn contains_all_of(items: Vec) -> Contains { Contains { items: items, exactly: false, @@ -131,6 +144,11 @@ pub fn contains(items: Vec) -> Contains { } } +#[deprecated(since = "0.2.0", note = "Use the contains_all_of instead")] +pub fn contains(items: Vec) -> Contains { + contains_all_of(items) +} + struct Pretty<'a, T: 'a>(&'a [T]); impl<'a, T: fmt::Debug> fmt::Display for Pretty<'a, T> { diff --git a/tests/all_of.rs b/tests/all_of.rs index 39e83c9..25911ad 100644 --- a/tests/all_of.rs +++ b/tests/all_of.rs @@ -19,10 +19,10 @@ mod all_of { } #[test] - fn vec_contains() { + fn vec_contains_all_of() { assert_that!( &vec![1, 2, 3], - all_of!(contains(vec![1, 2]), not(contains(vec![4]))) + all_of!(contains_all_of(vec![1, 2]), not(contains_all_of(vec![4]))) ); } } diff --git a/tests/any_of.rs b/tests/any_of.rs index cacb383..04a9d13 100644 --- a/tests/any_of.rs +++ b/tests/any_of.rs @@ -19,10 +19,13 @@ mod any_of { } #[test] - fn vec_contains() { + fn vec_contains_all_of() { assert_that!( &vec![1, 2, 3], - any_of!(contains(vec![1, 2, 5]), not(contains(vec![4]))) + any_of!( + contains_all_of(vec![1, 2, 5]), + not(contains_all_of(vec![4])) + ) ); } } diff --git a/tests/vecs.rs b/tests/vecs.rs index 9788d77..5e9c85a 100644 --- a/tests/vecs.rs +++ b/tests/vecs.rs @@ -14,37 +14,38 @@ mod vecs { use hamcrest::prelude::*; #[test] - fn vec_contains() { - assert_that!(&vec![1, 2, 3], contains(vec![1, 2])); - assert_that!(&vec![1, 2, 3], not(contains(vec![4]))); + fn vec_contains_all_of() { + assert_that!(&vec![1, 2, 3], contains_all_of(vec![1, 2])); + assert_that!(&vec![1, 2, 3], not(contains_all_of(vec![4]))); + assert_that!(&vec![1, 2, 3], does_not(contain_all_of(vec![4]))); } #[test] - fn vec_contains_exactly() { - assert_that!(&vec![1, 2, 3], contains(vec![1, 2, 3]).exactly()); - assert_that!(&vec![1, 2, 3], not(contains(vec![1, 2]).exactly())); + fn vec_contains_all_of_exactly() { + assert_that!(&vec![1, 2, 3], contains_all_of(vec![1, 2, 3]).exactly()); + assert_that!(&vec![1, 2, 3], not(contains_all_of(vec![1, 2]).exactly())); } #[test] - fn it_contains_elements_in_order() { - assert_that!(&vec![1, 2, 3], contains(vec![1, 2]).in_order()); + fn it_contains_all_of_elements_in_order() { + assert_that!(&vec![1, 2, 3], contains_all_of(vec![1, 2]).in_order()); } #[test] fn it_does_not_contain_elements_in_order() { - assert_that!(&vec![1, 2, 3], not(contains(vec![1, 3]).in_order())); + assert_that!(&vec![1, 2, 3], not(contains_all_of(vec![1, 3]).in_order())); } #[test] #[should_panic] - fn it_unsuccessfully_contains_elements_in_order() { - assert_that!(&vec![1, 2, 3], contains(vec![1, 3]).in_order()); + fn it_unsuccessfully_contains_all_of_elements_in_order() { + assert_that!(&vec![1, 2, 3], contains_all_of(vec![1, 3]).in_order()); } #[test] #[should_panic] fn it_unsuccessfully_does_not_contain_elements_in_order() { - assert_that!(&vec![1, 2, 3], not(contains(vec![2, 3]).in_order())); + assert_that!(&vec![1, 2, 3], not(contains_all_of(vec![2, 3]).in_order())); } #[test]