#![allow(clippy::missing_panics_doc, reason = "tests are allowed to panic")]
#![allow(clippy::panic, reason = "tests are allowed panic")]
use std::collections::BTreeMap;
use crate::{
json,
test::{ExpectFile, Expectation},
warning,
};
#[derive(Debug, serde::Deserialize)]
pub struct ParseExpect {
#[serde(default)]
pub unexpected_fields: Expectation<Vec<json::test::PathGlob>>,
}
#[derive(Debug, serde::Deserialize)]
pub struct FromJsonExpect {
#[serde(default)]
warnings: Expectation<BTreeMap<String, Vec<String>>>,
}
#[track_caller]
pub(crate) fn assert_parse_report(
mut unexpected_fields: json::UnexpectedFields<'_>,
expect: ExpectFile<ParseExpect>,
) {
let ExpectFile {
value,
expect_file_name,
} = expect;
let Some(ParseExpect {
unexpected_fields: expected,
}) = value
else {
json::test::expect_no_unexpected_fields(&expect_file_name, &unexpected_fields);
return;
};
json::test::expect_unexpected_fields(&expect_file_name, &mut unexpected_fields, expected);
}
#[track_caller]
pub(crate) fn assert_from_json_warnings(
warnings: &warning::Set<super::Warning>,
expect: ExpectFile<FromJsonExpect>,
) {
let ExpectFile {
value,
expect_file_name,
} = expect;
let Some(expect) = value else {
assert!(
warnings.is_empty(),
"There is no expectation file at `{expect_file_name}`\
but the tariff has warnings;\n{:#?}",
warnings.path_debug_map()
);
return;
};
warning::test::assert_warnings(&expect_file_name, warnings, expect.warnings);
}