Skip to content

Commit 410ed62

Browse files
committed
test: Add initial test for hyperlink support
1 parent 1bd5ae2 commit 410ed62

3 files changed

Lines changed: 116 additions & 0 deletions

File tree

tests/hyperlink.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
use annotate_snippets::{AnnotationKind, Level, Renderer, Snippet, renderer::DecorStyle};
2+
use snapbox::{assert_data_eq, file};
3+
4+
#[test]
5+
fn simple() {
6+
// Most basic test: check that the a hyperlink shows up in the error message displayed in the
7+
// README.
8+
let source = r#" annotations: vec![SourceAnnotation {
9+
label: "expected struct `annotate_snippets::snippet::Slice`, found reference"
10+
,
11+
range: <22, 25>,"#;
12+
let report =
13+
&[Level::ERROR
14+
.primary_title("expected type, found `22`")
15+
.element(
16+
Snippet::source(source)
17+
.line_start(26)
18+
.path("examples/footer.rs")
19+
.annotation(AnnotationKind::Primary.span(193..195).label(
20+
"expected struct `annotate_snippets::snippet::Slice`, found reference",
21+
))
22+
.annotation(
23+
AnnotationKind::Context
24+
.span(34..50)
25+
.label("while parsing this struct"),
26+
),
27+
)];
28+
29+
let expected_ascii = file!["hyperlink_expected_type.ascii.term.svg": TermSvg];
30+
let renderer = Renderer::styled().decor_style(DecorStyle::Ascii);
31+
assert_data_eq!(renderer.render(report), expected_ascii);
32+
33+
let expected_unicode = file!["hyperlink_expected_type.unicode.term.svg": TermSvg];
34+
let renderer = Renderer::styled().decor_style(DecorStyle::Unicode);
35+
assert_data_eq!(renderer.render(report), expected_unicode);
36+
}
Lines changed: 40 additions & 0 deletions
Loading
Lines changed: 40 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)