use std::slice;
use itertools::Itertools;
use crate::{cli::IgnoreArgs, test_utils};
use super::super::get_editorconfig_files;
#[test]
fn test_get_editorconfig_files_defaults() {
let repo = test_utils::get_repo();
let args = IgnoreArgs {
hidden: true,
git_settings: true,
ignore_file: None,
};
let config_files = get_editorconfig_files(slice::from_ref(&repo), &args);
let mut vscode = false;
for cf in config_files {
let f = cf
.expect("file in the iterator should not be an error")
.path;
assert!(
!f.starts_with(repo.join(".git")),
"A file of the .git directory is considered: {}",
f.display()
);
if f.starts_with(repo.join(".vscode")) {
vscode = true;
}
assert_eq!(
f.file_name().unwrap(),
".editorconfig",
"Another file than a .editorconfig file is included: {}",
f.display()
);
}
assert!(
vscode,
"no EditorConfig from .vscode (a hidden directory) in the editorconfig files"
);
}
#[test]
fn test_get_editorconfig_files_bool_options() {
let repo = test_utils::get_repo();
let args = IgnoreArgs {
hidden: false,
git_settings: false,
ignore_file: None,
};
let config_files = get_editorconfig_files(slice::from_ref(&repo), &args);
for cf in config_files {
let f = cf
.expect("file in the iterator should not be an error")
.path;
assert!(
!f.starts_with(repo.join(".git")),
"files in .git directory (a hidden directory) in editorconfig files: {}",
f.display()
);
assert!(
!f.starts_with(repo.join(".vscode")),
"files in .vscode directory (a hidden directory) in editorconfig files: {}",
f.display()
);
assert_eq!(
f.file_name().unwrap(),
".editorconfig",
"Another file than a .editorconfig file is included: {}",
f.display()
);
}
}
#[test]
fn test_get_editorconfig_files_multiple_targets() {
let repo = test_utils::get_repo();
let license_directory = repo.join("LICENSES");
let test_resouces_file = repo.join("tests").join("resources").join("README.md");
let targets = vec![license_directory.clone(), test_resouces_file.clone()];
let args = IgnoreArgs {
hidden: true,
git_settings: true,
ignore_file: None,
};
let config_files = get_editorconfig_files(&targets, &args);
let expected_paths = vec![
license_directory,
test_resouces_file.parent().unwrap().to_owned(),
]
.into_iter()
.map(|dir| dir.join(".editorconfig").canonicalize().unwrap())
.sorted()
.collect_vec();
let paths = config_files
.map(|cf| {
cf.expect("file in the iterator should not be an error")
.path
.canonicalize()
.unwrap()
})
.sorted()
.collect_vec();
assert_eq!(
paths, expected_paths,
"The found EditorConfigs are not as expected."
)
}