From 7134bba1ca2fb98a8def05413e4c70a4c96fb14f Mon Sep 17 00:00:00 2001 From: Amejonah1200 Date: Sun, 6 Oct 2024 18:10:03 +0200 Subject: [PATCH] Add tests --- src/write.rs | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/src/write.rs b/src/write.rs index 67d4b17..3da65a5 100644 --- a/src/write.rs +++ b/src/write.rs @@ -1389,4 +1389,81 @@ mod tests { ---' "###) } + + #[test] + fn single_note_single_line() { + let source = "apple == orange;"; + let msg = Report::>::build(ReportKind::Error, (), 0) + .with_config(no_color_and_ascii()) + .with_message("can't compare apples with oranges") + .with_label(Label::new(0..15).with_message("This is a strange comparison")) + .with_note("No need to try, they can't be compared.") + .finish() + .write_to_string(Source::from(source)); + println!("{}", msg); + assert_snapshot!(msg, @r###" + Error: can't compare apples with oranges + ,-[:1:1] + | + 1 | apple == orange; + | ^^^^^^^|^^^^^^^ + | `--------- This is a strange comparison + | + | Note: No need to try, they can't be compared. + ---' + "###) + } + + fn multi_notes_single_lines() { + let source = "apple == orange;"; + let msg = Report::>::build(ReportKind::Error, (), 0) + .with_config(no_color_and_ascii()) + .with_message("can't compare apples with oranges") + .with_label(Label::new(0..15).with_message("This is a strange comparison")) + .with_note("No need to try, they can't be compared.") + .with_note("Yeah, really, please stop.") + .finish() + .write_to_string(Source::from(source)); + println!("{}", msg); + assert_snapshot!(msg, @r###" + Error: can't compare apples with oranges + ,-[:1:1] + | + 1 | apple == orange; + | ^^^^^^^|^^^^^^^ + | `--------- This is a strange comparison + | + | Note 1: No need to try, they can't be compared. + | + | Note 2: Yeah, really, please stop. + ---' + "###) + } + #[test] + fn multi_notes_multi_lines() { + let source = "apple == orange;"; + let msg = Report::>::build(ReportKind::Error, (), 0) + .with_config(no_color_and_ascii()) + .with_message("can't compare apples with oranges") + .with_label(Label::new(0..15).with_message("This is a strange comparison")) + .with_note("No need to try, they can't be compared.") + .with_note("Yeah, really, please stop.\nIt has no resemblance.") + .finish() + .write_to_string(Source::from(source)); + println!("{}", msg); + assert_snapshot!(msg, @r###" + Error: can't compare apples with oranges + ,-[:1:1] + | + 1 | apple == orange; + | ^^^^^^^|^^^^^^^ + | `--------- This is a strange comparison + | + | Note 1: No need to try, they can't be compared. + | + | Note 2: Yeah, really, please stop. + | It has no resemblance. + ---' + "###) + } }