Make BlockMap unit test pass with 2d coordinates

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Antonio Scandurra 2021-11-15 16:30:58 +01:00
parent 3154ccbafe
commit 296944e34d
3 changed files with 127 additions and 82 deletions

View file

@ -23,6 +23,15 @@ impl Point {
Point::new(0, 0)
}
pub fn from_str(s: &str) -> Self {
let mut point = Self::zero();
for (row, line) in s.split('\n').enumerate() {
point.row = row as u32;
point.column = line.len() as u32;
}
point
}
pub fn is_zero(&self) -> bool {
self.row == 0 && self.column == 0
}

View file

@ -3,7 +3,7 @@ use crate::PointUtf16;
use super::Point;
use arrayvec::ArrayString;
use smallvec::SmallVec;
use std::{cmp, fmt, ops::Range, str};
use std::{cmp, fmt, mem, ops::Range, str};
use sum_tree::{Bias, Dimension, SumTree};
#[cfg(test)]
@ -89,6 +89,21 @@ impl Rope {
self.check_invariants();
}
pub fn push_front(&mut self, text: &str) {
let suffix = mem::replace(self, Rope::from(text));
self.append(suffix);
}
pub fn starts_with(&self, text: &str) -> bool {
self.chunks().flat_map(|c| c.bytes()).eq(text.bytes())
}
pub fn ends_with(&self, text: &str) -> bool {
self.reversed_chunks_in_range(0..self.len())
.flat_map(|c| c.bytes().rev())
.eq(text.bytes().rev())
}
fn check_invariants(&self) {
#[cfg(test)]
{