summaryrefslogtreecommitdiff
path: root/src/tests/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/mod.rs')
-rw-r--r--src/tests/mod.rs38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/tests/mod.rs b/src/tests/mod.rs
index 97a3a29..644c131 100644
--- a/src/tests/mod.rs
+++ b/src/tests/mod.rs
@@ -2,6 +2,8 @@ mod errors;
mod locations;
mod parsing;
+use crate::Configuration;
+
fn do_tests_in_dir(
dir: &str,
ext: &str,
@@ -32,3 +34,39 @@ fn do_tests_in_dir(
panic!("Error: {e}");
}
}
+
+#[test]
+fn misc() {
+ let conf = Configuration::load(
+ "<test configuration>",
+ "
+a = yes
+[foo]
+x = 5
+bar.y = 6
+"
+ .as_bytes(),
+ )
+ .unwrap();
+ // test section
+ assert_eq!(conf.section("foo").get("x"), Some("5"));
+ assert_eq!(conf.section("foo").get("bar.y"), Some("6"));
+ assert_eq!(conf.section("foo.bar").get("y"), Some("6"));
+ assert_eq!(conf.section("fob").get("x"), None);
+ // test get_or_default
+ assert_eq!(conf.get_or_default("foo.x", ""), "5");
+ assert_eq!(conf.get_or_default("foo.y", ""), "");
+ assert_eq!(conf.get_int_or_default("foo.x", 0).unwrap(), 5);
+ assert_eq!(conf.get_int_or_default("foo.y", 0).unwrap(), 0);
+ assert_eq!(conf.get_float_or_default("foo.x", 0.0).unwrap(), 5.0);
+ assert_eq!(conf.get_float_or_default("foo.y", 0.0).unwrap(), 0.0);
+ assert!(conf.get_bool_or_default("a", false).unwrap());
+ assert!(!conf.get_bool_or_default("aa", false).unwrap());
+ assert_eq!(conf.get_list_or_default("a", ["a"]), ["yes"]);
+ assert_eq!(conf.get_list_or_default("aa", ["a"]), ["a"]);
+ assert_eq!(conf.get_list_or_empty("a"), ["yes"]);
+ assert!(conf.get_list_or_empty("aa").is_empty());
+ let mut keys: Vec<_> = conf.keys().collect();
+ keys.sort();
+ assert_eq!(keys, ["a", "foo"]);
+}