ocpi-tariffs 0.46.0

OCPI tariff calculations
Documentation
use std::sync::Arc;

use crate::test;

use super::{test::PathGlob, PathNode};

#[test]
fn glob_should_match_path() {
    test::setup();

    let root = Arc::new(PathNode::Root);
    let path_a = Arc::new(PathNode::Array {
        parent: Arc::clone(&root),
        index: 1,
    });
    let path_b = Arc::new(PathNode::Object {
        parent: Arc::clone(&path_a),
        key: r#""name""#.into(),
    });
    let path_c = PathNode::Object {
        parent: Arc::clone(&path_b),
        key: r#""gene""#.into(),
    };

    assert!(PathGlob::from("$").matches(&root));
    assert!(PathGlob::from("*").matches(&root));

    assert!(!PathGlob::from("*").matches(&path_a));
    assert!(PathGlob::from("*.*").matches(&path_a));
    assert!(PathGlob::from("$.*").matches(&path_a));
    assert!(PathGlob::from("$.1").matches(&path_a));

    assert!(!PathGlob::from("*").matches(&path_b));
    assert!(!PathGlob::from("*.*").matches(&path_b));
    assert!(PathGlob::from("*.*.*").matches(&path_b));
    assert!(PathGlob::from("$.*.*").matches(&path_b));
    assert!(PathGlob::from("$.1.*").matches(&path_b));
    assert!(PathGlob::from("$.*.name").matches(&path_b));
    assert!(PathGlob::from("$.1.name").matches(&path_b));

    assert!(PathGlob::from("$.1.name.gene").matches(&path_c));
}