summaryrefslogtreecommitdiffstats
path: root/src/config.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs74
1 files changed, 72 insertions, 2 deletions
diff --git a/src/config.rs b/src/config.rs
index ca20ffd..75a1d14 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -20,10 +20,11 @@ pub struct Config {
pub default: Option<String>,
pub match_vim_exit_behavior: Option<bool>,
pub exec: Option<BTreeMap<String, Vec<String>>>,
+ pub ignore_case: Option<bool>,
pub color: Option<ConfigColor>,
}
-#[derive(Deserialize, Debug, Clone)]
+#[derive(Deserialize, Debug, Clone, PartialEq)]
pub struct ConfigColor {
pub dir_fg: Colorname,
pub file_fg: Colorname,
@@ -42,7 +43,7 @@ impl Default for ConfigColor {
}
}
-#[derive(Deserialize, Debug, Clone)]
+#[derive(Deserialize, Debug, Clone, PartialEq)]
pub enum Colorname {
Black, // 0
Red, // 1
@@ -70,6 +71,7 @@ impl Default for Config {
default: Default::default(),
match_vim_exit_behavior: Default::default(),
exec: Default::default(),
+ ignore_case: Some(false),
color: Some(Default::default()),
}
}
@@ -141,3 +143,71 @@ pub fn read_config_or_default() -> Result<ConfigWithPath, FxError> {
})
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn test_read_default_config() {
+ let default_config: Config = serde_yaml::from_str("").unwrap();
+ assert_eq!(default_config.default, None);
+ assert_eq!(default_config.match_vim_exit_behavior, None);
+ assert_eq!(default_config.exec, None);
+ assert_eq!(default_config.ignore_case, None);
+ assert_eq!(default_config.color, None);
+ }
+
+ #[test]
+ fn test_read_full_config() {
+ let full_config: Config = serde_yaml::from_str(
+ r#"
+default: nvim
+match_vim_exit_behavior: true
+exec:
+ zathura:
+ [pdf]
+ 'feh -.':
+ [jpg, jpeg, png, gif, svg, hdr]
+ignore_case: true
+color:
+ dir_fg: LightCyan
+ file_fg: LightWhite
+ symlink_fg: LightYellow
+ dirty_fg: Red
+"#,
+ )
+ .unwrap();
+ assert_eq!(full_config.default, Some("nvim".to_string()));
+ assert_eq!(full_config.match_vim_exit_behavior, Some(true));
+ assert_eq!(
+ full_config.exec.clone().unwrap().get("zathura"),
+ Some(&vec!["pdf".to_string()])
+ );
+ assert_eq!(
+ full_config.exec.unwrap().get("feh -."),
+ Some(&vec![
+ "jpg".to_string(),
+ "jpeg".to_string(),
+ "png".to_string(),
+ "gif".to_string(),
+ "svg".to_string(),
+ "hdr".to_string()
+ ])
+ );
+ assert_eq!(full_config.ignore_case, Some(true));
+ assert_eq!(
+ full_config.color.clone().unwrap().dir_fg,
+ Colorname::LightCyan
+ );
+ assert_eq!(
+ full_config.color.clone().unwrap().file_fg,
+ Colorname::LightWhite
+ );
+ assert_eq!(
+ full_config.color.clone().unwrap().symlink_fg,
+ Colorname::LightYellow
+ );
+ assert_eq!(full_config.color.unwrap().dirty_fg, Colorname::Red);
+ }
+}