mirror of
https://github.com/crate-ci/typos.git
synced 2024-11-24 18:10:56 -05:00
test(config): Verify layering
This commit is contained in:
parent
b8294d7afa
commit
29fafd1a63
1 changed files with 77 additions and 7 deletions
|
@ -1,6 +1,6 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
|
||||
#[derive(Debug, Clone, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||
#[serde(deny_unknown_fields, default)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub struct Config {
|
||||
|
@ -56,7 +56,7 @@ impl Config {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
|
||||
#[derive(Debug, Clone, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||
#[serde(deny_unknown_fields, default)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub struct Walk {
|
||||
|
@ -137,7 +137,7 @@ impl Walk {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
|
||||
#[derive(Debug, Clone, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||
#[serde(deny_unknown_fields, default)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub struct TypeEngineConfig {
|
||||
|
@ -153,7 +153,7 @@ impl TypeEngineConfig {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
|
||||
#[derive(Debug, Clone, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||
#[serde(deny_unknown_fields, default)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub struct EngineConfig {
|
||||
|
@ -226,7 +226,7 @@ impl EngineConfig {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
|
||||
#[derive(Debug, Clone, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||
#[serde(deny_unknown_fields, default)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub struct TokenizerConfig {
|
||||
|
@ -297,7 +297,7 @@ impl TokenizerConfig {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
|
||||
#[derive(Debug, Clone, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||
#[serde(deny_unknown_fields, default)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub struct DictConfig {
|
||||
|
@ -366,7 +366,7 @@ fn find_project_file(dir: &std::path::Path, names: &[&str]) -> Option<std::path:
|
|||
None
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, serde::Serialize, serde::Deserialize)]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub enum Locale {
|
||||
En,
|
||||
|
@ -424,3 +424,73 @@ impl std::fmt::Display for Locale {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_from_defaults() {
|
||||
let null = Config::default();
|
||||
let defaulted = Config::from_defaults();
|
||||
assert_ne!(defaulted, null);
|
||||
assert_ne!(defaulted.files, null.files);
|
||||
assert_ne!(defaulted.default, null.default);
|
||||
assert_ne!(defaulted.default.tokenizer, null.default.tokenizer);
|
||||
assert_ne!(defaulted.default.dict, null.default.dict);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_update_from_nothing() {
|
||||
let null = Config::default();
|
||||
let defaulted = Config::from_defaults();
|
||||
|
||||
let mut actual = defaulted.clone();
|
||||
actual.update(&null);
|
||||
|
||||
assert_eq!(actual, defaulted);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_update_from_defaults() {
|
||||
let null = Config::default();
|
||||
let defaulted = Config::from_defaults();
|
||||
|
||||
let mut actual = null.clone();
|
||||
actual.update(&defaulted);
|
||||
|
||||
assert_eq!(actual, defaulted);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extend_glob_updates() {
|
||||
let null = TypeEngineConfig::default();
|
||||
let extended = TypeEngineConfig {
|
||||
extend_glob: vec!["*.foo".into()],
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let mut actual = null.clone();
|
||||
actual.update(&extended);
|
||||
|
||||
assert_eq!(actual, extended);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extend_glob_extends() {
|
||||
let base = TypeEngineConfig {
|
||||
extend_glob: vec!["*.foo".into()],
|
||||
..Default::default()
|
||||
};
|
||||
let extended = TypeEngineConfig {
|
||||
extend_glob: vec!["*.bar".into()],
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let mut actual = base.clone();
|
||||
actual.update(&extended);
|
||||
|
||||
let expected: Vec<kstring::KString> = vec!["*.foo".into(), "*.bar".into()];
|
||||
assert_eq!(actual.extend_glob, expected);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue