mirror of https://github.com/zkat/miette.git
fix(graphical): Fix panic when span covers full line
This was introduced in 196c09ce7a, and is
a simple off-by-one error.
This commit is contained in:
parent
ac02a1242b
commit
64781c7fcc
|
|
@ -618,7 +618,7 @@ impl GraphicalReportHandler {
|
|||
|
||||
/// Returns the visual column position of a byte offset on a specific line.
|
||||
fn visual_offset(&self, line: &Line, offset: usize) -> usize {
|
||||
let line_range = line.offset..(line.offset + line.length);
|
||||
let line_range = line.offset..=(line.offset + line.length);
|
||||
assert!(line_range.contains(&offset));
|
||||
|
||||
let text = &line.text[..offset - line.offset];
|
||||
|
|
|
|||
|
|
@ -67,6 +67,38 @@ fn empty_source() -> Result<(), MietteError> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn full_line_span() {
|
||||
#[derive(Error, Debug, Diagnostic)]
|
||||
#[error("oops!")]
|
||||
#[diagnostic(severity(Error))]
|
||||
struct MyBad {
|
||||
#[source_code]
|
||||
src: NamedSource,
|
||||
#[label("This bit here")]
|
||||
bad_bit: SourceSpan,
|
||||
}
|
||||
let err = MyBad {
|
||||
src: NamedSource::new("issue", "source\ntext"),
|
||||
bad_bit: (7, 4).into(),
|
||||
};
|
||||
let out = fmt_report(err.into());
|
||||
println!("Error: {}", out);
|
||||
|
||||
let expected = r#"
|
||||
× oops!
|
||||
╭─[issue:1:1]
|
||||
1 │ source
|
||||
2 │ text
|
||||
· ──┬─
|
||||
· ╰── This bit here
|
||||
╰────
|
||||
"#
|
||||
.to_string();
|
||||
|
||||
assert_eq!(expected, out);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn single_line_with_wide_char() -> Result<(), MietteError> {
|
||||
#[derive(Debug, Diagnostic, Error)]
|
||||
|
|
|
|||
Loading…
Reference in New Issue