ocpi-tariffs 0.53.0

OCPI tariff calculations
Documentation
//! Tests for `Weekday::canonical` and `Weekday::from_canonical`, the version-neutral day names.
//!
//! `Weekday` carries its own copy of the seven names so a caller working from raw JSON does not
//! have to pick a spec version to read a day. That copy can drift from the two it was taken
//! from, so every test here closes a loop back through the `schema::v211` and `schema::v221`
//! tables rather than restating the names.

use crate::{
    schema::{self, OcpiEnum as _},
    weekday::Weekday,
    FromSchema as _,
};

#[test]
fn a_name_resolves_to_the_day_it_came_from() {
    for day in Weekday::ALL {
        assert_eq!(Weekday::from_canonical(day.canonical()), Some(day));
    }
}

#[test]
fn the_names_are_the_ones_the_v221_schema_permits() {
    for day in Weekday::ALL {
        let variant = schema::v221::DayOfWeek::from_canonical(day.canonical())
            .expect("the v221 schema names the same days");

        let lowered = Weekday::from_schema(&variant).expect("the lowering is infallible");

        assert_eq!(lowered.ignore_warnings(), day);
    }
}

#[test]
fn the_names_are_the_ones_the_v211_schema_permits() {
    for day in Weekday::ALL {
        let variant = schema::v211::DayOfWeek::from_canonical(day.canonical())
            .expect("the v211 schema names the same days");

        let lowered = Weekday::from_schema(&variant).expect("the lowering is infallible");

        assert_eq!(lowered.ignore_warnings(), day);
    }
}

// Sorting a `day_of_week` list relies on `Ord` putting the days in the order the spec lists
// them, which the derive takes from the declaration order rather than from `ALL`.
#[test]
fn the_days_are_declared_in_spec_order() {
    assert!(Weekday::ALL.is_sorted());
}

#[test]
fn a_name_the_spec_does_not_define_is_not_a_day() {
    assert_eq!(Weekday::from_canonical("CHRISTMAS"), None);
}

// The match is exact, so the fixer never rewrites a list it has only half understood.
#[test]
fn a_name_in_the_wrong_case_is_not_a_day() {
    assert_eq!(Weekday::from_canonical("Monday"), None);
}