crates: vendor annotate-snippets crate

This merely adds the crate to our repository. Some cosmetic changes are
made to make it work in our repo and follow our conventions, such as
changing the name to `ruff_annotate_snippets`. We retain the original
license information. We do drop some things, such as benchmarks, but
keep tests and examples.
This commit is contained in:
Andrew Gallant 2024-12-20 12:55:16 -05:00 committed by Andrew Gallant
parent 4f3209a3ec
commit 9c27c57b5b
58 changed files with 6171 additions and 8 deletions

View file

@ -0,0 +1,42 @@
mod deserialize;
use crate::deserialize::Fixture;
use ruff_annotate_snippets::{Message, Renderer};
use snapbox::data::DataFormat;
use snapbox::Data;
use std::error::Error;
fn main() {
#[cfg(not(windows))]
tryfn::Harness::new("tests/fixtures/", setup, test)
.select(["*/*.toml"])
.test();
}
fn setup(input_path: std::path::PathBuf) -> tryfn::Case {
let parent = input_path
.parent()
.unwrap()
.file_name()
.unwrap()
.to_str()
.unwrap();
let file_name = input_path.file_name().unwrap().to_str().unwrap();
let name = format!("{parent}/{file_name}");
let expected = Data::read_from(&input_path.with_extension("svg"), None);
tryfn::Case {
name,
fixture: input_path,
expected,
}
}
fn test(input_path: &std::path::Path) -> Result<Data, Box<dyn Error>> {
let src = std::fs::read_to_string(input_path)?;
let fixture: Fixture = toml::from_str(&src)?;
let renderer: Renderer = fixture.renderer.into();
let message: Message<'_> = (&fixture.message).into();
let actual = renderer.render(message).to_string();
Ok(Data::from(actual).coerce_to(DataFormat::TermSvg))
}