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
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -364,10 +364,10 @@ for types that implement `std::error::Error`.

for types that implement `core::fmt::Debug`:

| assertion | description |
|-----------------------------|----------------------------------------------------------------------------|
| has_debug_message | verify that a type formatted for debug is equal to the expected string |
| does_not_have_debug_message | verify that a type formatted for debug is not equal to the expected string |
| assertion | description |
|----------------------------|----------------------------------------------------------------------------|
| has_debug_string | verify that a type formatted for debug is equal to the expected string |
| does_not_have_debug_string | verify that a type formatted for debug is not equal to the expected string |

for types that implement `core::fmt::Display`:

Expand Down
14 changes: 7 additions & 7 deletions src/assertions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2287,10 +2287,10 @@ pub trait AssertErrorHasSource<'a, R> {
///
/// let subject = Foo { hello: "World".into() };
///
/// assert_that!(&subject).has_debug_message("Foo { hello: \"World\" }");
/// assert_that!(&subject).does_not_have_debug_message("Bar { hello: \"World\" }");
/// assert_that!(&subject).has_debug_string("Foo { hello: \"World\" }");
/// assert_that!(&subject).does_not_have_debug_string("Bar { hello: \"World\" }");
/// ```
pub trait AssertHasDebugMessage<E> {
pub trait AssertHasDebugString<E> {
/// Verifies that a subject formatted for debugging results in the expected
/// string.
///
Expand All @@ -2306,10 +2306,10 @@ pub trait AssertHasDebugMessage<E> {
///
/// let subject = Foo { hello: "World".into() };
///
/// assert_that!(subject).has_debug_message("Foo { hello: \"World\" }");
/// assert_that!(subject).has_debug_string("Foo { hello: \"World\" }");
/// ```
#[track_caller]
fn has_debug_message(self, expected: E) -> Self;
fn has_debug_string(self, expected: E) -> Self;

/// Verifies that a subject formatted for debugging does not result in the
/// expected string.
Expand All @@ -2326,10 +2326,10 @@ pub trait AssertHasDebugMessage<E> {
///
/// let subject = Foo { hello: "World".into() };
///
/// assert_that!(subject).does_not_have_debug_message("Hello World");
/// assert_that!(subject).does_not_have_debug_string("Hello World");
/// ```
#[track_caller]
fn does_not_have_debug_message(self, expected: E) -> Self;
fn does_not_have_debug_string(self, expected: E) -> Self;
}

/// Assert a type formatted into a display string.
Expand Down
20 changes: 10 additions & 10 deletions src/equality.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//! Implementation of the equality assertions.

use crate::assertions::{
AssertEquality, AssertHasDebugMessage, AssertHasDisplayMessage, AssertSameAs,
AssertEquality, AssertHasDebugString, AssertHasDisplayMessage, AssertSameAs,
};
use crate::colored::{mark_diff, mark_diff_str};
use crate::expectations::{
has_debug_message, has_display_message, is_equal_to, is_same_as, not, HasDebugMessage,
has_debug_string, has_display_message, is_equal_to, is_same_as, not, HasDebugString,
HasDisplayMessage, IsEqualTo, IsSameAs,
};
use crate::spec::{DiffFormat, Expectation, Expression, FailingStrategy, Invertible, Spec};
Expand Down Expand Up @@ -95,22 +95,22 @@ where

impl<E> Invertible for IsSameAs<E> {}

impl<S, E, R> AssertHasDebugMessage<E> for Spec<'_, S, R>
impl<S, E, R> AssertHasDebugString<E> for Spec<'_, S, R>
where
S: Debug,
E: AsRef<str>,
R: FailingStrategy,
{
fn has_debug_message(self, expected: E) -> Self {
self.expecting(has_debug_message(expected))
fn has_debug_string(self, expected: E) -> Self {
self.expecting(has_debug_string(expected))
}

fn does_not_have_debug_message(self, expected: E) -> Self {
self.expecting(not(has_debug_message(expected)))
fn does_not_have_debug_string(self, expected: E) -> Self {
self.expecting(not(has_debug_string(expected)))
}
}

impl<S, E> Expectation<S> for HasDebugMessage<E>
impl<S, E> Expectation<S> for HasDebugString<E>
where
S: Debug,
E: AsRef<str>,
Expand All @@ -131,12 +131,12 @@ where
let (marked_actual, marked_expected) =
mark_diff_str(&format!("{actual:?}"), expected, format);
format!(
"expected {expression} to {not}have debug message {expected:?}\n but was: {marked_actual}\n expected: {not}{marked_expected}",
"expected {expression} to {not}have a debug string equal to {expected:?}\n but was: {marked_actual}\n expected: {not}{marked_expected}",
)
}
}

impl<E> Invertible for HasDebugMessage<E> {}
impl<E> Invertible for HasDebugString<E> {}

impl<S, E, R> AssertHasDisplayMessage<E> for Spec<'_, S, R>
where
Expand Down
20 changes: 10 additions & 10 deletions src/error/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,28 @@ impl Display for SourceError {
impl Error for SourceError {}

#[test]
fn error_has_debug_message() {
fn error_has_debug_string() {
let error = SuperError {
source: SourceError::Bar,
};

assert_that(error).has_debug_message("SuperError { source: Bar }");
assert_that(error).has_debug_string("SuperError { source: Bar }");
}

#[test]
fn verify_error_has_debug_message_fails() {
fn verify_error_has_debug_string_fails() {
let error = SuperError {
source: SourceError::Foo,
};

let failures = verify_that(error)
.has_debug_message("SuperError { source: Bar }")
.has_debug_string("SuperError { source: Bar }")
.display_failures();

assert_eq!(
failures,
&[
r#"expected subject to have debug message "SuperError { source: Bar }"
r#"expected subject to have a debug string equal to "SuperError { source: Bar }"
but was: SuperError { source: Foo }
expected: SuperError { source: Bar }
"#
Expand All @@ -68,28 +68,28 @@ fn verify_error_has_debug_message_fails() {
}

#[test]
fn error_does_not_have_debug_message() {
fn error_does_not_have_debug_string() {
let error = SuperError {
source: SourceError::Bar,
};

assert_that(error).does_not_have_debug_message("SuperError { source: Foo }");
assert_that(error).does_not_have_debug_string("SuperError { source: Foo }");
}

#[test]
fn verify_error_does_not_have_debug_message_fails() {
fn verify_error_does_not_have_debug_string_fails() {
let error = SuperError {
source: SourceError::Bar,
};

let failures = verify_that(error)
.does_not_have_debug_message("SuperError { source: Bar }")
.does_not_have_debug_string("SuperError { source: Bar }")
.display_failures();

assert_eq!(
failures,
&[
r#"expected subject to not have debug message "SuperError { source: Bar }"
r#"expected subject to not have a debug string equal to "SuperError { source: Bar }"
but was: SuperError { source: Bar }
expected: not SuperError { source: Bar }
"#
Expand Down
8 changes: 4 additions & 4 deletions src/expectations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -637,12 +637,12 @@ pub struct ErrorHasSourceMessage {
pub expected_source_message: String,
}

/// Creates a [`HasDebugMessage`] expectation.
pub fn has_debug_message<E>(expected: E) -> HasDebugMessage<E> {
HasDebugMessage { expected }
/// Creates a [`HasDebugString`] expectation.
pub fn has_debug_string<E>(expected: E) -> HasDebugString<E> {
HasDebugString { expected }
}

pub struct HasDebugMessage<E> {
pub struct HasDebugString<E> {
pub expected: E,
}

Expand Down
Loading