diff options
Diffstat (limited to 'tests/get_scalar.rs')
-rw-r--r-- | tests/get_scalar.rs | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/get_scalar.rs b/tests/get_scalar.rs new file mode 100644 index 0000000..08d8507 --- /dev/null +++ b/tests/get_scalar.rs @@ -0,0 +1,52 @@ +extern crate config; + +use config::*; + +fn make() -> Config { + let mut c = Config::default(); + c.merge(File::new("tests/Settings", FileFormat::Toml)) + .unwrap(); + + c +} + +#[test] +fn test_scalar() { + let c = make(); + + assert!(c.get("debug").ok() == Some(true)); + assert!(c.get("production").ok() == Some(false)); +} + +#[test] +fn test_scalar_type_loose() { + let c = make(); + + assert!(c.get("debug").ok() == Some(true)); + assert!(c.get("debug").ok() == Some("true".to_string())); + assert!(c.get("debug").ok() == Some(1)); + assert!(c.get("debug").ok() == Some(1.0)); + + assert!(c.get("debug_s").ok() == Some(true)); + assert!(c.get("debug_s").ok() == Some("true".to_string())); + assert!(c.get("debug_s").ok() == Some(1)); + assert!(c.get("debug_s").ok() == Some(1.0)); + + assert!(c.get("production").ok() == Some(false)); + assert!(c.get("production").ok() == Some("false".to_string())); + assert!(c.get("production").ok() == Some(0)); + assert!(c.get("production").ok() == Some(0.0)); + + assert!(c.get("production_s").ok() == Some(false)); + assert!(c.get("production_s").ok() == Some("false".to_string())); + assert!(c.get("production_s").ok() == Some(0)); + assert!(c.get("production_s").ok() == Some(0.0)); +} + +#[test] +fn test_get_scalar_path() { + let c = make(); + + assert_eq!(c.get("place.favorite").ok(), Some(false)); + assert_eq!(c.get("place.creator.name").ok(), Some("John Smith".to_string())); +} |