ocpi-tariffs-cli 0.53.0

CLI application for OCPI tariff calculation
Documentation
//! Tests for `fixed_path`, which names the file a `--fix` run writes.

use std::{
    assert_matches,
    path::{Path, PathBuf},
};

use super::fixed_path;
use crate::Error;

#[test]
fn the_json_extension_is_replaced_by_the_fixed_suffix() {
    let fixed = fixed_path(Path::new("/srv/tariffs/tariff.json")).expect("the path names a file");

    assert_eq!(fixed, PathBuf::from("/srv/tariffs/tariff_fixed.json"));
}

#[test]
fn a_name_without_an_extension_gains_the_json_one() {
    let fixed = fixed_path(Path::new("/srv/tariffs/tariff")).expect("the path names a file");

    assert_eq!(fixed, PathBuf::from("/srv/tariffs/tariff_fixed.json"));
}

#[test]
fn an_extension_other_than_json_is_replaced_as_well() {
    let fixed = fixed_path(Path::new("/srv/tariffs/tariff.txt")).expect("the path names a file");

    assert_eq!(fixed, PathBuf::from("/srv/tariffs/tariff_fixed.json"));
}

// The suffix goes on the stem rather than after the whole name, so a dotted name keeps only its
// first segment. Nothing else names these files, so this is a choice rather than a constraint.
#[test]
fn only_the_last_extension_of_a_dotted_name_is_replaced() {
    let fixed = fixed_path(Path::new("/srv/tariffs/ac.0001.json")).expect("the path names a file");

    assert_eq!(fixed, PathBuf::from("/srv/tariffs/ac.0001_fixed.json"));
}

#[test]
fn a_relative_path_is_written_to_the_same_directory() {
    let fixed = fixed_path(Path::new("tariff.json")).expect("the path names a file");

    assert_eq!(fixed, PathBuf::from("tariff_fixed.json"));
}

#[test]
fn a_path_that_names_no_file_is_rejected() {
    let error = fixed_path(Path::new("/")).expect_err("the root names no file");

    assert_matches!(error, Error::PathNotFile { path: _ });
}