ocpi-tariffs 0.43.0

OCPI tariff calculations
Documentation
use std::path::Path;

use crate::{json::FromJson, tariff, test};

use super::Tariff;

#[test_each::file(
    glob = "ocpi-tariffs/test_data/v211/real_world/*/tariff*.json",
    name(segments = 2)
)]
fn should_parse_tariff(tariff_json: &str, path: &Path) {
    test::setup();

    let expect_json = test::read_expect_json(path, "parse");
    let parse_expect = test::parse_expect_json(expect_json.as_deref());

    let tariff::ParseReport {
        tariff: tariff_elem,
        unexpected_fields,
    } = tariff::parse_with_version(tariff_json, crate::Version::V211).unwrap();

    tariff::test::assert_parse_report(unexpected_fields, parse_expect);

    let tariff = Tariff::from_json(tariff_elem.as_element()).unwrap();
    let (_tariff, warnings) = tariff.into_parts();

    let from_json_expect = test::parse_expect_json(expect_json.as_deref());
    tariff::test::assert_from_json_warnings(&warnings, from_json_expect);
}