ocpi-tariffs 0.54.0

OCPI tariff calculations
Documentation
use std::assert_matches;

use crate::{json, schema, test, warning};

const TARIFF: &str = r#"{
    "country_code": "NLD",
    "party_id": "ENE",
    "currency": "EUR"
}"#;

/// A caller uses the element `find` returns to point at a field,
/// so the element has to be the one the matching warning was reported against,
/// not the first element in the set.
#[test]
fn should_return_the_element_of_the_matching_warning() {
    test::setup();

    let doc = json::parse_object(TARIFF).unwrap();
    let root = doc.root();

    let country_code = root.find_field("country_code").unwrap().element();
    let currency = root.find_field("currency").unwrap().element();

    let mut warnings = warning::Set::<schema::Warning>::new();
    warnings.insert(country_code, schema::Warning::NonSpecField);
    warnings.insert(currency, schema::Warning::NullField);
    warnings.insert(currency, schema::Warning::UnexpectedField);

    let (element, warning) = warnings
        .find(|warning| matches!(warning, schema::Warning::UnexpectedField))
        .unwrap();

    assert_eq!(element.path.as_str(), "$.currency");
    assert_matches!(warning, schema::Warning::UnexpectedField);
}