Skip to content

Commit 17ae038

Browse files
test: add more tests
1 parent e9e1c43 commit 17ae038

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

src/write.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,64 @@ mod tests {
840840
"###)
841841
}
842842

843+
#[test]
844+
fn span_numbers_are_char_offsets() {
845+
let source = "🍎 == apple";
846+
let msg = Report::<Range<usize>>::build(ReportKind::Error, (), 0)
847+
.with_config(no_color_and_ascii())
848+
.with_label(Label::new(2..4).with_message("comparison operator"))
849+
.finish()
850+
.write_to_string(Source::from(source));
851+
assert_snapshot!(msg, @r###"
852+
Error:
853+
,-[<unknown>:1:1]
854+
|
855+
1 | 🍎 == apple
856+
| ^|
857+
| `-- comparison operator
858+
---'
859+
"###);
860+
}
861+
862+
#[test]
863+
fn empty_label() {
864+
let source = "apple";
865+
let msg = Report::<Range<usize>>::build(ReportKind::Error, (), 0)
866+
.with_config(no_color_and_ascii())
867+
.with_label(Label::new(0..0).with_message("first character"))
868+
.finish()
869+
.write_to_string(Source::from(source));
870+
assert_snapshot!(msg, @r###"
871+
Error:
872+
,-[<unknown>:1:1]
873+
|
874+
1 | apple
875+
| |
876+
| `- first character
877+
---'
878+
"###);
879+
}
880+
881+
#[test]
882+
fn one_char_label() {
883+
let source = "apple";
884+
let msg = Report::<Range<usize>>::build(ReportKind::Error, (), 0)
885+
.with_config(no_color_and_ascii())
886+
.with_label(Label::new(0..1).with_message("first character"))
887+
.finish()
888+
.write_to_string(Source::from(source));
889+
// TODO: it would be nice if this rendered just like the empty_label test
890+
assert_snapshot!(msg, @r###"
891+
Error:
892+
,-[<unknown>:1:1]
893+
|
894+
1 | apple
895+
| |
896+
| `-- first character
897+
---'
898+
"###);
899+
}
900+
843901
#[test]
844902
fn two_labels_without_messages() {
845903
let source = "apple == orange;";

0 commit comments

Comments
 (0)