mirror of
https://github.com/RustPython/Parser.git
synced 2025-08-28 06:14:56 +00:00
Add PartialOrd to Location
This commit is contained in:
parent
b21ed24025
commit
26b529f9dc
1 changed files with 20 additions and 1 deletions
|
@ -1,7 +1,7 @@
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
/// Sourcecode location.
|
/// 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 struct Location {
|
||||||
pub(super) row: u32,
|
pub(super) row: u32,
|
||||||
pub(super) column: u32,
|
pub(super) column: u32,
|
||||||
|
@ -59,3 +59,22 @@ impl Location {
|
||||||
self.column = 1;
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue