|
| 1 | +use annotate_snippets::{renderer::DecorStyle, AnnotationKind, Level, Patch, Renderer, Snippet}; |
| 2 | + |
| 3 | +use snapbox::{assert_data_eq, file}; |
| 4 | + |
| 5 | +#[test] |
| 6 | +fn case() { |
| 7 | + // https://github.com/rust-lang/rust/blob/4b94758d2ba7d0ef71ccf5fde29ce4bc5d6fe2a4/tests/ui/argument-suggestions/wrong-highlight-span-extra-arguments-147070.rs |
| 8 | + |
| 9 | + let source = r#"struct Thingie; |
| 10 | +
|
| 11 | +impl Thingie { |
| 12 | + pub(crate) fn new( |
| 13 | + _a: String, |
| 14 | + _b: String, |
| 15 | + _c: String, |
| 16 | + _d: String, |
| 17 | + _e: String, |
| 18 | + _f: String, |
| 19 | + ) -> Self { |
| 20 | + unimplemented!() |
| 21 | + } |
| 22 | +} |
| 23 | +
|
| 24 | +fn main() { |
| 25 | + let foo = Thingie::new( |
| 26 | + String::from(""), |
| 27 | + String::from(""), |
| 28 | + String::from(""), |
| 29 | + String::from(""), |
| 30 | + String::from(""), |
| 31 | + String::from(""), |
| 32 | + String::from(""), |
| 33 | + ); |
| 34 | +}"#; |
| 35 | + |
| 36 | + let path = "$DIR/wrong-highlight-span-extra-arguments-147070.rs"; |
| 37 | + |
| 38 | + let report = &[ |
| 39 | + Level::ERROR |
| 40 | + .primary_title("this function takes 6 arguments but 7 arguments were supplied") |
| 41 | + .id("E0061") |
| 42 | + .element( |
| 43 | + Snippet::source(source) |
| 44 | + .path(path) |
| 45 | + .annotation( |
| 46 | + AnnotationKind::Context |
| 47 | + .span(429..445) |
| 48 | + .label("unexpected argument #7 of type `String`"), |
| 49 | + ) |
| 50 | + .annotation(AnnotationKind::Primary.span(251..263)), |
| 51 | + ), |
| 52 | + Level::NOTE |
| 53 | + .secondary_title("associated function defined here") |
| 54 | + .element( |
| 55 | + Snippet::source(source) |
| 56 | + .path(path) |
| 57 | + .annotation(AnnotationKind::Primary.span(50..53)), |
| 58 | + ), |
| 59 | + Level::HELP |
| 60 | + .secondary_title("remove the extra argument") |
| 61 | + .element( |
| 62 | + Snippet::source(source) |
| 63 | + .path(path) |
| 64 | + .patch(Patch::new(419..445, "")), |
| 65 | + ), |
| 66 | + ]; |
| 67 | + |
| 68 | + let expected_ascii = file!["highlight_duplicated_diff_lines.ascii.term.svg": TermSvg]; |
| 69 | + let renderer = Renderer::styled(); |
| 70 | + assert_data_eq!(renderer.render(report), expected_ascii); |
| 71 | + |
| 72 | + let expected_unicode = file!["highlight_duplicated_diff_lines.unicode.term.svg": TermSvg]; |
| 73 | + let renderer = renderer.decor_style(DecorStyle::Unicode); |
| 74 | + assert_data_eq!(renderer.render(report), expected_unicode); |
| 75 | +} |
0 commit comments