Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/bigdecimal/tests.rs
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion src/boolean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
38 changes: 27 additions & 11 deletions src/char/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -102,7 +102,9 @@ impl Expectation<char> 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}"
)
}
}

Expand Down Expand Up @@ -143,7 +145,9 @@ impl Expectation<char> 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}"
)
}
}

Expand Down Expand Up @@ -179,7 +183,9 @@ impl Expectation<char> 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"
)
}
}

Expand Down Expand Up @@ -215,7 +221,9 @@ impl Expectation<char> 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"
)
}
}

Expand Down Expand Up @@ -251,7 +259,9 @@ impl Expectation<char> 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"
)
}
}

Expand Down Expand Up @@ -287,7 +297,9 @@ impl Expectation<char> 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"
)
}
}

Expand Down Expand Up @@ -324,7 +336,9 @@ impl Expectation<char> 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}"
)
}
}

Expand Down Expand Up @@ -360,7 +374,9 @@ impl Expectation<char> 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"
)
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/char_count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
4 changes: 2 additions & 2 deletions src/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
4 changes: 2 additions & 2 deletions src/colored/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
25 changes: 14 additions & 11 deletions src/colored/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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);

Expand All @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions src/equality.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
14 changes: 10 additions & 4 deletions src/error/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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}"
)
}
}

Expand Down Expand Up @@ -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}"
)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/expectation_combinators/tests.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
8 changes: 5 additions & 3 deletions src/float/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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
)
}
Expand All @@ -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
)
}
Expand Down
12 changes: 6 additions & 6 deletions src/iterator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down
10 changes: 6 additions & 4 deletions src/length.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -48,7 +48,9 @@ where
("", "<empty>")
};
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}"
)
}
}

Expand Down
Loading
Loading