From d8bb353580f8d26e1e3dc2422e421ce64aa85417 Mon Sep 17 00:00:00 2001 From: lukeflo Date: Sun, 23 Feb 2025 12:35:56 +0100 Subject: test module for config crate --- src/config.rs | 50 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 3 deletions(-) (limited to 'src/config.rs') 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>, pub editor: Option, @@ -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(()) + }); + } +} -- cgit v1.2.3