From 3e1ae5fadf250c5183653dc5d9db2ca79ecffd7d Mon Sep 17 00:00:00 2001 From: Peter Hill Date: Wed, 20 Nov 2024 10:42:45 +0000 Subject: [PATCH] feat: Add `Level::None` for no title prefix --- src/renderer/display_list.rs | 1 + src/snippet.rs | 1 + tests/formatter.rs | 25 +++++++++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/src/renderer/display_list.rs b/src/renderer/display_list.rs index 8884b0d..061b3a1 100644 --- a/src/renderer/display_list.rs +++ b/src/renderer/display_list.rs @@ -914,6 +914,7 @@ impl From for DisplayAnnotationType { snippet::Level::Info => DisplayAnnotationType::Info, snippet::Level::Note => DisplayAnnotationType::Note, snippet::Level::Help => DisplayAnnotationType::Help, + snippet::Level::None => DisplayAnnotationType::None, } } } diff --git a/src/snippet.rs b/src/snippet.rs index 8e9a3a8..48cb1a4 100644 --- a/src/snippet.rs +++ b/src/snippet.rs @@ -133,6 +133,7 @@ pub enum Level { Info, Note, Help, + None, } impl Level { diff --git a/tests/formatter.rs b/tests/formatter.rs index 6faab76..542b10b 100644 --- a/tests/formatter.rs +++ b/tests/formatter.rs @@ -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); +}