ecformat 0.2.0

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 `spelling_language` property of EditorConfig.
//! Files for the Integration Tests here,
//! are in `tests/resources/spelling_language`.
//! There are not related Unit Tests as the implementation
//! uses the `ec4rs` crate for the core logic of the check.

use std::io;

use ec4rs::{PropertyKey, property::SpellingLanguage};
use itertools::Itertools;
use tempfile::TempDir;

use ecformat::errors::{CheckConfigErrorType, EditorConfigError};

mod integration_test_utils;

use integration_test_utils::test_utils;

/// Runs the `check` command to the test EditorConfig files.
#[test]
fn test_check_spelling_language() {
    let temp_dir = copy_test_editorconfigs().expect("Copy tests files into temp dir necessary");
    let error_list = integration_test_utils::run_check_command(temp_dir.path());

    // All files with errors found?
    let expected_error_files =
        integration_test_utils::get_filtered_test_editorconfig_names::<SpellingLanguage, _>(
            |test_entry| test_utils::spelling_language::is_faulty(test_entry),
        );
    let error_files = integration_test_utils::check_error_list_as_file_names(&error_list)
        .into_iter()
        .unique()
        .collect_vec();
    assert_eq!(
        error_files, expected_error_files,
        "Detected EditorConfigs with errors in its spelling_language not as expected"
    );

    // Type of errors correct?
    for error in &error_list {
        match error {
            EditorConfigError::ConfigError(config_error) => match config_error.error_type() {
                CheckConfigErrorType::SpellingLanguageError {
                    validation_error: _,
                } => {
                    // The actual validation is from `ec4rs`.
                    // Therefore, the exact errors are out of scope for the testing of ecformat.
                } // No other CheckConfigErrorType yet, which a default arm could match
                CheckConfigErrorType::ParsingError {
                    value: _,
                    property_name,
                } => {
                    assert_eq!(
                        *property_name,
                        SpellingLanguage::key(),
                        "Parsing for the wrong property failed"
                    )
                }
            },
            e => panic!("The error is no config error: {e}"),
        }
    }
}

/// Copy the all the test EditorConfig files into a temporary directory.
fn copy_test_editorconfigs() -> io::Result<TempDir> {
    integration_test_utils::copy_test_editorconfigs(test_utils::TestFileHelper::new::<
        SpellingLanguage,
    >())
}