Skip to content

Commit

Permalink
Merge pull request #541 from matthiasbeyer/test-ron-enum
Browse files Browse the repository at this point in the history
Add test for enums in ron
  • Loading branch information
matthiasbeyer authored Feb 28, 2024
2 parents c2fe079 + 7cfc959 commit 9542239
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/ron_enum.rs
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);
}

0 comments on commit 9542239

Please sign in to comment.