From fd22fe75cadbfb203204d2cf52c4e6fb49a957bd Mon Sep 17 00:00:00 2001 From: Christian Fochler Date: Sun, 28 Jan 2018 21:16:41 +0100 Subject: add tests for environment handling --- tests/env.rs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 tests/env.rs (limited to 'tests') diff --git a/tests/env.rs b/tests/env.rs new file mode 100644 index 0000000..fc93f15 --- /dev/null +++ b/tests/env.rs @@ -0,0 +1,38 @@ +extern crate config; + +use config::*; +use std::env; + +#[test] +fn test_default() { + env::set_var("A_B_C", "abc"); + + let environment = Environment::new(); + + assert!(environment.collect().unwrap().contains_key("a_b_c")); + + env::remove_var("A_B_C"); +} + +#[test] +fn test_prefix_is_removed_from_key() { + env::set_var("B_A_C", "abc"); + + let environment = Environment::with_prefix("B_"); + + assert!(environment.collect().unwrap().contains_key("a_c")); + + env::remove_var("B_A_C"); +} + +#[test] +fn test_separator_behavior() { + env::set_var("C_B_A", "abc"); + + let mut environment = Environment::with_prefix("C"); + environment.separator("_"); + + assert!(environment.collect().unwrap().contains_key("b.a")); + + env::remove_var("C_B_A"); +} -- cgit v1.2.3