serde error testing

This commit is contained in:
Robin Appelman 2023-12-18 15:16:48 +01:00
commit 778696590a
5 changed files with 56 additions and 2 deletions

View file

@ -1,3 +1,4 @@
use miette::{GraphicalReportHandler, GraphicalTheme};
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
use std::fs::read_to_string;
@ -151,8 +152,17 @@ struct GameList {
#[test_case("tests/data/concrete.vmt")]
#[test_case("tests/data/messy.vdf")]
#[test_case("tests/data/DialogConfigOverlay_1280x720.vdf")]
#[test_case("tests/errors/concrete.vmt")]
#[test_case("tests/errors/novalue.vdf")]
fn test_serde(path: &str) {
let raw = read_to_string(path).unwrap();
let result: Expected = from_str(&raw).map_err(miette::Error::from).unwrap();
insta::assert_ron_snapshot!(path, result);
match from_str::<Expected>(&raw) {
Ok(result) => insta::assert_ron_snapshot!(path, result),
Err(e) => {
let handler = GraphicalReportHandler::new_themed(GraphicalTheme::unicode_nocolor());
let mut out = String::new();
handler.render_report(&mut out, &e).unwrap();
insta::assert_snapshot!(path, out)
}
}
}