Skip to content

Commit b4984bb

Browse files
committed
Add testcase for lowercase log::Level deserialization
Signed-off-by: Matthias Beyer <[email protected]>
1 parent 00eb743 commit b4984bb

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tests/log.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ extern crate log;
33

44
#[macro_use]
55
extern crate serde_derive;
6+
extern crate serde_json;
67

78
use config::*;
89

@@ -26,3 +27,26 @@ fn test_load_level_uppercase() {
2627
assert_eq!(l, log::Level::Error);
2728
}
2829

30+
#[test]
31+
fn test_load_level_lowercase() {
32+
// to verify that this works
33+
{
34+
use std::str::FromStr;
35+
let l = log::Level::from_str("error").unwrap();
36+
assert_eq!(l, log::Level::Error);
37+
}
38+
39+
let s = r#"{ "log": "error" }"#;
40+
41+
// to confirm serde_json works as expected
42+
{
43+
let j: Settings = serde_json::from_str(s).unwrap();
44+
assert_eq!(j.log, log::Level::Error);
45+
}
46+
47+
let c = config(s);
48+
assert_eq!(c.get_str("log").unwrap(), "error");
49+
let l = c.get::<log::Level>("log");
50+
assert!(l.is_ok(), "Expected Ok(_) for {:?}", l);
51+
assert_eq!(l.unwrap(), log::Level::Error);
52+
}

0 commit comments

Comments
 (0)