ecformat 0.1.1

command line tool to keep files correct in respect of your EditorConfig
Documentation
// SPDX-FileCopyrightText: Contributors to ecformat project <https://codeberg.org/BaumiCoder/ecformat>
//
// SPDX-License-Identifier: BlueOak-1.0.0

//! Tests for the integrated license information,
//! which aim to ruffly check if the information seems to be valid / complete.

use cargo_toml::Manifest;
use rstest::rstest;
use serde::Deserialize;

use super::get_license_information;

#[rstest]
fn test_snippet(
    #[values(
        // Full license names
        "Blue Oak Model License 1.0.0",
        "Apache License 2.0",
        "MIT License",
        // Some snippets from the template in `about.hbs`
        "In the following you can find the licenses of ecformat and all its dependencies.",
        "All license text",
        "Used by"
    )]
    snippet: &str,
) {
    let about = get_license_information();

    assert!(
        about.contains(snippet),
        "License information does not contain '{snippet}'"
    );
}

#[test]
fn test_direct_dependencies() {
    let deps = Manifest::from_str(include_str!("../Cargo.toml"))
        .unwrap()
        .dependencies;
    let about = get_license_information();

    // All crates in the normal dependencies section needs to be mentioned
    for dep in deps.keys() {
        assert!(
            about.contains(dep),
            "Crate {dep} is missing in the license information"
        );
    }
}

/// struct of the `about.toml`
#[derive(Deserialize)]
struct AboutToml {
    accepted: Vec<String>,
}

#[test]
fn test_license_spdx_ids() {
    let toml_content = include_str!("../about.toml");
    let about_toml: AboutToml = toml::from_str(toml_content).unwrap();
    let about = get_license_information();

    for license in about_toml.accepted {
        assert!(
            about.contains(&license),
            "License {license} is missing in the license information"
        );
    }
}

#[test]
fn test_license_text_blue_oak() {
    let about = get_license_information();

    assert!(
        about.contains(include_str!("../LICENSES/BlueOak-1.0.0.txt")),
        "License information does not contain the license text of BlueOak"
    );
}