Skip to content

Commit

Permalink
test: add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
not-my-profile committed Aug 30, 2023
1 parent e9e1c43 commit 17ae038
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions src/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,64 @@ mod tests {
"###)
}

#[test]
fn span_numbers_are_char_offsets() {
let source = "🍎 == apple";
let msg = Report::<Range<usize>>::build(ReportKind::Error, (), 0)
.with_config(no_color_and_ascii())
.with_label(Label::new(2..4).with_message("comparison operator"))
.finish()
.write_to_string(Source::from(source));
assert_snapshot!(msg, @r###"
Error:
,-[<unknown>:1:1]
|
1 | 🍎 == apple
| ^|
| `-- comparison operator
---'
"###);
}

#[test]
fn empty_label() {
let source = "apple";
let msg = Report::<Range<usize>>::build(ReportKind::Error, (), 0)
.with_config(no_color_and_ascii())
.with_label(Label::new(0..0).with_message("first character"))
.finish()
.write_to_string(Source::from(source));
assert_snapshot!(msg, @r###"
Error:
,-[<unknown>:1:1]
|
1 | apple
| |
| `- first character
---'
"###);
}

#[test]
fn one_char_label() {
let source = "apple";
let msg = Report::<Range<usize>>::build(ReportKind::Error, (), 0)
.with_config(no_color_and_ascii())
.with_label(Label::new(0..1).with_message("first character"))
.finish()
.write_to_string(Source::from(source));
// TODO: it would be nice if this rendered just like the empty_label test
assert_snapshot!(msg, @r###"
Error:
,-[<unknown>:1:1]
|
1 | apple
| |
| `-- first character
---'
"###);
}

#[test]
fn two_labels_without_messages() {
let source = "apple == orange;";
Expand Down

0 comments on commit 17ae038

Please sign in to comment.