aboutsummaryrefslogtreecommitdiff
path: root/helix-core/src/position.rs
blob: 8c82b83ba50f8317e6afee36e85794bb15e47aba (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/// Represents a single point in a text buffer. Zero indexed.
#[derive(Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct Position {
    pub row: usize,
    pub col: usize,
}

impl Position {
    pub fn new(row: usize, col: usize) -> Self {
        Self { row, col }
    }

    pub fn is_zero(self) -> bool {
        self.row == 0 && self.col == 0
    }
}

#[cfg(test)]
mod test {
    use super::*;

    #[test]
    fn test_ordering() {
        // (0, 5) is less than (1, 0 w v f)
        assert!(Position::new(0, 5) < Position::new(1, 0));
    }
}