diff --git a/src/spec/mod.rs b/src/spec/mod.rs index 8cfc59e..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; @@ -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 {