From 4fc816cc2c0ae028f82d4e7f6d8c3e702a989e94 Mon Sep 17 00:00:00 2001 From: haraldmaida Date: Sun, 12 Jul 2026 09:54:12 +0200 Subject: [PATCH 1/2] feat: make `OwnedLocation` comparable to `Location` and vice versa --- src/spec/mod.rs | 25 +++++++++++++++++++++++++ src/spec/tests.rs | 28 ++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/src/spec/mod.rs b/src/spec/mod.rs index 8cfc59e..75739a1 100644 --- a/src/spec/mod.rs +++ b/src/spec/mod.rs @@ -18,6 +18,7 @@ use crate::std::vec; use crate::std::vec::Vec; #[cfg(feature = "panic")] use crate::std::{cell::RefCell, rc::Rc}; +use std::cmp::Ordering; /// Starts an assertion for the given subject or expression in the /// [`PanicOnFail`] mode. @@ -627,6 +628,30 @@ impl OwnedLocation { } } +impl PartialEq> for OwnedLocation { + fn eq(&self, other: &Location<'_>) -> bool { + self.as_location() == *other + } +} + +impl PartialEq for Location<'_> { + fn eq(&self, other: &OwnedLocation) -> bool { + self == &other.as_location() + } +} + +impl PartialOrd> for OwnedLocation { + fn partial_cmp(&self, other: &Location<'_>) -> Option { + self.as_location().partial_cmp(other) + } +} + +impl PartialOrd for Location<'_> { + fn partial_cmp(&self, other: &OwnedLocation) -> Option { + self.partial_cmp(&other.as_location()) + } +} + /// Data of an actual assertion. /// /// It holds the data needed to execute an assertion such as the subject, diff --git a/src/spec/tests.rs b/src/spec/tests.rs index f54af04..d9cd0e0 100644 --- a/src/spec/tests.rs +++ b/src/spec/tests.rs @@ -51,6 +51,34 @@ fn owned_location_can_be_referenced_as_location() { }); } +#[test] +fn can_check_equality_of_owned_location_and_location() { + let owned_location = OwnedLocation::new("src/my_module/my_test.rs", 54, 13); + + assert_that!(owned_location).is_equal_to(Location::new("src/my_module/my_test.rs", 54, 13)); +} + +#[test] +fn can_check_equality_of_location_and_owned_location() { + let location = Location::new("src/my_module/my_test.rs", 54, 13); + + assert_that!(location).is_equal_to(OwnedLocation::new("src/my_module/my_test.rs", 54, 13)); +} + +#[test] +fn can_compare_owned_location_to_location() { + let owned_location = OwnedLocation::new("src/my_module/my_test.rs", 54, 13); + + assert_that!(owned_location).is_less_than(Location::new("src/my_module/my_test.rs", 55, 4)); +} + +#[test] +fn can_compare_location_to_owned_location() { + let location = Location::new("src/my_module/my_test.rs", 54, 13); + + assert_that!(location).is_greater_than(OwnedLocation::new("src/my_module/my_test.rs", 53, 38)); +} + #[test] fn assert_failure_display_format() { let failure = AssertFailure { From 7da9e36cc93247f49494c8572065d1f1a7333ffe Mon Sep 17 00:00:00 2001 From: haraldmaida Date: Sun, 12 Jul 2026 10:13:21 +0200 Subject: [PATCH 2/2] bug: fix compile error for no-std environment --- src/spec/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spec/mod.rs b/src/spec/mod.rs index 75739a1..6043fda 100644 --- a/src/spec/mod.rs +++ b/src/spec/mod.rs @@ -8,6 +8,7 @@ use crate::expectations::satisfies; use crate::recursive_comparison::RecursiveComparison; use crate::std::any; use crate::std::borrow::{Borrow, Cow, ToOwned}; +use crate::std::cmp::Ordering; use crate::std::error::Error as StdError; use crate::std::fmt::{self, Debug, Display}; use crate::std::format; @@ -18,7 +19,6 @@ use crate::std::vec; use crate::std::vec::Vec; #[cfg(feature = "panic")] use crate::std::{cell::RefCell, rc::Rc}; -use std::cmp::Ordering; /// Starts an assertion for the given subject or expression in the /// [`PanicOnFail`] mode.