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
25 changes: 25 additions & 0 deletions src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -627,6 +628,30 @@ impl OwnedLocation {
}
}

impl PartialEq<Location<'_>> for OwnedLocation {
fn eq(&self, other: &Location<'_>) -> bool {
self.as_location() == *other
}
}

impl PartialEq<OwnedLocation> for Location<'_> {
fn eq(&self, other: &OwnedLocation) -> bool {
self == &other.as_location()
}
}

impl PartialOrd<Location<'_>> for OwnedLocation {
fn partial_cmp(&self, other: &Location<'_>) -> Option<Ordering> {
self.as_location().partial_cmp(other)
}
}

impl PartialOrd<OwnedLocation> for Location<'_> {
fn partial_cmp(&self, other: &OwnedLocation) -> Option<Ordering> {
self.partial_cmp(&other.as_location())
}
}

/// Data of an actual assertion.
///
/// It holds the data needed to execute an assertion such as the subject,
Expand Down
28 changes: 28 additions & 0 deletions src/spec/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading