aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorlukeflo2025-02-23 12:35:56 +0100
committerlukeflo2025-02-23 12:35:56 +0100
commitd8bb353580f8d26e1e3dc2422e421ce64aa85417 (patch)
treeab5f2d888ab0a46d2593bea95ce1225453ae8bf7 /src
parent63d4410fdfe7712faec287aee2f5c0ca288dc996 (diff)
downloadbibiman-d8bb353580f8d26e1e3dc2422e421ce64aa85417.tar.gz
bibiman-d8bb353580f8d26e1e3dc2422e421ce64aa85417.zip
test module for config crate
Diffstat (limited to 'src')
-rw-r--r--src/config.rs50
1 files changed, 47 insertions, 3 deletions
diff --git a/src/config.rs b/src/config.rs
index e2c34b9..91bd1e8 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -28,14 +28,14 @@ use serde::{Deserialize, Serialize};
use crate::cliargs::CLIArgs;
/// Main struct of the config file. Contains substructs/headings in toml
-#[derive(Debug, Clone, Serialize, Deserialize)]
+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct BibiConfig {
pub general: General,
pub colors: Colors,
}
/// Substruct [general] in config.toml
-#[derive(Debug, Clone, Deserialize, Serialize)]
+#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
pub struct General {
pub bibfiles: Option<Vec<PathBuf>>,
pub editor: Option<String>,
@@ -44,7 +44,7 @@ pub struct General {
}
/// Substruct [colors] in config.toml
-#[derive(Debug, Clone, Deserialize, Serialize)]
+#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
pub struct Colors {
pub main_text_color: Color,
pub highlight_text_color: Color,
@@ -118,3 +118,47 @@ fn select_opener() -> String {
_ => panic!("Couldn't detect OS for setting correct opener"),
}
}
+
+#[cfg(test)]
+mod tests {
+ use figment::{
+ providers::{Format, Toml},
+ Figment,
+ };
+
+ use super::BibiConfig;
+
+ #[test]
+ fn parse_default_config() {
+ figment::Jail::expect_with(|jail| {
+ jail.create_file(
+ "bibiman.toml",
+ r#"
+ [general]
+ pdf_opener = "xdg-open"
+ url_opener = "xdg-open"
+
+ [colors]
+ main_text_color = "250"
+ highlight_text_color = "254"
+ entry_color = "36"
+ keyword_color = "101"
+ info_color = "99"
+ confirm_color = "47"
+ warn_color = "124"
+ bar_bg_color = "235"
+ popup_bg_color = "234"
+ selected_row_bg_color = "237"
+ "#,
+ )?;
+
+ let config: BibiConfig = Figment::new().merge(Toml::file("bibiman.toml")).extract()?;
+
+ let default_config: BibiConfig = BibiConfig::default();
+
+ assert_eq!(config, default_config);
+
+ Ok(())
+ });
+ }
+}