diff --git a/src/collections/mod.rs b/src/collections/mod.rs index 84820ad..276e0da 100644 --- a/src/collections/mod.rs +++ b/src/collections/mod.rs @@ -189,7 +189,7 @@ pub(crate) struct CollectionDebug<'wrapper, C> { pub(crate) collection: &'wrapper C, } -impl<'wrapper, 'collection, C> Debug for CollectionDebug<'wrapper, C> +impl<'collection, C> Debug for CollectionDebug<'_, C> where C: Collection<'collection>, C::Item: Debug diff --git a/src/collections/partial_eq/mod.rs b/src/collections/partial_eq/mod.rs index 5c346be..7434ac0 100644 --- a/src/collections/partial_eq/mod.rs +++ b/src/collections/partial_eq/mod.rs @@ -574,6 +574,12 @@ mod tests { but it "was <[ 2, 3, [5] ]>"); } + /// Test-case generator for assertions of the kind "contains_all_of", potentially with different + /// implementations (such as HashSet/BTreeSet/...). + /// + /// # Arguments + /// + /// * $assertion: The identifier of the assertion method. #[macro_export] macro_rules! test_contains_all_of { ($assertion:ident) => { @@ -626,6 +632,12 @@ mod tests { test_contains_all_of!(contains_all_of); + /// Test-case generator for assertions of the kind "contains_none_of", potentially with + /// different implementations (such as HashSet/BTreeSet/...). + /// + /// # Arguments + /// + /// * $assertion: The identifier of the assertion method. #[macro_export] macro_rules! test_contains_none_of { ($assertion:ident) => { @@ -663,6 +675,12 @@ mod tests { test_contains_none_of!(contains_none_of); + /// Test-case generator for assertions of the kind "contains_exactly_in_any_order", potentially + /// with different implementations (such as HashSet/BTreeSet/...). + /// + /// # Arguments + /// + /// * $assertion: The identifier of the assertion method. #[macro_export] macro_rules! test_contains_exactly_in_any_order { ($assertion:ident) => { diff --git a/src/lock.rs b/src/lock.rs index bc64f40..5de36be 100644 --- a/src/lock.rs +++ b/src/lock.rs @@ -46,7 +46,7 @@ impl_lock_ref!(Box); impl_lock_ref!(Rc); impl_lock_ref!(Arc); -impl<'cow, L: Clone + Lock> Lock for Cow<'cow, L> { +impl Lock for Cow<'_, L> { fn is_poisoned(&self) -> bool { L::is_poisoned(self.borrow()) } diff --git a/src/maps/debug.rs b/src/maps/debug.rs index f7437d7..3065af6 100644 --- a/src/maps/debug.rs +++ b/src/maps/debug.rs @@ -8,7 +8,7 @@ struct MapEntryDebug<'reference, 'map, M: Map<'map>> { entry: (&'reference M::Key, &'reference M::Value) } -impl<'reference, 'map, M> Debug for MapEntryDebug<'reference, 'map, M> +impl<'map, M> Debug for MapEntryDebug<'_, 'map, M> where M: Map<'map>, M::Key: Debug, @@ -38,7 +38,7 @@ impl<'reference, 'map, M: Map<'map>> MapEntriesDebug<'reference, 'map, M> { } } -impl<'reference, 'map, M> Debug for MapEntriesDebug<'reference, 'map, M> +impl<'map, M> Debug for MapEntriesDebug<'_, 'map, M> where M: Map<'map>, M::Key: Debug, @@ -53,7 +53,7 @@ pub(crate) struct MapDebug<'wrapper, M> { pub(crate) map: &'wrapper M } -impl<'wrapper, 'map, M> Debug for MapDebug<'wrapper, M> +impl<'map, M> Debug for MapDebug<'_, M> where M: Map<'map>, M::Key: Debug, @@ -73,7 +73,7 @@ where pub(crate) highlighted_key: &'key M::Key } -impl<'wrapper, 'key, 'map, M> Debug for HighlightedMapDebug<'wrapper, 'key, 'map, M> +impl<'key, 'map, M> Debug for HighlightedMapDebug<'_, 'key, 'map, M> where M: Map<'map>, 'map: 'key, diff --git a/src/maps/partial_eq/mod.rs b/src/maps/partial_eq/mod.rs index fee76d9..d7f231a 100644 --- a/src/maps/partial_eq/mod.rs +++ b/src/maps/partial_eq/mod.rs @@ -525,6 +525,12 @@ mod tests { but it "was <[ \"apple\" => 41, [\"banana\" => 42], \"cherry\" => 43 ]>"); } + /// Test-case generator for assertions of the kind "contains_values", potentially with different + /// implementations (such as HashSet/BTreeSet/...). + /// + /// # Arguments + /// + /// * $assertion: The identifier of the assertion method. #[macro_export] macro_rules! test_contains_values { ($assertion:ident) => { @@ -640,7 +646,12 @@ mod tests { but it "was <[ \"apple\" => 1, [\"banana\" => 2] ]>"); } - + /// Test-case generator for assertions of the kind "contains_exactly_values", potentially with + /// different implementations (such as HashSet/BTreeSet/...). + /// + /// # Arguments + /// + /// * $assertion: The identifier of the assertion method. #[macro_export] macro_rules! test_contains_exactly_values { ($assertion:ident) => { diff --git a/src/test_util.rs b/src/test_util.rs index c810f3f..475d450 100644 --- a/src/test_util.rs +++ b/src/test_util.rs @@ -13,12 +13,42 @@ pub(crate) fn assert_fails_do () + UnwindSafe>( assert_that!(assertion).panics_with_message(expected_message); } +/// Utility-macro to compactly write tests for failing assertions. As an example, consider the +/// following assertion. +/// +/// ```norun +/// assert_that!(1).is_equal_to(2); +/// ``` +/// +/// To test that this assertion fails with the correct message, we would use this macro as follows. +/// +/// ```norun +/// assert_fails!((1).is_equal_to(2), +/// expected it "to equal <2>" +/// but it "was <1>"); +/// ``` +/// +/// # Arguments +/// +/// * $input: The expression tested by the assertion which is expected to fail. Put inside +/// parentheses to ensure it is isolated from the rest (`.` would otherwise be interpreted as part +/// of the expression). In the example, this would be `1`. +/// * $assertion: The identifier of the assertion-method to test. In the example, this would be +/// `is_equal_to`. +/// * args: A parameter list to supply to the assertion expected to fail. In the example, this would +/// be `2` +/// * $expected_it: A string literal containing the expected part of the error message that comes +/// after `expected: <...> `. The first part of this line is asserted to be as the `Failure` +/// struct defines, with appropriate expression text. In the example, this would be +/// `"to equal <2>"`. +/// * $but_it: A string literal containing the expected part of the error message that comes +/// after `but: it <...> `. In the example, this would be `"was <1>"`. #[macro_export] macro_rules! assert_fails { - (( $input:expr ) . $assertion:ident ( $( $expected:expr ),* ), + (( $input:expr ) . $assertion:ident ( $( $args:expr ),* ), expected it $expected_it:tt but it $but_it:tt) => { $crate::test_util::assert_fails_do( - || { $crate::assert_that!($input).$assertion($( $expected, )*); }, + || { $crate::assert_that!($input).$assertion($( $args, )*); }, stringify!($input), $expected_it, $but_it); diff --git a/src/util/multiset/mod.rs b/src/util/multiset/mod.rs index b03992b..374b471 100644 --- a/src/util/multiset/mod.rs +++ b/src/util/multiset/mod.rs @@ -107,6 +107,12 @@ fn multiset_map_remove>(multiset_map: &mut M, item: &T) -> #[cfg(test)] mod tests { + /// Test-case generator for different Multiset-implementations, with different underlying data + /// structures (such as HashMap/BTreeMap/...). + /// + /// # Arguments + /// + /// * $multiset_type: The identifier of the tested type implementing Multiset. #[macro_export] macro_rules! test_multiset_impl { ($multiset_type:ident) => {