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;
#[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());
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"
);
for error in &error_list {
match error {
EditorConfigError::ConfigError(config_error) => match config_error.error_type() {
CheckConfigErrorType::SpellingLanguageError {
validation_error: _,
} => {
} 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}"),
}
}
}
fn copy_test_editorconfigs() -> io::Result<TempDir> {
integration_test_utils::copy_test_editorconfigs(test_utils::TestFileHelper::new::<
SpellingLanguage,
>())
}