Skip to content

Commit

Permalink
feat: Add Level::None for no title prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
ZedThree committed Nov 20, 2024
1 parent 40197bb commit 3e1ae5f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/renderer/display_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,7 @@ impl From<snippet::Level> for DisplayAnnotationType {
snippet::Level::Info => DisplayAnnotationType::Info,
snippet::Level::Note => DisplayAnnotationType::Note,
snippet::Level::Help => DisplayAnnotationType::Help,
snippet::Level::None => DisplayAnnotationType::None,
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/snippet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ pub enum Level {
Info,
Note,
Help,
None,
}

impl Level {
Expand Down
25 changes: 25 additions & 0 deletions tests/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -955,3 +955,28 @@ error: title
let renderer = Renderer::plain();
assert_data_eq!(renderer.render(input).to_string(), expected);
}

#[test]
fn level_none() {
let source = "aaa\nbbb\nccc\nddd\n";
let input = Level::None.title("title").snippet(
Snippet::source(source)
.origin("origin.txt")
.fold(false)
.annotation(Level::Error.span(8 + 1..8 + 3).label("annotation")),
);

let expected = str![[r#"
title
--> origin.txt:3:2
|
1 | aaa
2 | bbb
3 | ccc
| ^^ annotation
4 | ddd
|
"#]];
let renderer = Renderer::plain();
assert_data_eq!(renderer.render(input).to_string(), expected);
}

0 comments on commit 3e1ae5f

Please sign in to comment.