diff options
author | Joel Gallant <joel@joelgallant.me> | 2020-04-28 19:59:19 -0600 |
---|---|---|
committer | John Brandt <johnb0@outlook.com> | 2021-05-04 10:30:31 -0600 |
commit | a6088847f06e99e3d15148c4cec9b7f5c469bf9b (patch) | |
tree | 928c80c9357224c2c56dab9e0fc4e21b5b127cac /tests/env.rs | |
parent | 86f87764fed802f876a7b8bf1fc7f824c28d28c8 (diff) |
Adds 'parse_numbers' options for Environment
This can be particularly helpful for `MY_SERVER_PORT=4334 cargo run`
Diffstat (limited to 'tests/env.rs')
-rw-r--r-- | tests/env.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/env.rs b/tests/env.rs index 578933e..fdeb373 100644 --- a/tests/env.rs +++ b/tests/env.rs @@ -83,3 +83,23 @@ fn test_custom_separator_behavior() { env::remove_var("C.B.A"); } + +fn test_parse_numbers() { + env::set_var("INT_VAL", "42"); + env::set_var("FLOAT_VAL", "42.2"); + + let environment = Environment::new().parse_numbers(true); + let values = environment.collect().unwrap(); + + assert_eq!( + values.get("int_val").unwrap().clone().into_int().ok(), + Some(42) + ); + assert_eq!( + values.get("float_val").unwrap().clone().into_float().ok(), + Some(42.2) + ); + + env::remove_var("INT_VAL"); + env::remove_var("FLOAT_VAL"); +} |