style(config): fix formatting
This commit is contained in:
parent
9202c1189c
commit
be68a1f8ff
|
@ -269,14 +269,15 @@ mod tests {
|
|||
.unwrap();
|
||||
let parsed_config: ParsedConfig = config.try_into().unwrap();
|
||||
|
||||
let keyboard_layout: BTreeMap<String, String> =
|
||||
vec![
|
||||
let keyboard_layout: BTreeMap<String, String> = vec![
|
||||
("rules".to_string(), "test_rule".to_string()),
|
||||
("model".to_string(), "test_model".to_string()),
|
||||
("layout".to_string(), "test_layout".to_string()),
|
||||
("variant".to_string(), "test_variant".to_string()),
|
||||
("options".to_string(), "test_options".to_string()),
|
||||
].into_iter().collect();
|
||||
]
|
||||
.into_iter()
|
||||
.collect();
|
||||
|
||||
assert_eq!(
|
||||
parsed_config,
|
||||
|
|
|
@ -17,13 +17,22 @@
|
|||
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use super::{AppProperties, Backend, Config, RMLVOConfig, ToggleKey, default::{DEFAULT_CLIPBOARD_THRESHOLD, DEFAULT_PRE_PASTE_DELAY, DEFAULT_RESTORE_CLIPBOARD_DELAY, DEFAULT_SHORTCUT_EVENT_DELAY}, parse::ParsedConfig, path::calculate_paths, util::os_matches};
|
||||
use super::{
|
||||
default::{
|
||||
DEFAULT_CLIPBOARD_THRESHOLD, DEFAULT_PRE_PASTE_DELAY, DEFAULT_RESTORE_CLIPBOARD_DELAY,
|
||||
DEFAULT_SHORTCUT_EVENT_DELAY,
|
||||
},
|
||||
parse::ParsedConfig,
|
||||
path::calculate_paths,
|
||||
util::os_matches,
|
||||
AppProperties, Backend, Config, RMLVOConfig, ToggleKey,
|
||||
};
|
||||
use crate::{counter::next_id, merge};
|
||||
use anyhow::Result;
|
||||
use log::error;
|
||||
use regex::Regex;
|
||||
use std::path::PathBuf;
|
||||
use std::{collections::HashSet, path::Path};
|
||||
use std::{path::PathBuf};
|
||||
use thiserror::Error;
|
||||
|
||||
const STANDARD_INCLUDES: &[&str] = &["../match/**/*.yml"];
|
||||
|
@ -240,7 +249,8 @@ impl Config for ResolvedConfig {
|
|||
}
|
||||
|
||||
fn word_separators(&self) -> Vec<String> {
|
||||
self.parsed.word_separators.clone().unwrap_or_else(|| vec![
|
||||
self.parsed.word_separators.clone().unwrap_or_else(|| {
|
||||
vec![
|
||||
" ".to_string(),
|
||||
",".to_string(),
|
||||
".".to_string(),
|
||||
|
@ -249,7 +259,8 @@ impl Config for ResolvedConfig {
|
|||
"\r".to_string(),
|
||||
"\n".to_string(),
|
||||
(22u8 as char).to_string(),
|
||||
])
|
||||
]
|
||||
})
|
||||
}
|
||||
|
||||
fn backspace_limit(&self) -> usize {
|
||||
|
@ -261,7 +272,11 @@ impl Config for ResolvedConfig {
|
|||
}
|
||||
|
||||
fn keyboard_layout(&self) -> Option<RMLVOConfig> {
|
||||
self.parsed.keyboard_layout.as_ref().map(|layout| RMLVOConfig {
|
||||
self
|
||||
.parsed
|
||||
.keyboard_layout
|
||||
.as_ref()
|
||||
.map(|layout| RMLVOConfig {
|
||||
rules: layout.get("rules").map(String::from),
|
||||
model: layout.get("model").map(String::from),
|
||||
layout: layout.get("layout").map(String::from),
|
||||
|
@ -459,7 +474,10 @@ impl ResolvedConfig {
|
|||
let exclude_paths = calculate_paths(base_dir, excludes.iter());
|
||||
let include_paths = calculate_paths(base_dir, includes.iter());
|
||||
|
||||
include_paths.difference(&exclude_paths).cloned().collect::<HashSet<_>>()
|
||||
include_paths
|
||||
.difference(&exclude_paths)
|
||||
.cloned()
|
||||
.collect::<HashSet<_>>()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -481,7 +499,10 @@ mod tests {
|
|||
ResolvedConfig::aggregate_includes(&ParsedConfig {
|
||||
..Default::default()
|
||||
}),
|
||||
vec!["../match/**/*.yml".to_string(),].iter().cloned().collect::<HashSet<_>>()
|
||||
vec!["../match/**/*.yml".to_string(),]
|
||||
.iter()
|
||||
.cloned()
|
||||
.collect::<HashSet<_>>()
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -505,7 +526,8 @@ mod tests {
|
|||
}),
|
||||
vec!["../match/**/*.yml".to_string(), "custom/*.yml".to_string()]
|
||||
.iter()
|
||||
.cloned().collect::<HashSet<_>>()
|
||||
.cloned()
|
||||
.collect::<HashSet<_>>()
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -518,7 +540,8 @@ mod tests {
|
|||
}),
|
||||
vec!["../match/**/*.yml".to_string(), "custom/*.yml".to_string()]
|
||||
.iter()
|
||||
.cloned().collect::<HashSet<_>>()
|
||||
.cloned()
|
||||
.collect::<HashSet<_>>()
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -536,7 +559,8 @@ mod tests {
|
|||
"sub/*.yml".to_string()
|
||||
]
|
||||
.iter()
|
||||
.cloned().collect::<HashSet<_>>()
|
||||
.cloned()
|
||||
.collect::<HashSet<_>>()
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -546,7 +570,10 @@ mod tests {
|
|||
ResolvedConfig::aggregate_excludes(&ParsedConfig {
|
||||
..Default::default()
|
||||
}),
|
||||
vec!["../match/**/_*.yml".to_string(),].iter().cloned().collect::<HashSet<_>>()
|
||||
vec!["../match/**/_*.yml".to_string(),]
|
||||
.iter()
|
||||
.cloned()
|
||||
.collect::<HashSet<_>>()
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -570,7 +597,8 @@ mod tests {
|
|||
}),
|
||||
vec!["../match/**/_*.yml".to_string(), "custom/*.yml".to_string()]
|
||||
.iter()
|
||||
.cloned().collect::<HashSet<_>>()
|
||||
.cloned()
|
||||
.collect::<HashSet<_>>()
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -583,7 +611,8 @@ mod tests {
|
|||
}),
|
||||
vec!["../match/**/_*.yml".to_string(), "custom/*.yml".to_string()]
|
||||
.iter()
|
||||
.cloned().collect::<HashSet<_>>()
|
||||
.cloned()
|
||||
.collect::<HashSet<_>>()
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -601,7 +630,8 @@ mod tests {
|
|||
"sub/*.yml".to_string()
|
||||
]
|
||||
.iter()
|
||||
.cloned().collect::<HashSet<_>>()
|
||||
.cloned()
|
||||
.collect::<HashSet<_>>()
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use std::path::{Path, PathBuf};
|
||||
use anyhow::Error;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct NonFatalErrorSet {
|
||||
|
|
|
@ -976,8 +976,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_config_set_load_fail_bad_directory() {
|
||||
let config_set =
|
||||
LegacyConfigSet::load(Path::new("invalid/path"), Path::new("invalid/path"));
|
||||
let config_set = LegacyConfigSet::load(Path::new("invalid/path"), Path::new("invalid/path"));
|
||||
assert!(config_set.is_err());
|
||||
assert_eq!(
|
||||
config_set.unwrap_err(),
|
||||
|
@ -1606,9 +1605,10 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_list_has_conflict_no_conflict() {
|
||||
assert!(
|
||||
!LegacyConfigSet::list_has_conflicts(&[":ab".to_owned(), ":bc".to_owned()])
|
||||
);
|
||||
assert!(!LegacyConfigSet::list_has_conflicts(&[
|
||||
":ab".to_owned(),
|
||||
":bc".to_owned()
|
||||
]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1643,9 +1643,10 @@ mod tests {
|
|||
);
|
||||
|
||||
let config_set = LegacyConfigSet::load(data_dir.path(), package_dir.path()).unwrap();
|
||||
assert!(
|
||||
!LegacyConfigSet::has_conflicts(&config_set.default, &config_set.specific),
|
||||
);
|
||||
assert!(!LegacyConfigSet::has_conflicts(
|
||||
&config_set.default,
|
||||
&config_set.specific
|
||||
),);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1675,9 +1676,10 @@ mod tests {
|
|||
);
|
||||
|
||||
let config_set = LegacyConfigSet::load(data_dir.path(), package_dir.path()).unwrap();
|
||||
assert!(
|
||||
LegacyConfigSet::has_conflicts(&config_set.default, &config_set.specific),
|
||||
);
|
||||
assert!(LegacyConfigSet::has_conflicts(
|
||||
&config_set.default,
|
||||
&config_set.specific
|
||||
),);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1705,9 +1707,10 @@ mod tests {
|
|||
);
|
||||
|
||||
let config_set = LegacyConfigSet::load(data_dir.path(), package_dir.path()).unwrap();
|
||||
assert!(
|
||||
LegacyConfigSet::has_conflicts(&config_set.default, &config_set.specific),
|
||||
);
|
||||
assert!(LegacyConfigSet::has_conflicts(
|
||||
&config_set.default,
|
||||
&config_set.specific
|
||||
),);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1746,9 +1749,10 @@ mod tests {
|
|||
);
|
||||
|
||||
let config_set = LegacyConfigSet::load(data_dir.path(), package_dir.path()).unwrap();
|
||||
assert!(
|
||||
!LegacyConfigSet::has_conflicts(&config_set.default, &config_set.specific),
|
||||
);
|
||||
assert!(!LegacyConfigSet::has_conflicts(
|
||||
&config_set.default,
|
||||
&config_set.specific
|
||||
),);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -34,7 +34,13 @@ pub mod matches;
|
|||
mod util;
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub fn load(base_path: &Path) -> Result<(Box<dyn ConfigStore>, Box<dyn MatchStore>, Vec<error::NonFatalErrorSet>)> {
|
||||
pub fn load(
|
||||
base_path: &Path,
|
||||
) -> Result<(
|
||||
Box<dyn ConfigStore>,
|
||||
Box<dyn MatchStore>,
|
||||
Vec<error::NonFatalErrorSet>,
|
||||
)> {
|
||||
let config_dir = base_path.join("config");
|
||||
if !config_dir.exists() || !config_dir.is_dir() {
|
||||
return Err(ConfigError::MissingConfigDir().into());
|
||||
|
@ -43,16 +49,24 @@ pub fn load(base_path: &Path) -> Result<(Box<dyn ConfigStore>, Box<dyn MatchStor
|
|||
let (config_store, non_fatal_config_errors) = config::load_store(&config_dir)?;
|
||||
let root_paths = config_store.get_all_match_paths();
|
||||
|
||||
let (match_store, non_fatal_match_errors) = matches::store::load(&root_paths.into_iter().collect::<Vec<String>>());
|
||||
let (match_store, non_fatal_match_errors) =
|
||||
matches::store::load(&root_paths.into_iter().collect::<Vec<String>>());
|
||||
|
||||
let mut non_fatal_errors = Vec::new();
|
||||
non_fatal_errors.extend(non_fatal_config_errors.into_iter());
|
||||
non_fatal_errors.extend(non_fatal_match_errors.into_iter());
|
||||
|
||||
Ok((Box::new(config_store), Box::new(match_store), non_fatal_errors))
|
||||
Ok((
|
||||
Box::new(config_store),
|
||||
Box::new(match_store),
|
||||
non_fatal_errors,
|
||||
))
|
||||
}
|
||||
|
||||
pub fn load_legacy(config_dir: &Path, package_dir: &Path) -> Result<(Box<dyn ConfigStore>, Box<dyn MatchStore>)> {
|
||||
pub fn load_legacy(
|
||||
config_dir: &Path,
|
||||
package_dir: &Path,
|
||||
) -> Result<(Box<dyn ConfigStore>, Box<dyn MatchStore>)> {
|
||||
legacy::load(config_dir, package_dir)
|
||||
}
|
||||
|
||||
|
@ -70,7 +84,7 @@ pub enum ConfigError {
|
|||
mod tests {
|
||||
use super::*;
|
||||
use crate::util::tests::use_test_directory;
|
||||
use config::{AppProperties};
|
||||
use config::AppProperties;
|
||||
|
||||
#[test]
|
||||
fn load_works_correctly() {
|
||||
|
@ -280,11 +294,15 @@ mod tests {
|
|||
.unwrap();
|
||||
|
||||
let config_file = config_dir.join("default.yml");
|
||||
std::fs::write(&config_file, r#"
|
||||
std::fs::write(
|
||||
&config_file,
|
||||
r#"
|
||||
invalid
|
||||
|
||||
"
|
||||
"#).unwrap();
|
||||
"#,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
// A syntax error in the default.yml file cannot be handled gracefully
|
||||
assert!(load(base).is_err());
|
||||
|
|
|
@ -17,11 +17,11 @@
|
|||
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use std::{path::Path};
|
||||
use std::path::Path;
|
||||
|
||||
use anyhow::Result;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_yaml::{Mapping};
|
||||
use serde_yaml::Mapping;
|
||||
|
||||
use crate::util::is_yaml_empty;
|
||||
|
||||
|
|
|
@ -140,17 +140,26 @@ mod tests {
|
|||
#[test]
|
||||
fn convert_value_params() {
|
||||
let mut mapping = serde_yaml::Mapping::new();
|
||||
mapping.insert(serde_yaml::Value::String("test".to_string()), serde_yaml::Value::Null);
|
||||
mapping.insert(
|
||||
serde_yaml::Value::String("test".to_string()),
|
||||
serde_yaml::Value::Null,
|
||||
);
|
||||
|
||||
let mut expected = Params::new();
|
||||
expected.insert("test".to_string(), Value::Null);
|
||||
assert_eq!(convert_value(serde_yaml::Value::Mapping(mapping)).unwrap(), Value::Object(expected));
|
||||
assert_eq!(
|
||||
convert_value(serde_yaml::Value::Mapping(mapping)).unwrap(),
|
||||
Value::Object(expected)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn convert_params_works_correctly() {
|
||||
let mut mapping = serde_yaml::Mapping::new();
|
||||
mapping.insert(serde_yaml::Value::String("test".to_string()), serde_yaml::Value::Null);
|
||||
mapping.insert(
|
||||
serde_yaml::Value::String("test".to_string()),
|
||||
serde_yaml::Value::Null,
|
||||
);
|
||||
|
||||
let mut expected = Params::new();
|
||||
expected.insert("test".to_string(), Value::Null);
|
||||
|
|
Loading…
Reference in New Issue
Block a user