Skip to content

Commit 4680ba8

Browse files
committed
test: Add a test for Message before primary Snippet
1 parent dc65194 commit 4680ba8

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

tests/formatter.rs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3075,3 +3075,77 @@ error[E0277]: the size for values of type `T` cannot be known at compilation tim
30753075
let renderer = Renderer::plain();
30763076
assert_data_eq!(renderer.render(input_new), expected);
30773077
}
3078+
3079+
#[test]
3080+
fn message_before_primary_snippet() {
3081+
let source = r#"struct Thing {
3082+
a0: Foo,
3083+
a1: Foo,
3084+
a2: Foo,
3085+
a3: Foo,
3086+
a4: Foo,
3087+
a5: Foo,
3088+
a6: Foo,
3089+
a7: Foo,
3090+
a8: Foo,
3091+
a9: Foo,
3092+
}
3093+
3094+
struct Foo {
3095+
field: Field,
3096+
}
3097+
3098+
struct Field;
3099+
3100+
impl Foo {
3101+
fn bar(&self) {}
3102+
}
3103+
3104+
fn bar(t: Thing) {
3105+
t.bar();
3106+
t.field;
3107+
}
3108+
3109+
fn main() {}
3110+
"#;
3111+
3112+
let input = &[Group::with_title(
3113+
Level::ERROR
3114+
.title("no field `field` on type `Thing`")
3115+
.id("E0609"),
3116+
)
3117+
.element(Level::NOTE.message("a `Title` then a `Message`!?!?"))
3118+
.element(
3119+
Snippet::source(source)
3120+
.path("$DIR/too-many-field-suggestions.rs")
3121+
.annotation(
3122+
AnnotationKind::Primary
3123+
.span(270..275)
3124+
.label("unknown field"),
3125+
),
3126+
)];
3127+
3128+
let expected_ascii = str![[r#"
3129+
error[E0609]: no field `field` on type `Thing`
3130+
|
3131+
= note: a `Title` then a `Message`!?!?
3132+
--> $DIR/too-many-field-suggestions.rs:26:7
3133+
|
3134+
LL | t.field;
3135+
| ^^^^^ unknown field
3136+
"#]];
3137+
let renderer = Renderer::plain().anonymized_line_numbers(true);
3138+
assert_data_eq!(renderer.render(input), expected_ascii);
3139+
3140+
let expected_unicode = str![[r#"
3141+
error[E0609]: no field `field` on type `Thing`
3142+
3143+
├ note: a `Title` then a `Message`!?!?
3144+
╭▸ $DIR/too-many-field-suggestions.rs:26:7
3145+
3146+
LL │ t.field;
3147+
╰╴ ━━━━━ unknown field
3148+
"#]];
3149+
let renderer = renderer.theme(OutputTheme::Unicode);
3150+
assert_data_eq!(renderer.render(input), expected_unicode);
3151+
}

0 commit comments

Comments
 (0)