diff --git a/Cargo.lock b/Cargo.lock index 4db45ddc8..7ce945f42 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -177,7 +177,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6798148dccfbff0fae41c7574d2fa8f1ef3492fba0face179de5d8d447d67b05" dependencies = [ "memchr", - "regex-automata", + "regex-automata 0.3.8", "serde", ] @@ -1686,14 +1686,14 @@ dependencies = [ [[package]] name = "regex" -version = "1.9.5" +version = "1.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "697061221ea1b4a94a624f67d0ae2bfe4e22b8a17b6a192afb11046542cc8c47" +checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" dependencies = [ "aho-corasick 1.0.4", "memchr", - "regex-automata", - "regex-syntax 0.7.5", + "regex-automata 0.4.3", + "regex-syntax 0.8.2", ] [[package]] @@ -1701,10 +1701,16 @@ name = "regex-automata" version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2f401f4955220693b56f8ec66ee9c78abffd8d1c4f23dc41a23839eb88f0795" + +[[package]] +name = "regex-automata" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" dependencies = [ "aho-corasick 1.0.4", "memchr", - "regex-syntax 0.7.5", + "regex-syntax 0.8.2", ] [[package]] @@ -1719,6 +1725,12 @@ version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" +[[package]] +name = "regex-syntax" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" + [[package]] name = "reqwest" version = "0.11.19" diff --git a/crates/maple_core/src/config.rs b/crates/maple_core/src/config.rs index d472fc227..c82bfe551 100644 --- a/crates/maple_core/src/config.rs +++ b/crates/maple_core/src/config.rs @@ -55,7 +55,7 @@ pub fn config_file() -> &'static PathBuf { CONFIG_FILE.get().expect("Config file uninitialized") } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)] #[serde(rename_all = "kebab-case", default, deny_unknown_fields)] pub struct MatcherConfig { pub tiebreak: String, @@ -78,7 +78,7 @@ impl MatcherConfig { } } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)] #[serde(rename_all = "kebab-case", default, deny_unknown_fields)] pub struct LogConfig { pub log_file: Option, @@ -94,7 +94,7 @@ impl Default for LogConfig { } } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)] #[serde(rename_all = "kebab-case", default, deny_unknown_fields)] pub struct CursorWordConfig { /// Whether to enable this plugin. @@ -115,21 +115,21 @@ impl Default for CursorWordConfig { } } -#[derive(Serialize, Deserialize, Debug, Default)] +#[derive(Serialize, Deserialize, Debug, Default, Eq, PartialEq)] #[serde(rename_all = "kebab-case", default, deny_unknown_fields)] pub struct MarkdownPluginConfig { /// Whether to enable this plugin. pub enable: bool, } -#[derive(Serialize, Deserialize, Debug, Default)] +#[derive(Serialize, Deserialize, Debug, Default, Eq, PartialEq)] #[serde(rename_all = "kebab-case", default, deny_unknown_fields)] pub struct CtagsPluginConfig { /// Whether to enable this plugin. pub enable: bool, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)] #[serde(rename_all = "kebab-case", default, deny_unknown_fields)] pub struct GitPluginConfig { /// Whether to enable this plugin. @@ -150,14 +150,14 @@ impl Default for GitPluginConfig { } } -#[derive(Serialize, Deserialize, Debug, Default)] +#[derive(Serialize, Deserialize, Debug, Default, Eq, PartialEq)] #[serde(rename_all = "kebab-case", default, deny_unknown_fields)] pub struct LinterPluginConfig { /// Whether to enable this plugin. pub enable: bool, } -#[derive(Serialize, Deserialize, Debug, Default)] +#[derive(Serialize, Deserialize, Debug, Default, Eq, PartialEq)] #[serde(rename_all = "kebab-case", default, deny_unknown_fields)] pub struct PluginConfig { pub cursorword: CursorWordConfig, @@ -167,7 +167,7 @@ pub struct PluginConfig { pub markdown: MarkdownPluginConfig, } -#[derive(Serialize, Deserialize, Debug, Default)] +#[derive(Serialize, Deserialize, Debug, Default, Eq, PartialEq)] #[serde(rename_all = "kebab-case", default, deny_unknown_fields)] pub struct IgnoreConfig { /// Whether to ignore the comment line when it's possible. @@ -180,7 +180,7 @@ pub struct IgnoreConfig { pub ignore_file_path_pattern: Vec, } -#[derive(Serialize, Deserialize, Debug, Default)] +#[derive(Serialize, Deserialize, Debug, Default, Eq, PartialEq)] #[serde(rename_all = "kebab-case", default, deny_unknown_fields)] pub struct ProviderConfig { /// Delay in milliseconds before the user query will be handled actually. @@ -217,7 +217,7 @@ pub struct ProviderConfig { pub share_input_history: bool, } -#[derive(Serialize, Deserialize, Debug, Default)] +#[derive(Serialize, Deserialize, Debug, Default, Eq, PartialEq)] #[serde(rename_all = "kebab-case", default, deny_unknown_fields)] pub struct Config { /// Log configuration. @@ -299,7 +299,44 @@ mod tests { "#; let user_config: Config = toml::from_str(toml_content).expect("Failed to deserialize config"); - println!("{:#?}", user_config); - println!("{}", toml::to_string(&user_config).unwrap()); + + assert_eq!( + user_config, + Config { + log: LogConfig { + log_file: Some("/tmp/clap.log".to_string()), + max_level: "trace".to_string() + }, + matcher: MatcherConfig { + tiebreak: "score,-begin,-end,-length".to_string() + }, + plugin: PluginConfig { + cursorword: CursorWordConfig { + enable: true, + ..Default::default() + }, + ..Default::default() + }, + provider: ProviderConfig { + debounce: HashMap::from_iter([ + ("*".to_string(), 200), + ("files".to_string(), 100) + ]), + ignore: HashMap::from([( + "dumb_jump".to_string(), + IgnoreConfig { + ignore_comments: true, + ..Default::default() + } + )]), + ..Default::default() + }, + global_ignore: IgnoreConfig { + ignore_file_path_pattern: vec!["test".to_string(), "build".to_string()], + ..Default::default() + }, + ..Default::default() + } + ); } }