diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /vendor/annotate-snippets-0.8.0/tests/fixtures | |
parent | Initial commit. (diff) | |
download | rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip |
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
11 files changed, 219 insertions, 0 deletions
diff --git a/vendor/annotate-snippets-0.8.0/tests/fixtures/no-color/multiline_annotation.toml b/vendor/annotate-snippets-0.8.0/tests/fixtures/no-color/multiline_annotation.toml new file mode 100644 index 000000000..bdb577f46 --- /dev/null +++ b/vendor/annotate-snippets-0.8.0/tests/fixtures/no-color/multiline_annotation.toml @@ -0,0 +1,40 @@ +[[slices]] +source = """ +) -> Option<String> { + for ann in annotations { + match (ann.range.0, ann.range.1) { + (None, None) => continue, + (Some(start), Some(end)) if start > end_index || end < start_index => continue, + (Some(start), Some(end)) if start >= start_index && end <= end_index => { + let label = if let Some(ref label) = ann.label { + format!(" {}", label) + } else { + String::from("") + }; + + return Some(format!( + "{}{}{}", + " ".repeat(start - start_index), + "^".repeat(end - start), + label + )); + } + _ => continue, + } + } +""" +line_start = 51 +origin = "src/format.rs" +fold = true +[[slices.annotations]] +label = "expected `std::option::Option<std::string::String>` because of return type" +annotation_type = "Warning" +range = [5, 19] +[[slices.annotations]] +label = "expected enum `std::option::Option`, found ()" +annotation_type = "Error" +range = [22, 765] +[title] +label = "mismatched types" +id = "E0308" +annotation_type = "Error" diff --git a/vendor/annotate-snippets-0.8.0/tests/fixtures/no-color/multiline_annotation.txt b/vendor/annotate-snippets-0.8.0/tests/fixtures/no-color/multiline_annotation.txt new file mode 100644 index 000000000..bacdec10d --- /dev/null +++ b/vendor/annotate-snippets-0.8.0/tests/fixtures/no-color/multiline_annotation.txt @@ -0,0 +1,14 @@ +error[E0308]: mismatched types + --> src/format.rs:51:6 + | +51 | ) -> Option<String> { + | -------------- expected `std::option::Option<std::string::String>` because of return type +52 | / for ann in annotations { +53 | | match (ann.range.0, ann.range.1) { +54 | | (None, None) => continue, +55 | | (Some(start), Some(end)) if start > end_index || end < start_index => continue, +... | +71 | | } +72 | | } + | |_____^ expected enum `std::option::Option`, found () + | diff --git a/vendor/annotate-snippets-0.8.0/tests/fixtures/no-color/multiline_annotation2.toml b/vendor/annotate-snippets-0.8.0/tests/fixtures/no-color/multiline_annotation2.toml new file mode 100644 index 000000000..6ec0b1fe8 --- /dev/null +++ b/vendor/annotate-snippets-0.8.0/tests/fixtures/no-color/multiline_annotation2.toml @@ -0,0 +1,18 @@ +[[slices]] +source = """ + if let DisplayLine::Source { + ref mut inline_marks, + } = body[body_idx] +""" +line_start = 139 +origin = "src/display_list.rs" +fold = false +[[slices.annotations]] +label = "missing fields `lineno`, `content`" +annotation_type = "Error" +range = [31, 127] + +[title] +label = "pattern does not mention fields `lineno`, `content`" +id = "E0027" +annotation_type = "Error" diff --git a/vendor/annotate-snippets-0.8.0/tests/fixtures/no-color/multiline_annotation2.txt b/vendor/annotate-snippets-0.8.0/tests/fixtures/no-color/multiline_annotation2.txt new file mode 100644 index 000000000..8a00bfa20 --- /dev/null +++ b/vendor/annotate-snippets-0.8.0/tests/fixtures/no-color/multiline_annotation2.txt @@ -0,0 +1,9 @@ +error[E0027]: pattern does not mention fields `lineno`, `content` + --> src/display_list.rs:139:32 + | +139 | if let DisplayLine::Source { + | ________________________________^ +140 | | ref mut inline_marks, +141 | | } = body[body_idx] + | |_________________________^ missing fields `lineno`, `content` + | diff --git a/vendor/annotate-snippets-0.8.0/tests/fixtures/no-color/multiline_annotation3.toml b/vendor/annotate-snippets-0.8.0/tests/fixtures/no-color/multiline_annotation3.toml new file mode 100644 index 000000000..21bbcd857 --- /dev/null +++ b/vendor/annotate-snippets-0.8.0/tests/fixtures/no-color/multiline_annotation3.toml @@ -0,0 +1,18 @@ +[[slices]] +source = """ +This is an exampl +e of an edge case of an annotation overflowing +to exactly one character on next line. +""" +line_start = 26 +origin = "foo.txt" +fold = false +[[slices.annotations]] +label = "this should not be on separate lines" +annotation_type = "Error" +range = [11, 18] + +[title] +label = "spacing error found" +id = "E####" +annotation_type = "Error" diff --git a/vendor/annotate-snippets-0.8.0/tests/fixtures/no-color/multiline_annotation3.txt b/vendor/annotate-snippets-0.8.0/tests/fixtures/no-color/multiline_annotation3.txt new file mode 100644 index 000000000..12e174c56 --- /dev/null +++ b/vendor/annotate-snippets-0.8.0/tests/fixtures/no-color/multiline_annotation3.txt @@ -0,0 +1,9 @@ +error[E####]: spacing error found + --> foo.txt:26:12 + | +26 | This is an exampl + | ____________^ +27 | | e of an edge case of an annotation overflowing + | |_^ this should not be on separate lines +28 | to exactly one character on next line. + |
\ No newline at end of file diff --git a/vendor/annotate-snippets-0.8.0/tests/fixtures/no-color/multiple_annotations.toml b/vendor/annotate-snippets-0.8.0/tests/fixtures/no-color/multiple_annotations.toml new file mode 100644 index 000000000..84efc5f17 --- /dev/null +++ b/vendor/annotate-snippets-0.8.0/tests/fixtures/no-color/multiple_annotations.toml @@ -0,0 +1,25 @@ +[[slices]] +source = """ +fn add_title_line(result: &mut Vec<String>, main_annotation: Option<&Annotation>) { + if let Some(annotation) = main_annotation { + result.push(format_title_line( + &annotation.annotation_type, + None, + &annotation.label, + )); + } +} +""" +line_start = 96 +[[slices.annotations]] +label = "Variable defined here" +annotation_type = "Error" +range = [100, 110] +[[slices.annotations]] +label = "Referenced here" +annotation_type = "Error" +range = [184, 194] +[[slices.annotations]] +label = "Referenced again here" +annotation_type = "Error" +range = [243, 253] diff --git a/vendor/annotate-snippets-0.8.0/tests/fixtures/no-color/multiple_annotations.txt b/vendor/annotate-snippets-0.8.0/tests/fixtures/no-color/multiple_annotations.txt new file mode 100644 index 000000000..26c677f7e --- /dev/null +++ b/vendor/annotate-snippets-0.8.0/tests/fixtures/no-color/multiple_annotations.txt @@ -0,0 +1,14 @@ + | + 96 | fn add_title_line(result: &mut Vec<String>, main_annotation: Option<&Annotation>) { + 97 | if let Some(annotation) = main_annotation { + | ^^^^^^^^^^ Variable defined here + 98 | result.push(format_title_line( + 99 | &annotation.annotation_type, + | ^^^^^^^^^^ Referenced here +100 | None, +101 | &annotation.label, + | ^^^^^^^^^^ Referenced again here +102 | )); +103 | } +104 | } + | diff --git a/vendor/annotate-snippets-0.8.0/tests/fixtures/no-color/simple.toml b/vendor/annotate-snippets-0.8.0/tests/fixtures/no-color/simple.toml new file mode 100644 index 000000000..6c38674ac --- /dev/null +++ b/vendor/annotate-snippets-0.8.0/tests/fixtures/no-color/simple.toml @@ -0,0 +1,18 @@ +[[slices]] +source = """ + }) + + for line in &self.body {""" +line_start = 169 +origin = "src/format_color.rs" +[[slices.annotations]] +label = "unexpected token" +annotation_type = "Error" +range = [20, 23] +[[slices.annotations]] +label = "expected one of `.`, `;`, `?`, or an operator here" +annotation_type = "Warning" +range = [10, 11] +[title] +label = "expected one of `.`, `;`, `?`, or an operator, found `for`" +annotation_type = "Error" diff --git a/vendor/annotate-snippets-0.8.0/tests/fixtures/no-color/simple.txt b/vendor/annotate-snippets-0.8.0/tests/fixtures/no-color/simple.txt new file mode 100644 index 000000000..752cc890f --- /dev/null +++ b/vendor/annotate-snippets-0.8.0/tests/fixtures/no-color/simple.txt @@ -0,0 +1,9 @@ +error: expected one of `.`, `;`, `?`, or an operator, found `for` + --> src/format_color.rs:171:9 + | +169 | }) + | - expected one of `.`, `;`, `?`, or an operator here +170 | +171 | for line in &self.body { + | ^^^ unexpected token + | diff --git a/vendor/annotate-snippets-0.8.0/tests/fixtures_test.rs b/vendor/annotate-snippets-0.8.0/tests/fixtures_test.rs new file mode 100644 index 000000000..e471521f2 --- /dev/null +++ b/vendor/annotate-snippets-0.8.0/tests/fixtures_test.rs @@ -0,0 +1,45 @@ +mod diff; +mod snippet; + +use crate::snippet::SnippetDef; +use annotate_snippets::{display_list::DisplayList, snippet::Snippet}; +use glob::glob; +use std::{error::Error, fs::File, io, io::prelude::*}; + +fn read_file(path: &str) -> Result<String, io::Error> { + let mut f = File::open(path)?; + let mut s = String::new(); + (f.read_to_string(&mut s))?; + Ok(s.trim_end().to_string()) +} + +fn read_fixture<'de>(src: &'de str) -> Result<Snippet<'de>, Box<dyn Error>> { + Ok(toml::from_str(src).map(|a: SnippetDef| a.into())?) +} + +#[test] +fn test_fixtures() { + for entry in glob("./tests/fixtures/no-color/**/*.toml").expect("Failed to read glob pattern") { + let p = entry.expect("Error while getting an entry"); + + let path_in = p.to_str().expect("Can't print path"); + let path_out = path_in.replace(".toml", ".txt"); + + let src = read_file(&path_in).expect("Failed to read file"); + let snippet = read_fixture(&src).expect("Failed to read file"); + let expected_out = read_file(&path_out).expect("Failed to read file"); + + let dl = DisplayList::from(snippet); + let actual_out = dl.to_string(); + println!("{}", expected_out); + println!("{}", actual_out.trim_end()); + + assert_eq!( + expected_out, + actual_out.trim_end(), + "\n\n\nWhile parsing: {}\nThe diff is:\n\n\n{}\n\n\n", + path_in, + diff::get_diff(expected_out.as_str(), actual_out.as_str()) + ); + } +} |