ruff/crates/ruff_annotate_snippets/tests/fixtures/main.rs
Andrew Gallant 9c27c57b5b 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.
2025-01-15 13:37:52 -05:00

42 lines
1.2 KiB
Rust

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))
}