Skip to content

Commit

Permalink
Add test for serde renamed member
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Beyer <[email protected]>
  • Loading branch information
matthiasbeyer committed Feb 2, 2024
1 parent fd5aa23 commit 4d5c40d
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/rename.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#[test]
fn test_rename_attr() {
use config::{Config, File, FileFormat};

#[allow(unused)]
#[derive(serde::Deserialize, Debug)]
struct MyConfig {
#[serde(rename = "FooBar")]
foo_bar: String,
}

const MY_CONFIG: &str = r#"{
"FooBar": "Hello, world!"
}"#;

let cfg = Config::builder()
.add_source(File::from_str(MY_CONFIG, FileFormat::Json))
.build()
.unwrap();

let desered: Result<MyConfig, _> = cfg.try_deserialize();
assert!(desered.is_ok(), "Not Ok(_): {}", desered.unwrap_err());
}

0 comments on commit 4d5c40d

Please sign in to comment.