-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #541 from matthiasbeyer/test-ron-enum
Add test for enums in ron
- Loading branch information
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use config::{Config, File, FileFormat}; | ||
use serde_derive::Deserialize; | ||
|
||
#[derive(Debug, Deserialize)] | ||
#[serde(untagged)] | ||
enum A { | ||
VariantA { port: u16 }, | ||
} | ||
|
||
#[derive(Debug, Deserialize)] | ||
struct Settings { | ||
a: A, | ||
} | ||
|
||
#[test] | ||
fn test_ron_enum() { | ||
let c = Config::builder() | ||
.add_source(File::from_str( | ||
r#" | ||
( | ||
a: VariantA ( port: 5000 ) | ||
) | ||
"#, | ||
FileFormat::Ron, | ||
)) | ||
.build() | ||
.unwrap(); | ||
|
||
// Deserialize the entire file as single struct | ||
let s = c.try_deserialize::<Settings>(); | ||
assert!(s.is_ok(), "Not Ok(_): {}", s.unwrap_err()); | ||
let s = s.unwrap(); | ||
let A::VariantA { port } = s.a; | ||
assert_eq!(port, 5000); | ||
} |