Skip to content

Commit 7cfc959

Browse files
committed
Add test for enums in ron
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
1 parent c2fe079 commit 7cfc959

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tests/ron_enum.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use config::{Config, File, FileFormat};
2+
use serde_derive::Deserialize;
3+
4+
#[derive(Debug, Deserialize)]
5+
#[serde(untagged)]
6+
enum A {
7+
VariantA { port: u16 },
8+
}
9+
10+
#[derive(Debug, Deserialize)]
11+
struct Settings {
12+
a: A,
13+
}
14+
15+
#[test]
16+
fn test_ron_enum() {
17+
let c = Config::builder()
18+
.add_source(File::from_str(
19+
r#"
20+
(
21+
a: VariantA ( port: 5000 )
22+
)
23+
"#,
24+
FileFormat::Ron,
25+
))
26+
.build()
27+
.unwrap();
28+
29+
// Deserialize the entire file as single struct
30+
let s = c.try_deserialize::<Settings>();
31+
assert!(s.is_ok(), "Not Ok(_): {}", s.unwrap_err());
32+
let s = s.unwrap();
33+
let A::VariantA { port } = s.a;
34+
assert_eq!(port, 5000);
35+
}

0 commit comments

Comments
 (0)