Skip to content

Commit

Permalink
fix(read_span): prevent multilines MietteSpanContents from skipping l…
Browse files Browse the repository at this point in the history
…ines (#81)

Fixes: #76
  • Loading branch information
towaanu authored and zkat committed Oct 6, 2021
1 parent 6fc4fb0 commit cb5a919
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/source_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ fn context_info<'a>(

if offset >= (span.offset() + span.len()).saturating_sub(1) {
let starting_offset = before_lines_starts.get(0).copied().unwrap_or_else(|| {
if line_count > 0 {
if context_lines_before == 0 {
span.offset()
} else {
0
Expand Down Expand Up @@ -268,4 +268,19 @@ mod tests {
assert_eq!(&span, contents.span());
Ok(())
}

#[test]
fn multiline_with_context_line_start() -> Result<(), MietteError> {
let src = String::from("one\ntwo\n\nthree\nfour\nfive\n\nsix\nseven\n");
let contents = src.read_span(&(2, 0).into(), 2, 2)?;
assert_eq!(
"one\ntwo\n\n",
std::str::from_utf8(contents.data()).unwrap()
);
assert_eq!(0, contents.line());
assert_eq!(0, contents.column());
let span: SourceSpan = (0, 9).into();
assert_eq!(&span, contents.span());
Ok(())
}
}

0 comments on commit cb5a919

Please sign in to comment.