Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,3 +459,58 @@ impl<'de> de::Deserializer<'de> for Config {
identifier ignored_any unit_struct tuple_struct tuple
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::Config;
use crate::File;
use crate::FileFormat;

#[derive(Deserialize)]
struct CFG {
e: EnumConfig,
}

#[derive(Deserialize)]
enum EnumConfig {
Foo,
Bar { filename: std::path::PathBuf },
}

#[test]
fn test_unreachable_reachable_not_panicing_1() {
let working_config = r#"
e.Bar.filename = "blah"
"#;

let mut c = Config::default();
c.merge(File::from_str(working_config, FileFormat::Toml))
.unwrap();
let c: CFG = c.try_into().unwrap();
}
#[test]
fn test_unreachable_reachable_not_panicing_2() {
let working_config = r#"
e = "Foo"
"#;

let mut c = Config::default();
c.merge(File::from_str(working_config, FileFormat::Toml))
.unwrap();
let c: CFG = c.try_into().unwrap();
}

#[test]
#[should_panic]
fn test_unreachable_reachable_panicing() {
let panicing_config = r#"
e = "Bar"
"#;

let mut c = Config::default();
c.merge(File::from_str(panicing_config, FileFormat::Toml))
.unwrap();
let c: CFG = c.try_into().unwrap();
}
}