From ea878f2d646a7ca43705d6de88325a33bc4e46ea Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Sun, 4 Sep 2022 16:31:34 -0400 Subject: [PATCH] Add PartialOrd to Location --- compiler/core/src/location.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/compiler/core/src/location.rs b/compiler/core/src/location.rs index fedcdcf746..73d6ec89d2 100644 --- a/compiler/core/src/location.rs +++ b/compiler/core/src/location.rs @@ -1,7 +1,7 @@ use serde::{Deserialize, Serialize}; /// Sourcecode location. -#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)] pub struct Location { pub(super) row: u32, pub(super) column: u32, @@ -59,3 +59,22 @@ impl Location { self.column = 1; } } + +#[cfg(test)] +mod tests { + use crate::Location; + + #[test] + fn test_gt() { + assert!(Location::new(1, 2) > Location::new(1, 1)); + assert!(Location::new(2, 1) > Location::new(1, 1)); + assert!(Location::new(2, 1) > Location::new(1, 2)); + } + + #[test] + fn test_lt() { + assert!(Location::new(1, 1) < Location::new(1, 2)); + assert!(Location::new(1, 1) < Location::new(2, 1)); + assert!(Location::new(1, 2) < Location::new(2, 1)); + } +}