ocpi-tariffs 0.52.0

OCPI tariff calculations
Documentation
use super::parse;

#[test]
fn should_resolve_to_source_json() {
    const JSON: &str = r#"{
    "name": "David Byrne",
    "hobbies": ["song writing", "thinking about society"]
}"#;

    let doc = parse(JSON.into()).unwrap();

    let root = doc.root();
    assert_eq!(root.source_json_value(), JSON);

    let [name, hobbies] = root.as_object_fields().unwrap() else {
        panic!("expected exactly two fields")
    };

    let field_name = name.element();
    assert_eq!(field_name.source_json_value(), r#""David Byrne""#);

    let field_hobbies = hobbies.element();
    assert_eq!(
        field_hobbies.source_json_value(),
        r#"["song writing", "thinking about society"]"#
    );

    let [hobbies_one, hobbies_two] = field_hobbies.as_array().unwrap() else {
        panic!("expected exactly two hobbies")
    };

    assert_eq!(hobbies_one.source_json_value(), r#""song writing""#);
    assert_eq!(hobbies_one.source_json_value(), r#""song writing""#);

    assert_eq!(
        hobbies_two.source_json_value(),
        r#""thinking about society""#
    );
    assert_eq!(
        hobbies_two.source_json_value(),
        r#""thinking about society""#
    );
}