Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 55 additions & 6 deletions src/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -706,11 +706,9 @@ impl<S: Span> Report<'_, S> {
// Arrows
for row in 0..line_labels.len() {
let line_label = &line_labels[row];
//No message to draw thus no arrow to draw
if line_label.label.display_info.msg.is_none() {
continue;
}
if !self.config.compact {
if (line_label.label.display_info.msg.is_some() || row == 0)
&& !self.config.compact
{
// Margin alternate
write_margin(
&mut w,
Expand Down Expand Up @@ -769,6 +767,11 @@ impl<S: Span> Report<'_, S> {
writeln!(w)?;
}

// No message to draw thus no arrow to draw
if line_label.label.display_info.msg.is_none() {
continue;
}

// Margin
write_margin(
&mut w,
Expand Down Expand Up @@ -947,12 +950,34 @@ mod tests {
.with_label(Label::new(9..15))
.finish()
.write_to_string(Source::from(source));
// TODO: it would be nice if these spans still showed up (like codespan-reporting does)
assert_snapshot!(msg, @r###"
Error: can't compare apples with oranges
,-[<unknown>:1:1]
|
1 | apple == orange;
| ^^^^^ ^^^^^^
---'
"###);
}

#[test]
fn two_labels_without_messages_on_different_lines() {
let source = "apple\n== orange;";
let msg = Report::<Range<usize>>::build(ReportKind::Error, (), 0)
.with_config(no_color_and_ascii())
.with_message("can't compare apples with oranges")
.with_label(Label::new(0..5))
.with_label(Label::new(9..15))
.finish()
.write_to_string(Source::from(source));
assert_snapshot!(msg, @r###"
Error: can't compare apples with oranges
,-[<unknown>:1:1]
|
1 | apple
| ^^^^^
2 | == orange;
| ^^^^^^
---'
"###);
}
Expand Down Expand Up @@ -981,6 +1006,30 @@ mod tests {
"###);
}

#[test]
fn two_labels_with_messages_on_different_lines() {
let source = "apple ==\norange;";
let msg = Report::<Range<usize>>::build(ReportKind::Error, (), 0)
.with_config(no_color_and_ascii())
.with_message("can't compare apples with oranges")
.with_label(Label::new(0..5).with_message("This is an apple"))
.with_label(Label::new(9..15).with_message("This is an orange"))
.finish()
.write_to_string(Source::from(source));
assert_snapshot!(msg, @r###"
Error: can't compare apples with oranges
,-[<unknown>:1:1]
|
1 | apple ==
| ^^|^^
| `---- This is an apple
2 | orange;
| ^^^|^^
| `---- This is an orange
---'
"###);
}

#[test]
fn multi_byte_chars() {
let source = "äpplë == örängë;";
Expand Down