Skip to content

Commit

Permalink
fix(ad) #13 correctly reading range dots
Browse files Browse the repository at this point in the history
  • Loading branch information
sminez committed Sep 8, 2024
1 parent aa60e21 commit 5ba7139
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/dot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl Dot {

pub fn as_char_indices(&self) -> (usize, usize) {
match *self {
Self::Cur { c: Cur { idx } } => (idx, idx + 1),
Self::Cur { c: Cur { idx } } => (idx, idx),
Self::Range {
r:
Range {
Expand Down Expand Up @@ -86,7 +86,7 @@ impl Dot {
}

let (from, to) = self.as_char_indices();
b.txt.slice(from, min(to, len_chars)).to_string()
b.txt.slice(from, min(to + 1, len_chars)).to_string()
}

#[inline]
Expand Down Expand Up @@ -242,4 +242,20 @@ The third paragraph is even shorter.";

assert_eq!(b.dot, expected);
}

#[test_case(c(0, 0), "T"; "first character")]
#[test_case(r(0, 0, 0, 34), "This is the first line of the file."; "first sentence")]
#[test_case(
r(0, 0, 1, 18),
"This is the first line of the file. Followed\nby the second line.";
"spanning a newline"
)]
#[test]
fn content_includes_expected_text(dot: Dot, expected: &str) {
let mut b = Buffer::new_virtual(0, "test".to_string(), EXAMPLE_TEXT.to_string());
b.dot = dot;
let content = b.dot_contents();

assert_eq!(content, expected);
}
}

0 comments on commit 5ba7139

Please sign in to comment.