Skip to content

Commit

Permalink
Add test for empty inner object
Browse files Browse the repository at this point in the history
Adds a test for an empty inner object as reported in #461.

Reported-by: Zhenchi <zhongzc_arch@outlook.com>
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
  • Loading branch information
matthiasbeyer committed Sep 28, 2023
1 parent f57eadd commit f934f5d
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/empty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,25 @@ fn empty_deserializes() {
assert_eq!(s.foo, 0);
assert_eq!(s.bar, 0);
}

#[derive(Debug, Serialize, Deserialize, PartialEq)]
struct A {
b: Option<B>,
}
#[derive(Debug, Serialize, Deserialize, PartialEq)]
struct B {}

#[test]
fn empty_inner_obj() {
let a = A {
b: Some(B {})
};

let de_from_default_object: A = Config::builder()
.add_source(Config::try_from(&a).unwrap())
.build()
.unwrap()
.try_deserialize()
.unwrap();
assert_eq!(a, de_from_default_object); // Failed
}

0 comments on commit f934f5d

Please sign in to comment.