mirror of
https://github.com/crate-ci/typos.git
synced 2024-11-21 16:41:01 -05:00
test(config): Ensure CLI overrides work
This commit is contained in:
parent
29fafd1a63
commit
68c0a0d898
3 changed files with 62 additions and 1 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
@ -767,6 +767,12 @@ dependencies = [
|
|||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "maplit"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.3.4"
|
||||
|
@ -1516,6 +1522,7 @@ dependencies = [
|
|||
"itertools 0.10.0",
|
||||
"kstring",
|
||||
"log",
|
||||
"maplit",
|
||||
"once_cell",
|
||||
"phf",
|
||||
"predicates",
|
||||
|
|
|
@ -65,6 +65,7 @@ typed-arena = "2.0.1"
|
|||
assert_fs = "1.0"
|
||||
predicates = "1.0"
|
||||
criterion = "0.3"
|
||||
maplit = "1.0"
|
||||
|
||||
[profile.dev]
|
||||
panic = "abort"
|
||||
|
|
|
@ -133,7 +133,6 @@ impl<'s> ConfigEngine<'s> {
|
|||
|
||||
let mut types = Default::default();
|
||||
std::mem::swap(&mut types, &mut config.type_);
|
||||
|
||||
let mut types = types
|
||||
.into_iter()
|
||||
.map(|(type_, type_engine)| {
|
||||
|
@ -338,3 +337,57 @@ impl<'t, 'd> Default for Policy<'t, 'd> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_load_config_applies_overrides() {
|
||||
let storage = ConfigStorage::new();
|
||||
let mut engine = ConfigEngine::new(&storage);
|
||||
engine.set_isolated(true);
|
||||
|
||||
let type_name = kstring::KString::from_static("toml");
|
||||
|
||||
let config = crate::config::Config {
|
||||
default: crate::config::EngineConfig {
|
||||
binary: Some(true),
|
||||
check_filename: Some(true),
|
||||
..Default::default()
|
||||
},
|
||||
type_: maplit::hashmap! {
|
||||
type_name.clone() => crate::config::TypeEngineConfig {
|
||||
engine: crate::config::EngineConfig {
|
||||
check_filename: Some(false),
|
||||
check_file: Some(true),
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
},
|
||||
},
|
||||
overrides: crate::config::EngineConfig {
|
||||
binary: Some(false),
|
||||
check_file: Some(false),
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
};
|
||||
engine.set_overrides(config);
|
||||
|
||||
let cwd = std::path::Path::new(".");
|
||||
let loaded = engine.load_config(&cwd).unwrap();
|
||||
assert_eq!(loaded.default.binary, Some(false));
|
||||
assert_eq!(loaded.default.check_filename, Some(true));
|
||||
assert_eq!(loaded.default.check_file, Some(false));
|
||||
assert_eq!(loaded.type_[type_name.as_str()].engine.binary, Some(false));
|
||||
assert_eq!(
|
||||
loaded.type_[type_name.as_str()].engine.check_filename,
|
||||
Some(false)
|
||||
);
|
||||
assert_eq!(
|
||||
loaded.type_[type_name.as_str()].engine.check_file,
|
||||
Some(false)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue