diff --git a/Cargo.toml b/Cargo.toml index 34e3b02..6d76364 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "asserting" version = "0.14.0" authors = ["haraldmaida"] license = "MIT OR Apache-2.0" -edition = "2021" +edition = "2024" rust-version = "1.85.1" repository = "https://github.com/innoave/asserting" readme = "README.md" @@ -73,15 +73,19 @@ version-sync.opt-level = 3 [lints.rust] unsafe_code = "forbid" unstable_features = "forbid" +deprecated_safe = { level = "forbid", priority = -1 } bare_trait_objects = "warn" deprecated = "warn" explicit_outlives_requirements = "warn" +keyword_idents_2024 = "warn" noop_method_call = "warn" rust_2018_idioms = { level = "warn", priority = -1 } rust_2021_incompatible_closure_captures = "warn" rust_2021_incompatible_or_patterns = "warn" rust_2021_prefixes_incompatible_syntax = "warn" rust_2021_prelude_collisions = "warn" +rust_2024_guarded_string_incompatible_syntax = "warn" +rust_2024_prelude_collisions = "warn" single_use_lifetimes = "warn" trivial_casts = "warn" trivial_numeric_casts = "warn" diff --git a/src/bigdecimal/tests.rs b/src/bigdecimal/tests.rs index c56ecc9..c11110b 100644 --- a/src/bigdecimal/tests.rs +++ b/src/bigdecimal/tests.rs @@ -1,6 +1,6 @@ use crate::prelude::*; -use bigdecimal::num_bigint::BigInt; use bigdecimal::BigDecimal; +use bigdecimal::num_bigint::BigInt; #[test] fn bigdecimal_is_equal_to_other() { diff --git a/src/boolean/mod.rs b/src/boolean/mod.rs index 5049e77..480420b 100644 --- a/src/boolean/mod.rs +++ b/src/boolean/mod.rs @@ -2,7 +2,7 @@ use crate::assertions::AssertBoolean; use crate::colored::{mark_missing, mark_unexpected}; -use crate::expectations::{is_false, is_true, IsFalse, IsTrue}; +use crate::expectations::{IsFalse, IsTrue, is_false, is_true}; use crate::spec::{DiffFormat, Expectation, Expression, FailingStrategy, Invertible, Spec}; use crate::std::format; use crate::std::string::String; diff --git a/src/char/mod.rs b/src/char/mod.rs index d31ef59..a4fedab 100644 --- a/src/char/mod.rs +++ b/src/char/mod.rs @@ -1,9 +1,9 @@ use crate::assertions::AssertChar; use crate::colored::{mark_missing_string, mark_unexpected_char}; use crate::expectations::{ - is_alphabetic, is_alphanumeric, is_ascii, is_control_char, is_digit, is_lower_case, - is_upper_case, is_whitespace, IsAlphabetic, IsAlphanumeric, IsAscii, IsControlChar, IsDigit, - IsLowerCase, IsUpperCase, IsWhitespace, + IsAlphabetic, IsAlphanumeric, IsAscii, IsControlChar, IsDigit, IsLowerCase, IsUpperCase, + IsWhitespace, is_alphabetic, is_alphanumeric, is_ascii, is_control_char, is_digit, + is_lower_case, is_upper_case, is_whitespace, }; use crate::spec::{DiffFormat, Expectation, Expression, FailingStrategy, Invertible, Spec}; use crate::std::format; @@ -102,7 +102,9 @@ impl Expectation for IsLowerCase { }; let marked_actual = mark_unexpected_char(*actual, format); let marked_expected = mark_missing_string(&expected, format); - format!("expected {expression} to be {not}lowercase\n but was: {marked_actual}\n expected: {marked_expected}") + format!( + "expected {expression} to be {not}lowercase\n but was: {marked_actual}\n expected: {marked_expected}" + ) } } @@ -143,7 +145,9 @@ impl Expectation for IsUpperCase { }; let marked_actual = mark_unexpected_char(*actual, format); let marked_expected = mark_missing_string(&expected, format); - format!("expected {expression} to be {not}uppercase\n but was: {marked_actual}\n expected: {marked_expected}") + format!( + "expected {expression} to be {not}uppercase\n but was: {marked_actual}\n expected: {marked_expected}" + ) } } @@ -179,7 +183,9 @@ impl Expectation for IsAscii { ) -> String { let not = if inverted { "not " } else { "" }; let marked_actual = mark_unexpected_char(*actual, format); - format!("expected {expression} to be {not}an ASCII character\n but was: {marked_actual}\n expected: {not}an ASCII character") + format!( + "expected {expression} to be {not}an ASCII character\n but was: {marked_actual}\n expected: {not}an ASCII character" + ) } } @@ -215,7 +221,9 @@ impl Expectation for IsAlphabetic { ) -> String { let not = if inverted { "not " } else { "" }; let marked_actual = mark_unexpected_char(*actual, format); - format!("expected {expression} to be {not}an alphabetic character\n but was: {marked_actual}\n expected: {not}an alphabetic character") + format!( + "expected {expression} to be {not}an alphabetic character\n but was: {marked_actual}\n expected: {not}an alphabetic character" + ) } } @@ -251,7 +259,9 @@ impl Expectation for IsAlphanumeric { ) -> String { let not = if inverted { "not " } else { "" }; let marked_actual = mark_unexpected_char(*actual, format); - format!("expected {expression} to be {not}an alphanumeric character\n but was: {marked_actual}\n expected: {not}an alphanumeric character") + format!( + "expected {expression} to be {not}an alphanumeric character\n but was: {marked_actual}\n expected: {not}an alphanumeric character" + ) } } @@ -287,7 +297,9 @@ impl Expectation for IsControlChar { ) -> String { let not = if inverted { "not " } else { "" }; let marked_actual = mark_unexpected_char(*actual, format); - format!("expected {expression} to be {not}a control character\n but was: {marked_actual}\n expected: {not}a control character") + format!( + "expected {expression} to be {not}a control character\n but was: {marked_actual}\n expected: {not}a control character" + ) } } @@ -324,7 +336,9 @@ impl Expectation for IsDigit { let not = if inverted { "not " } else { "" }; let radix = self.radix; let marked_actual = mark_unexpected_char(*actual, format); - format!("expected {expression} to be {not}a digit in the radix {radix}\n but was: {marked_actual}\n expected: {not}a digit in the radix {radix}") + format!( + "expected {expression} to be {not}a digit in the radix {radix}\n but was: {marked_actual}\n expected: {not}a digit in the radix {radix}" + ) } } @@ -360,7 +374,9 @@ impl Expectation for IsWhitespace { ) -> String { let not = if inverted { "not " } else { "" }; let marked_actual = mark_unexpected_char(*actual, format); - format!("expected {expression} to be {not}whitespace\n but was: {marked_actual}\n expected: {not}whitespace") + format!( + "expected {expression} to be {not}whitespace\n but was: {marked_actual}\n expected: {not}whitespace" + ) } } diff --git a/src/char_count.rs b/src/char_count.rs index aed743f..8196ba2 100644 --- a/src/char_count.rs +++ b/src/char_count.rs @@ -3,9 +3,9 @@ use crate::assertions::AssertHasCharCount; use crate::colored::{mark_missing, mark_unexpected}; use crate::expectations::{ - has_at_least_char_count, has_at_most_char_count, has_char_count, has_char_count_greater_than, - has_char_count_in_range, has_char_count_less_than, HasAtLeastCharCount, HasAtMostCharCount, - HasCharCount, HasCharCountGreaterThan, HasCharCountInRange, HasCharCountLessThan, + HasAtLeastCharCount, HasAtMostCharCount, HasCharCount, HasCharCountGreaterThan, + HasCharCountInRange, HasCharCountLessThan, has_at_least_char_count, has_at_most_char_count, + has_char_count, has_char_count_greater_than, has_char_count_in_range, has_char_count_less_than, }; use crate::properties::CharCountProperty; use crate::spec::{DiffFormat, Expectation, Expression, FailingStrategy, Spec}; diff --git a/src/collection.rs b/src/collection.rs index 323a1b1..8dbbb63 100644 --- a/src/collection.rs +++ b/src/collection.rs @@ -2,8 +2,8 @@ use crate::properties::{DefinedOrderProperty, IsEmptyProperty, LengthProperty}; use crate::std::collections::{ - btree_map, btree_set, linked_list, vec_deque, BTreeMap, BTreeSet, BinaryHeap, LinkedList, - VecDeque, + BTreeMap, BTreeSet, BinaryHeap, LinkedList, VecDeque, btree_map, btree_set, linked_list, + vec_deque, }; use crate::std::{array, slice}; use crate::std::{vec, vec::Vec}; diff --git a/src/colored/mod.rs b/src/colored/mod.rs index e5506af..1b80053 100644 --- a/src/colored/mod.rs +++ b/src/colored/mod.rs @@ -47,8 +47,8 @@ #[cfg(feature = "colored")] #[cfg_attr(docsrs, doc(cfg(feature = "colored")))] pub use with_colored_feature::{ - diff_format_for_mode, DIFF_FORMAT_BOLD, DIFF_FORMAT_RED_BLUE, DIFF_FORMAT_RED_GREEN, - DIFF_FORMAT_RED_YELLOW, + DIFF_FORMAT_BOLD, DIFF_FORMAT_RED_BLUE, DIFF_FORMAT_RED_GREEN, DIFF_FORMAT_RED_YELLOW, + diff_format_for_mode, }; use crate::spec::{DiffFormat, Highlight}; diff --git a/src/colored/tests.rs b/src/colored/tests.rs index 75e235f..fe1c74f 100644 --- a/src/colored/tests.rs +++ b/src/colored/tests.rs @@ -59,12 +59,15 @@ mod with_colored_feature { })) .display_failures(); - assert_eq!(failures, &[ - "expected subject to be equal to Some(Foo { lorem: \"Hello World!\", ipsum: 42, dolor: Some(\"hey ho!\") })\n \ + assert_eq!( + failures, + &[ + "expected subject to be equal to Some(Foo { lorem: \"Hello World!\", ipsum: 42, dolor: Some(\"hey ho!\") })\n \ but was: Some(Foo { lorem: \"\u{1b}[31m¡\u{1b}[0mH\u{1b}[31mo\u{1b}[0ml\u{1b}[31ma,\u{1b}[0m W\u{1b}[31me\u{1b}[0ml\u{1b}[31mt\u{1b}[0m!\", ipsum: 42, dolor: Some(\"hey\") })\n \ expected: Some(Foo { lorem: \"H\u{1b}[32me\u{1b}[0ml\u{1b}[32mlo\u{1b}[0m W\u{1b}[32mor\u{1b}[0ml\u{1b}[32md\u{1b}[0m!\", ipsum: 42, dolor: Some(\"hey\u{1b}[32m ho!\u{1b}[0m\") })\n\ ", - ]); + ] + ); } #[test] @@ -136,8 +139,8 @@ mod with_colored_feature { } #[test] - fn mark_unexpected_substring_in_string_highlights_nothing_if_the_string_does_not_contain_the_substring( - ) { + fn mark_unexpected_substring_in_string_highlights_nothing_if_the_string_does_not_contain_the_substring() + { let marked_string = mark_unexpected_substring_in_string( "mollit est eu amet", "st eux a", @@ -159,8 +162,8 @@ mod with_colored_feature { } #[test] - fn mark_missing_substring_in_string_highlights_nothing_if_the_string_does_not_contain_the_substring( - ) { + fn mark_missing_substring_in_string_highlights_nothing_if_the_string_does_not_contain_the_substring() + { let marked_string = mark_missing_substring_in_string( "mollit est eu amet", "xt est eu", @@ -171,8 +174,8 @@ mod with_colored_feature { } #[test] - fn mark_unexpected_char_in_string_highlights_all_occurences_of_a_char_within_a_string_as_unexpected( - ) { + fn mark_unexpected_char_in_string_highlights_all_occurences_of_a_char_within_a_string_as_unexpected() + { let marked_string = mark_unexpected_char_in_string("zzril mazim sint", 'z', &DIFF_FORMAT_RED_YELLOW); @@ -181,8 +184,8 @@ mod with_colored_feature { } #[test] - fn mark_unexpected_char_in_string_highlights_nothing_if_the_string_does_not_contain_the_character( - ) { + fn mark_unexpected_char_in_string_highlights_nothing_if_the_string_does_not_contain_the_character() + { let marked_string = mark_unexpected_char_in_string("zzril mazim sint", 'v', &DIFF_FORMAT_RED_YELLOW); diff --git a/src/equality.rs b/src/equality.rs index d580f23..3564fdb 100644 --- a/src/equality.rs +++ b/src/equality.rs @@ -5,8 +5,8 @@ use crate::assertions::{ }; use crate::colored::{mark_diff, mark_diff_str}; use crate::expectations::{ - has_debug_string, has_display_string, is_equal_to, is_same_as, not, HasDebugString, - HasDisplayString, IsEqualTo, IsSameAs, + HasDebugString, HasDisplayString, IsEqualTo, IsSameAs, has_debug_string, has_display_string, + is_equal_to, is_same_as, not, }; use crate::spec::{DiffFormat, Expectation, Expression, FailingStrategy, Invertible, Spec}; use crate::std::fmt::{Debug, Display}; diff --git a/src/error/mod.rs b/src/error/mod.rs index 4133fa8..9e54ba7 100644 --- a/src/error/mod.rs +++ b/src/error/mod.rs @@ -1,7 +1,7 @@ use crate::assertions::AssertErrorHasSource; use crate::colored::{mark_missing, mark_missing_string, mark_unexpected, mark_unexpected_string}; use crate::expectations::{ - error_has_source, error_has_source_message, not, ErrorHasSource, ErrorHasSourceMessage, + ErrorHasSource, ErrorHasSourceMessage, error_has_source, error_has_source_message, not, }; use crate::spec::{DiffFormat, Expectation, Expression, FailingStrategy, Invertible, Spec}; use crate::std::error::Error; @@ -52,7 +52,9 @@ where }; let marked_actual = mark_unexpected(actual, format); let marked_expected = mark_missing_string(expected, format); - format!("expected {expression} to have {a} source\n but was: {marked_actual}\n expected: {marked_expected}") + format!( + "expected {expression} to have {a} source\n but was: {marked_actual}\n expected: {marked_expected}" + ) } } @@ -80,12 +82,16 @@ where if let Some(actual_source) = actual.source() { let marked_actual = mark_unexpected_string(&actual_source.to_string(), format); let marked_expected = mark_missing_string(expected, format); - format!("expected {expression} to have a source message {not}equal to \"{expected}\"\n but was: \"{marked_actual}\"\n expected: \"{marked_expected}\"") + format!( + "expected {expression} to have a source message {not}equal to \"{expected}\"\n but was: \"{marked_actual}\"\n expected: \"{marked_expected}\"" + ) } else { let mut marked_actual = mark_unexpected(actual, format); marked_actual.push_str(" - which has no source"); let marked_expected = mark_missing(expected, format); - format!("expected {expression} to have a source message {not}equal to \"{expected}\"\n but was: {marked_actual}\n expected: {not}{marked_expected}") + format!( + "expected {expression} to have a source message {not}equal to \"{expected}\"\n but was: {marked_actual}\n expected: {not}{marked_expected}" + ) } } } diff --git a/src/expectation_combinators/tests.rs b/src/expectation_combinators/tests.rs index 82e8f4b..1870ead 100644 --- a/src/expectation_combinators/tests.rs +++ b/src/expectation_combinators/tests.rs @@ -1,6 +1,6 @@ use crate::expectations::{ - all, any, not, rec, IsBetween, IsEmpty, IsGreaterThan, IsLessThan, IsNegative, IsOne, - IsPositive, IsZero, StringContains, StringContainsAnyOf, + IsBetween, IsEmpty, IsGreaterThan, IsLessThan, IsNegative, IsOne, IsPositive, IsZero, + StringContains, StringContainsAnyOf, all, any, not, rec, }; use crate::prelude::*; use crate::spec::{Expectation, Expression}; diff --git a/src/float/mod.rs b/src/float/mod.rs index 59b43f1..5b98edc 100644 --- a/src/float/mod.rs +++ b/src/float/mod.rs @@ -97,7 +97,7 @@ impl IsNanProperty for f64 { mod cmp { use crate::assertions::{AssertIsCloseToWithDefaultMargin, AssertIsCloseToWithinMargin}; use crate::colored::mark_diff; - use crate::expectations::{is_close_to, not, IsCloseTo}; + use crate::expectations::{IsCloseTo, is_close_to, not}; use crate::spec::{DiffFormat, Expectation, Expression, FailingStrategy, Invertible, Spec}; use crate::std::{format, string::String}; use float_cmp::{ApproxEq, F32Margin, F64Margin}; @@ -172,7 +172,8 @@ mod cmp { ) -> String { let not = if inverted { "not " } else { "" }; let (marked_actual, marked_expected) = mark_diff(actual, &self.expected, format); - format!("expected {expression} to be {not}close to {:?}\n within a margin of epsilon={:e} and ulps={}\n but was: {marked_actual}\n expected: {marked_expected}", + format!( + "expected {expression} to be {not}close to {:?}\n within a margin of epsilon={:e} and ulps={}\n but was: {marked_actual}\n expected: {marked_expected}", &self.expected, self.margin.epsilon, self.margin.ulps ) } @@ -194,7 +195,8 @@ mod cmp { ) -> String { let not = if inverted { "not " } else { "" }; let (marked_actual, marked_expected) = mark_diff(actual, &self.expected, format); - format!("expected {expression} to be {not}close to {:?}\n within a margin of epsilon={:e} and ulps={}\n but was: {marked_actual}\n expected: {marked_expected}", + format!( + "expected {expression} to be {not}close to {:?}\n within a margin of epsilon={:e} and ulps={}\n but was: {marked_actual}\n expected: {marked_expected}", &self.expected, self.margin.epsilon, self.margin.ulps ) } diff --git a/src/iterator/mod.rs b/src/iterator/mod.rs index aa4cbdb..eb18dfd 100644 --- a/src/iterator/mod.rs +++ b/src/iterator/mod.rs @@ -9,15 +9,15 @@ use crate::colored::{ mark_selected_items_in_collection, mark_unexpected, mark_unexpected_string, }; use crate::expectations::{ - all_satisfy, any_satisfies, has_at_least_number_of_elements, has_single_element, + AllSatisfy, AnySatisfies, HasAtLeastNumberOfElements, HasSingleElement, IteratorContains, + IteratorContainsAllInOrder, IteratorContainsAllOf, IteratorContainsAnyOf, + IteratorContainsExactly, IteratorContainsExactlyInAnyOrder, IteratorContainsOnly, + IteratorContainsOnlyOnce, IteratorContainsSequence, IteratorEndsWith, IteratorStartsWith, + NoneSatisfies, all_satisfy, any_satisfies, has_at_least_number_of_elements, has_single_element, iterator_contains, iterator_contains_all_in_order, iterator_contains_all_of, iterator_contains_any_of, iterator_contains_exactly, iterator_contains_exactly_in_any_order, iterator_contains_only, iterator_contains_only_once, iterator_contains_sequence, - iterator_ends_with, iterator_starts_with, none_satisfies, not, AllSatisfy, AnySatisfies, - HasAtLeastNumberOfElements, HasSingleElement, IteratorContains, IteratorContainsAllInOrder, - IteratorContainsAllOf, IteratorContainsAnyOf, IteratorContainsExactly, - IteratorContainsExactlyInAnyOrder, IteratorContainsOnly, IteratorContainsOnlyOnce, - IteratorContainsSequence, IteratorEndsWith, IteratorStartsWith, NoneSatisfies, + iterator_ends_with, iterator_starts_with, none_satisfies, not, }; use crate::properties::DefinedOrderProperty; use crate::spec::{ diff --git a/src/length.rs b/src/length.rs index 863e057..845b7d0 100644 --- a/src/length.rs +++ b/src/length.rs @@ -3,9 +3,9 @@ use crate::assertions::{AssertEmptiness, AssertHasLength}; use crate::colored::{mark_missing, mark_unexpected}; use crate::expectations::{ - has_at_least_length, has_at_most_length, has_length, has_length_greater_than, - has_length_in_range, has_length_less_than, is_empty, not, HasAtLeastLength, HasAtMostLength, - HasLength, HasLengthGreaterThan, HasLengthInRange, HasLengthLessThan, IsEmpty, + HasAtLeastLength, HasAtMostLength, HasLength, HasLengthGreaterThan, HasLengthInRange, + HasLengthLessThan, IsEmpty, has_at_least_length, has_at_most_length, has_length, + has_length_greater_than, has_length_in_range, has_length_less_than, is_empty, not, }; use crate::properties::{IsEmptyProperty, LengthProperty}; use crate::spec::{DiffFormat, Expectation, Expression, FailingStrategy, Invertible, Spec}; @@ -48,7 +48,9 @@ where ("", "") }; let marked_actual = mark_unexpected(actual, format); - format!("expected {expression} to be {not}empty\n but was: {marked_actual}\n expected: {expected}") + format!( + "expected {expression} to be {not}empty\n but was: {marked_actual}\n expected: {expected}" + ) } } diff --git a/src/map/mod.rs b/src/map/mod.rs index f0c9beb..3f9e592 100644 --- a/src/map/mod.rs +++ b/src/map/mod.rs @@ -4,10 +4,10 @@ use crate::colored::{ mark_selected_items_in_collection, mark_unexpected_string, }; use crate::expectations::{ - map_contains_exactly_keys, map_contains_key, map_contains_keys, map_contains_value, - map_contains_values, map_does_not_contain_keys, map_does_not_contain_values, not, MapContainsExactlyKeys, MapContainsKey, MapContainsKeys, MapContainsValue, MapContainsValues, - MapDoesNotContainKeys, MapDoesNotContainValues, + MapDoesNotContainKeys, MapDoesNotContainValues, map_contains_exactly_keys, map_contains_key, + map_contains_keys, map_contains_value, map_contains_values, map_does_not_contain_keys, + map_does_not_contain_values, not, }; use crate::iterator::collect_selected_values; use crate::properties::MapProperties; @@ -92,7 +92,9 @@ where ("", all_entries_marked) }; let marked_expected = mark_missing(&self.expected_key, format); - format!("expected {expression} to {not}contain the key {expected_key:?}\n but was: {marked_actual}\n expected: {not}{marked_expected}") + format!( + "expected {expression} to {not}contain the key {expected_key:?}\n but was: {marked_actual}\n expected: {not}{marked_expected}" + ) } } @@ -328,7 +330,9 @@ where }; let marked_expected = mark_missing(&self.expected_value, format); - format!("expected {expression} to {not}contain the value {expected_value:?}\n but was: {marked_actual}\n expected: {not}{marked_expected}") + format!( + "expected {expression} to {not}contain the value {expected_value:?}\n but was: {marked_actual}\n expected: {not}{marked_expected}" + ) } } diff --git a/src/number.rs b/src/number.rs index 307bdf6..f38dbf7 100644 --- a/src/number.rs +++ b/src/number.rs @@ -5,9 +5,9 @@ use crate::assertions::{ }; use crate::colored::{mark_missing, mark_missing_string, mark_unexpected}; use crate::expectations::{ - has_precision_of, has_scale_of, is_a_number, is_finite, is_infinite, is_integer, is_negative, - is_one, is_positive, is_zero, not, HasPrecisionOf, HasScaleOf, IsANumber, IsFinite, IsInfinite, - IsInteger, IsNegative, IsOne, IsPositive, IsZero, + HasPrecisionOf, HasScaleOf, IsANumber, IsFinite, IsInfinite, IsInteger, IsNegative, IsOne, + IsPositive, IsZero, has_precision_of, has_scale_of, is_a_number, is_finite, is_infinite, + is_integer, is_negative, is_one, is_positive, is_zero, not, }; use crate::properties::{ AdditiveIdentityProperty, DecimalProperties, InfinityProperty, IsNanProperty, @@ -62,7 +62,9 @@ where }; let marked_actual = mark_unexpected(actual, format); let marked_expected = mark_missing_string(expected, format); - format!("expected {expression} to be {not}negative\n but was: {marked_actual}\n expected: {marked_expected}") + format!( + "expected {expression} to be {not}negative\n but was: {marked_actual}\n expected: {marked_expected}" + ) } } @@ -90,7 +92,9 @@ where }; let marked_actual = mark_unexpected(actual, format); let marked_expected = mark_missing_string(expected, format); - format!("expected {expression} to be {not}positive\n but was: {marked_actual}\n expected: {marked_expected}") + format!( + "expected {expression} to be {not}positive\n but was: {marked_actual}\n expected: {marked_expected}" + ) } } @@ -128,7 +132,9 @@ where let not = if inverted { "not " } else { "" }; let marked_actual = mark_unexpected(&actual, format); let marked_expected = mark_missing(&S::additive_identity(), format); - format!("expected {expression} to be {not}zero\n but was: {marked_actual}\n expected: {not}{marked_expected}") + format!( + "expected {expression} to be {not}zero\n but was: {marked_actual}\n expected: {not}{marked_expected}" + ) } } @@ -152,7 +158,9 @@ where let not = if inverted { "not " } else { "" }; let marked_actual = mark_unexpected(actual, format); let marked_expected = mark_missing(&S::multiplicative_identity(), format); - format!("expected {expression} to be {not}one\n but was: {marked_actual}\n expected: {not}{marked_expected}") + format!( + "expected {expression} to be {not}one\n but was: {marked_actual}\n expected: {not}{marked_expected}" + ) } } @@ -194,7 +202,9 @@ where }; let marked_actual = mark_unexpected(actual, format); let marked_expected = mark_missing_string(expected, format); - format!("expected {expression} to be {not}finite\n but was: {marked_actual}\n expected: {marked_expected}") + format!( + "expected {expression} to be {not}finite\n but was: {marked_actual}\n expected: {marked_expected}" + ) } } @@ -222,7 +232,9 @@ where }; let marked_actual = mark_unexpected(actual, format); let marked_expected = mark_missing_string(expected, format); - format!("expected {expression} to be {not}infinite\n but was: {marked_actual}\n expected: {marked_expected}") + format!( + "expected {expression} to be {not}infinite\n but was: {marked_actual}\n expected: {marked_expected}" + ) } } @@ -264,7 +276,9 @@ where }; let marked_actual = mark_unexpected(actual, format); let marked_expected = mark_missing_string(expected, format); - format!("expected {expression} to be {not}a number\n but was: {marked_actual}\n expected: {marked_expected}") + format!( + "expected {expression} to be {not}a number\n but was: {marked_actual}\n expected: {marked_expected}" + ) } } @@ -307,7 +321,9 @@ where let expected_scale = self.expected_scale; let marked_actual = mark_unexpected(&actual.scale_property(), format); let marked_expected = mark_missing(&expected_scale, format); - format!("expected {expression} to {not}have a scale of {expected_scale}\n but was: {marked_actual}\n expected: {not}{marked_expected}") + format!( + "expected {expression} to {not}have a scale of {expected_scale}\n but was: {marked_actual}\n expected: {not}{marked_expected}" + ) } } @@ -332,7 +348,9 @@ where let expected_precision = self.expected_precision; let marked_actual = mark_unexpected(&actual.precision_property(), format); let marked_expected = mark_missing(&expected_precision, format); - format!("expected {expression} to {not}have a precision of {expected_precision}\n but was: {marked_actual}\n expected: {not}{marked_expected}") + format!( + "expected {expression} to {not}have a precision of {expected_precision}\n but was: {marked_actual}\n expected: {not}{marked_expected}" + ) } } @@ -358,6 +376,8 @@ where }; let marked_actual = mark_unexpected(&actual, format); let marked_expected = mark_missing_string(expected, format); - format!("expected {expression} to be {not}an integer value\n but was: {marked_actual}\n expected: {marked_expected}") + format!( + "expected {expression} to be {not}an integer value\n but was: {marked_actual}\n expected: {marked_expected}" + ) } } diff --git a/src/option/mod.rs b/src/option/mod.rs index 1ef06b9..5c2d938 100644 --- a/src/option/mod.rs +++ b/src/option/mod.rs @@ -4,7 +4,7 @@ use crate::assertions::{ AssertBorrowedOptionValue, AssertHasValue, AssertOption, AssertOptionValue, }; use crate::colored::{mark_missing, mark_unexpected}; -use crate::expectations::{has_value, is_none, is_some, HasValue, IsNone, IsSome}; +use crate::expectations::{HasValue, IsNone, IsSome, has_value, is_none, is_some}; use crate::spec::{ DiffFormat, Expectation, Expression, FailingStrategy, Invertible, Spec, Unknown, }; @@ -201,7 +201,9 @@ where let expected = &self.expected; let marked_actual = mark_unexpected(actual, format); let marked_expected = mark_missing(&Some(expected), format); - format!("expected {expression} to be some {not}containing {expected:?}\n but was: {marked_actual}\n expected: {not}{marked_expected}") + format!( + "expected {expression} to be some {not}containing {expected:?}\n but was: {marked_actual}\n expected: {not}{marked_expected}" + ) } } diff --git a/src/order/mod.rs b/src/order/mod.rs index f78a8f5..63c906d 100644 --- a/src/order/mod.rs +++ b/src/order/mod.rs @@ -3,8 +3,8 @@ use crate::assertions::AssertOrder; use crate::colored::{mark_missing, mark_unexpected}; use crate::expectations::{ - is_after, is_at_least, is_at_most, is_before, is_between, is_greater_than, is_less_than, - IsAfter, IsAtLeast, IsAtMost, IsBefore, IsBetween, IsGreaterThan, IsLessThan, + IsAfter, IsAtLeast, IsAtMost, IsBefore, IsBetween, IsGreaterThan, IsLessThan, is_after, + is_at_least, is_at_most, is_before, is_between, is_greater_than, is_less_than, }; use crate::spec::{DiffFormat, Expectation, Expression, FailingStrategy, Invertible, Spec}; use crate::std::fmt::Debug; diff --git a/src/panic/mod.rs b/src/panic/mod.rs index 7a08cd6..ff8df1b 100644 --- a/src/panic/mod.rs +++ b/src/panic/mod.rs @@ -2,7 +2,7 @@ use crate::assertions::AssertCodePanics; use crate::colored::{mark_missing_string, mark_unexpected_string}; -use crate::expectations::{does_not_panic, does_panic, DoesNotPanic, DoesPanic}; +use crate::expectations::{DoesNotPanic, DoesPanic, does_not_panic, does_panic}; use crate::spec::{Code, DiffFormat, Expectation, Expression, FailingStrategy, Spec}; use crate::std::any::Any; use crate::std::panic; @@ -114,14 +114,18 @@ where } else if let Some(expected_message) = &self.expected_message { let marked_expected_message = mark_missing_string(expected_message, format); let marked_actual_message = mark_unexpected_string(actual_message, format); - format!("expected {expression} to panic with message {expected_message:?}\n but was: \"{marked_actual_message}\"\n expected: \"{marked_expected_message}\"") + format!( + "expected {expression} to panic with message {expected_message:?}\n but was: \"{marked_actual_message}\"\n expected: \"{marked_expected_message}\"" + ) } else { // should be unreachable format!("expected {expression} to panic, but did not panic") } } else if let Some(expected_message) = &self.expected_message { let marked_did_not_panic = mark_unexpected_string("did not panic", format); - format!("expected {expression} to panic with message {expected_message:?},\n but {marked_did_not_panic}") + format!( + "expected {expression} to panic with message {expected_message:?},\n but {marked_did_not_panic}" + ) } else { let marked_did_not_panic = mark_unexpected_string("did not panic", format); format!("expected {expression} to panic, but {marked_did_not_panic}") diff --git a/src/prelude.rs b/src/prelude.rs index e900534..88a8464 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -20,8 +20,8 @@ pub use super::{ colored::{DEFAULT_DIFF_FORMAT, DIFF_FORMAT_NO_HIGHLIGHT}, properties::*, spec::{ - assert_that, verify_that, CollectFailures, DoFail, GetFailures, Location, PanicOnFail, - SoftPanic, + CollectFailures, DoFail, GetFailures, Location, PanicOnFail, SoftPanic, assert_that, + verify_that, }, verify_that, }; diff --git a/src/range/mod.rs b/src/range/mod.rs index f3711c8..22b5727 100644 --- a/src/range/mod.rs +++ b/src/range/mod.rs @@ -2,7 +2,7 @@ use crate::assertions::AssertInRange; use crate::colored::{mark_missing, mark_missing_string, mark_unexpected}; -use crate::expectations::{is_in_range, not, IsInRange}; +use crate::expectations::{IsInRange, is_in_range, not}; use crate::properties::IsEmptyProperty; use crate::spec::{DiffFormat, Expectation, Expression, FailingStrategy, Invertible, Spec}; use crate::std::fmt::Debug; diff --git a/src/recursive_comparison/serialize/mod.rs b/src/recursive_comparison/serialize/mod.rs index f7048ec..d432947 100644 --- a/src/recursive_comparison/serialize/mod.rs +++ b/src/recursive_comparison/serialize/mod.rs @@ -9,7 +9,7 @@ use crate::std::string::{String, ToString}; use crate::std::vec; use crate::std::vec::Vec; use serde_core::ser::Error as SerdeError; -use serde_core::{ser, Serialize, Serializer}; +use serde_core::{Serialize, Serializer, ser}; /// Serializes the given object of some type into a [`Value`]. The given type /// must implement [`serde::Serialize`]. diff --git a/src/recursive_comparison/serialize/tests.rs b/src/recursive_comparison/serialize/tests.rs index 8d0221e..741a3e5 100644 --- a/src/recursive_comparison/serialize/tests.rs +++ b/src/recursive_comparison/serialize/tests.rs @@ -1,8 +1,8 @@ use super::*; use crate::recursive_comparison::value::{ - self, bool, char, field, float32, float64, int128, int16, int32, int64, int8, isize, map, none, - seq, some, string, struct_, struct_variant, tuple, tuple_struct, tuple_variant, uint128, - uint16, uint32, uint64, uint8, unit, unit_struct, unit_variant, usize, + self, bool, char, field, float32, float64, int8, int16, int32, int64, int128, isize, map, none, + seq, some, string, struct_, struct_variant, tuple, tuple_struct, tuple_variant, uint8, uint16, + uint32, uint64, uint128, unit, unit_struct, unit_variant, usize, }; use crate::std::string::ToString; use indexmap::IndexMap; diff --git a/src/recursive_comparison/tests.rs b/src/recursive_comparison/tests.rs index 2d77416..3ac7d59 100644 --- a/src/recursive_comparison/tests.rs +++ b/src/recursive_comparison/tests.rs @@ -327,8 +327,8 @@ fn struct_is_equal_to_using_recursive_comparison_ignoring_one_field_and_all_its_ } #[test] -fn verify_struct_is_equal_to_using_recursive_comparison_ignoring_one_field_and_all_its_subfields_fails( -) { +fn verify_struct_is_equal_to_using_recursive_comparison_ignoring_one_field_and_all_its_subfields_fails() + { let person = Person { id: 123, name: "Silvia".into(), @@ -416,8 +416,8 @@ fn struct_is_equal_to_using_recursive_comparison_ignoring_three_fields_repeated_ } #[test] -fn verify_struct_is_equal_to_using_recursive_comparison_ignoring_three_fields_repeated_method_calls_fails( -) { +fn verify_struct_is_equal_to_using_recursive_comparison_ignoring_three_fields_repeated_method_calls_fails() + { let person = Person { id: 123, name: "Silvia".into(), @@ -594,8 +594,8 @@ fn struct_is_equal_to_using_recursive_comparison_ignoring_id_fields_on_different } #[test] -fn verify_struct_is_equal_to_using_recursive_comparison_ignoring_id_fields_on_different_levels_fails( -) { +fn verify_struct_is_equal_to_using_recursive_comparison_ignoring_id_fields_on_different_levels_fails() + { let person = Person { id: 123, name: "Silvia".into(), @@ -956,8 +956,8 @@ fn struct_is_equivalent_to_struct_with_relevant_fields() { } #[test] -fn verify_struct_is_equivalent_to_struct_with_relevant_fields_do_not_ignore_not_expected_fields_fails( -) { +fn verify_struct_is_equivalent_to_struct_with_relevant_fields_do_not_ignore_not_expected_fields_fails() + { let person = Person { id: 456, name: "Silvia".into(), diff --git a/src/recursive_comparison/value/mod.rs b/src/recursive_comparison/value/mod.rs index cf2943d..aca61f1 100644 --- a/src/recursive_comparison/value/mod.rs +++ b/src/recursive_comparison/value/mod.rs @@ -13,7 +13,7 @@ use crate::std::string::{String, ToString}; use crate::std::vec::Vec; use crate::std::{format, vec}; pub use map::Map; -pub use number::{Number, F32, F64}; +pub use number::{F32, F64, Number}; /// Represents a field in a struct, tuple, or enum. #[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] diff --git a/src/recursive_comparison/value/proptest_support.rs b/src/recursive_comparison/value/proptest_support.rs index 1458674..7036e3a 100644 --- a/src/recursive_comparison/value/proptest_support.rs +++ b/src/recursive_comparison/value/proptest_support.rs @@ -3,7 +3,7 @@ //! This module mainly provides methods that provide [`Strategy`]s for //! generating arbitrary values of type [`Value`] and [`Number`]. -use crate::recursive_comparison::value::{Number, Value, F32, F64}; +use crate::recursive_comparison::value::{F32, F64, Number, Value}; use crate::std::string::String; use crate::std::vec; use proptest::prelude::*; diff --git a/src/result/mod.rs b/src/result/mod.rs index 155c098..bdc3d59 100644 --- a/src/result/mod.rs +++ b/src/result/mod.rs @@ -6,7 +6,7 @@ use crate::assertions::{ }; use crate::colored::{mark_missing, mark_unexpected}; use crate::expectations::{ - has_error, has_value, is_equal_to, is_err, is_ok, HasError, HasValue, IsErr, IsOk, + HasError, HasValue, IsErr, IsOk, has_error, has_value, is_equal_to, is_err, is_ok, }; use crate::spec::{ DiffFormat, Expectation, Expression, FailingStrategy, Invertible, Spec, Unknown, diff --git a/src/slice/tests.rs b/src/slice/tests.rs index 1b073ea..c1ecb30 100644 --- a/src/slice/tests.rs +++ b/src/slice/tests.rs @@ -933,14 +933,17 @@ mod colored { .contains_exactly_in_any_order(&[1, 2, 3, 13, 8, 7, 12, 15, 31, 19, 20, 11, 31]) .display_failures(); - assert_eq!(failures, &[ - "expected subject to contain exactly in any order [1, 2, 3, 13, 8, 7, 12, 15, 31, 19, 20, 11, 31]\n \ + assert_eq!( + failures, + &[ + "expected subject to contain exactly in any order [1, 2, 3, 13, 8, 7, 12, 15, 31, 19, 20, 11, 31]\n \ but was: [13, \u{1b}[31m5\u{1b}[0m, 7, 19, 1, 3, 11, \u{1b}[31m29\u{1b}[0m, \u{1b}[31m23\u{1b}[0m, 31, \u{1b}[31m37\u{1b}[0m]\n \ expected: [1, \u{1b}[34m2\u{1b}[0m, 3, 13, \u{1b}[34m8\u{1b}[0m, 7, \u{1b}[34m12\u{1b}[0m, \u{1b}[34m15\u{1b}[0m, 31, 19, \u{1b}[34m20\u{1b}[0m, 11, \u{1b}[34m31\u{1b}[0m]\n \ missing: [2, 8, 12, 15, 20, 31]\n \ extra: [5, 29, 23, 37]\n\ " - ]); + ] + ); } #[test] @@ -952,12 +955,15 @@ mod colored { .contains_any_of(&[2, 4, 6, 8, 9, 10, 12, 15, 32, 20, 18]) .display_failures(); - assert_eq!(failures, &[ - "expected subject to contain any of [2, 4, 6, 8, 9, 10, 12, 15, 32, 20, 18]\n \ + assert_eq!( + failures, + &[ + "expected subject to contain any of [2, 4, 6, 8, 9, 10, 12, 15, 32, 20, 18]\n \ but was: [\u{1b}[31m13\u{1b}[0m, \u{1b}[31m5\u{1b}[0m, \u{1b}[31m7\u{1b}[0m, \u{1b}[31m19\u{1b}[0m, \u{1b}[31m1\u{1b}[0m, \u{1b}[31m3\u{1b}[0m, \u{1b}[31m11\u{1b}[0m, \u{1b}[31m29\u{1b}[0m, \u{1b}[31m23\u{1b}[0m, \u{1b}[31m31\u{1b}[0m, \u{1b}[31m37\u{1b}[0m]\n \ expected: [\u{1b}[34m2\u{1b}[0m, \u{1b}[34m4\u{1b}[0m, \u{1b}[34m6\u{1b}[0m, \u{1b}[34m8\u{1b}[0m, \u{1b}[34m9\u{1b}[0m, \u{1b}[34m10\u{1b}[0m, \u{1b}[34m12\u{1b}[0m, \u{1b}[34m15\u{1b}[0m, \u{1b}[34m32\u{1b}[0m, \u{1b}[34m20\u{1b}[0m, \u{1b}[34m18\u{1b}[0m]\n\ " - ]); + ] + ); } #[test] @@ -969,12 +975,15 @@ mod colored { .does_not_contain_any_of(&[2, 4, 6, 8, 9, 10, 11, 15, 32, 20, 18]) .display_failures(); - assert_eq!(failures, &[ - "expected subject to not contain any of [2, 4, 6, 8, 9, 10, 11, 15, 32, 20, 18]\n \ + assert_eq!( + failures, + &[ + "expected subject to not contain any of [2, 4, 6, 8, 9, 10, 11, 15, 32, 20, 18]\n \ but was: [13, 5, 7, 19, \u{1b}[31m11\u{1b}[0m, \u{1b}[31m11\u{1b}[0m, 3, \u{1b}[31m11\u{1b}[0m, 29, 23, 31, 37]\n \ expected: not [2, 4, 6, 8, 9, 10, \u{1b}[34m11\u{1b}[0m, 15, 32, 20, 18]\n\ " - ]); + ] + ); } #[test] @@ -986,13 +995,16 @@ mod colored { .contains_all_of(&[2, 3, 5, 20, 11, 13, 19, 37, 22]) .display_failures(); - assert_eq!(failures, &[ - "expected subject to contain all of [2, 3, 5, 20, 11, 13, 19, 37, 22]\n \ + assert_eq!( + failures, + &[ + "expected subject to contain all of [2, 3, 5, 20, 11, 13, 19, 37, 22]\n \ but was: [13, 5, \u{1b}[31m7\u{1b}[0m, 19, \u{1b}[31m1\u{1b}[0m, 3, 11, \u{1b}[31m29\u{1b}[0m, \u{1b}[31m23\u{1b}[0m, \u{1b}[31m31\u{1b}[0m, 37]\n \ expected: [\u{1b}[34m2\u{1b}[0m, 3, 5, \u{1b}[34m20\u{1b}[0m, 11, 13, 19, 37, \u{1b}[34m22\u{1b}[0m]\n \ missing: [2, 20, 22]\n\ " - ]); + ] + ); } #[test] @@ -1004,13 +1016,16 @@ mod colored { .contains_only(&[13, 3, 5, 20, 11, 13, 19, 37, 22]) .display_failures(); - assert_eq!(failures, &[ - "expected subject to contain only [13, 3, 5, 20, 11, 13, 19, 37, 22]\n \ + assert_eq!( + failures, + &[ + "expected subject to contain only [13, 3, 5, 20, 11, 13, 19, 37, 22]\n \ but was: [13, 5, \u{1b}[31m7\u{1b}[0m, 19, \u{1b}[31m1\u{1b}[0m, 3, 11, \u{1b}[31m29\u{1b}[0m, \u{1b}[31m23\u{1b}[0m, \u{1b}[31m31\u{1b}[0m, 37]\n \ expected: [13, 3, 5, \u{1b}[34m20\u{1b}[0m, 11, 13, 19, 37, \u{1b}[34m22\u{1b}[0m]\n \ extra: [7, 1, 29, 23, 31]\n\ " - ]); + ] + ); } #[test] @@ -1044,15 +1059,18 @@ mod colored { .contains_exactly(&[13, 20, 5, 19, 11, 29, 8, 1, 23, 31, 41]) .display_failures(); - assert_eq!(failures, &[ - "expected subject to contain exactly in order [13, 20, 5, 19, 11, 29, 8, 1, 23, 31, 41]\n \ + assert_eq!( + failures, + &[ + "expected subject to contain exactly in order [13, 20, 5, 19, 11, 29, 8, 1, 23, 31, 41]\n \ but was: [13, \u{1b}[31m5\u{1b}[0m, \u{1b}[31m7\u{1b}[0m, 19, \u{1b}[31m1\u{1b}[0m, \u{1b}[31m3\u{1b}[0m, \u{1b}[31m11\u{1b}[0m, \u{1b}[31m29\u{1b}[0m, 23, 31, \u{1b}[31m37\u{1b}[0m]\n \ expected: [13, \u{1b}[33m20\u{1b}[0m, \u{1b}[33m5\u{1b}[0m, 19, \u{1b}[33m11\u{1b}[0m, \u{1b}[33m29\u{1b}[0m, \u{1b}[33m8\u{1b}[0m, \u{1b}[33m1\u{1b}[0m, 23, 31, \u{1b}[33m41\u{1b}[0m]\n \ missing: [20, 8, 41]\n \ extra: [7, 3, 37]\n \ out-of-order: [5, 1, 11, 29]\n\ " - ]); + ] + ); } #[test] @@ -1109,14 +1127,12 @@ mod colored { assert_eq!( failures, - &[ - "expected subject to start with [13, 5, 8, 19, 4]\n \ + &["expected subject to start with [13, 5, 8, 19, 4]\n \ but was: [13, 5, \u{1b}[31m7\u{1b}[0m, 19, \u{1b}[31m1\u{1b}[0m, 3, 11, 29, 23, 31, 37]\n \ expected: [13, 5, \u{1b}[33m8\u{1b}[0m, 19, \u{1b}[33m4\u{1b}[0m]\n \ missing: [8, 4]\n \ extra: [7, 1]\n\ - " - ] + "] ); } @@ -1131,14 +1147,12 @@ mod colored { assert_eq!( failures, - &[ - "expected subject to end with [3, 11, 28, 29, 30, 37]\n \ + &["expected subject to end with [3, 11, 28, 29, 30, 37]\n \ but was: [13, 5, 7, 19, 1, 3, 11, \u{1b}[31m29\u{1b}[0m, \u{1b}[31m23\u{1b}[0m, \u{1b}[31m31\u{1b}[0m, 37]\n \ expected: [3, 11, \u{1b}[33m28\u{1b}[0m, \u{1b}[33m29\u{1b}[0m, \u{1b}[33m30\u{1b}[0m, 37]\n \ missing: [28, 29, 30]\n \ extra: [29, 23, 31]\n\ - " - ] + "] ); } } diff --git a/src/string/mod.rs b/src/string/mod.rs index 1c10265..dca10b7 100644 --- a/src/string/mod.rs +++ b/src/string/mod.rs @@ -7,8 +7,8 @@ use crate::colored::{ mark_unexpected_char_in_string, mark_unexpected_string, mark_unexpected_substring_in_string, }; use crate::expectations::{ - not, string_contains, string_contains_any_of, string_ends_with, string_starts_with, - StringContains, StringContainsAnyOf, StringEndsWith, StringStartWith, + StringContains, StringContainsAnyOf, StringEndsWith, StringStartWith, not, string_contains, + string_contains_any_of, string_ends_with, string_starts_with, }; use crate::properties::{CharCountProperty, DefinedOrderProperty, IsEmptyProperty, LengthProperty}; use crate::spec::{DiffFormat, Expectation, Expression, FailingStrategy, Invertible, Spec}; @@ -702,7 +702,7 @@ impl Invertible for StringContainsAnyOf<&[char; N]> {} mod regex { use crate::assertions::AssertStringMatches; use crate::colored::{mark_missing_string, mark_unexpected_string}; - use crate::expectations::{not, string_matches, StringMatches}; + use crate::expectations::{StringMatches, not, string_matches}; use crate::spec::{DiffFormat, Expectation, Expression, FailingStrategy, Invertible, Spec}; use crate::std::fmt::Debug; use crate::std::format; @@ -745,7 +745,9 @@ mod regex { let regex = self.regex.as_str(); let marked_actual = mark_unexpected_string(actual.as_ref(), format); let marked_expected = mark_missing_string(regex, format); - format!("expected {expression} to {not}match the regex {regex}\n but was: {marked_actual}\n {does_not_match} regex: {marked_expected}") + format!( + "expected {expression} to {not}match the regex {regex}\n but was: {marked_actual}\n {does_not_match} regex: {marked_expected}" + ) } }