Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add test #290

Merged
merged 2 commits into from
Apr 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
# 'feh -.':
# [jpg, jpeg, png, gif, svg, hdr]

# Whether to do the case-insensitive search by `/`.
# ignore_case: true

# The foreground color of directory, file and symlink.
# Pick one of the following:
# Black // 0
Expand Down
72 changes: 70 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct Config {
pub color: Option<ConfigColor>,
}

#[derive(Deserialize, Debug, Clone)]
#[derive(Deserialize, Debug, Clone, PartialEq)]
pub struct ConfigColor {
pub dir_fg: Colorname,
pub file_fg: Colorname,
Expand All @@ -43,7 +43,7 @@ impl Default for ConfigColor {
}
}

#[derive(Deserialize, Debug, Clone)]
#[derive(Deserialize, Debug, Clone, PartialEq)]
pub enum Colorname {
Black, // 0
Red, // 1
Expand Down Expand Up @@ -143,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);
}
}
Loading