use std::path::Path;
use assert_matches::assert_matches;
use crate::{guess, test, Version, Versioned as _};
use super::{parse_and_report, test::assert_parse_guess_report};
#[test_each::file(
glob = "ocpi-tariffs/test_data/v211/real_world/*/tariff*.json",
name(segments = 2)
)]
fn should_parse_v211(tariff_json: &str, path: &Path) {
test::setup();
expect_version(tariff_json, path, Version::V211);
}
#[test_each::file(
glob = "ocpi-tariffs/test_data/v221/real_world/*/tariff*.json",
name(segments = 2)
)]
fn should_parse_v221(tariff_json: &str, path: &Path) {
test::setup();
expect_version(tariff_json, path, Version::V221);
}
fn expect_version(tariff_json: &str, path: &Path, expected_version: Version) {
let report = parse_and_report(tariff_json).unwrap();
let expect_json = test::read_expect_json(path, "parse");
let parse_expect = test::parse_expect_json(expect_json.as_deref());
let tariff = assert_matches!(&report.version, guess::Version::Certain(tariff) => tariff);
assert_eq!(tariff.version(), expected_version);
assert_parse_guess_report(report, parse_expect);
}