aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock2
-rw-r--r--Cargo.toml2
-rw-r--r--src/config.rs50
3 files changed, 50 insertions, 4 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 9c83245..3ad5cee 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -470,7 +470,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8cb01cd46b0cf372153850f4c6c272d9cbea2da513e07538405148f95bd789f3"
dependencies = [
"atomic",
+ "parking_lot",
"serde",
+ "tempfile",
"toml",
"uncased",
"version_check",
diff --git a/Cargo.toml b/Cargo.toml
index 2bd6a3f..bc73fcb 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -37,4 +37,4 @@ regex = "1.11.1"
ureq = "2.12.1"
# config = { version = "0.15.8", default-features = false, features = ["async", "async-trait", "convert-case", "convert_case", "toml"] }
serde = { version = "1.0.217", features = ["serde_derive"] }
-figment = { version = "0.10.19", features = [ "toml" ]}
+figment = { version = "0.10.19", features = [ "toml", "test" ]}
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(())
+ });
+ }
+}