Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit da92db4

Browse files
authored
Merge pull request #4149 from charliermarsh/charlie/location
Add PartialOrd to Location
2 parents fe10a4b + ea878f2 commit da92db4

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

compiler/core/src/location.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use serde::{Deserialize, Serialize};
22

33
/// Sourcecode location.
4-
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
4+
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
55
pub struct Location {
66
pub(super) row: u32,
77
pub(super) column: u32,
@@ -59,3 +59,22 @@ impl Location {
5959
self.column = 1;
6060
}
6161
}
62+
63+
#[cfg(test)]
64+
mod tests {
65+
use crate::Location;
66+
67+
#[test]
68+
fn test_gt() {
69+
assert!(Location::new(1, 2) > Location::new(1, 1));
70+
assert!(Location::new(2, 1) > Location::new(1, 1));
71+
assert!(Location::new(2, 1) > Location::new(1, 2));
72+
}
73+
74+
#[test]
75+
fn test_lt() {
76+
assert!(Location::new(1, 1) < Location::new(1, 2));
77+
assert!(Location::new(1, 1) < Location::new(2, 1));
78+
assert!(Location::new(1, 2) < Location::new(2, 1));
79+
}
80+
}

0 commit comments

Comments
 (0)