From 508e4e648d07771ce2443da34330c76df0f5dc48 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 19 Mar 2021 10:08:53 +0100 Subject: [PATCH 1/2] Add test whether unreachable is reachable Signed-off-by: Matthias Beyer --- src/de.rs | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/src/de.rs b/src/de.rs index a7a6fb49..82bac8a9 100644 --- a/src/de.rs +++ b/src/de.rs @@ -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(); + } +} From eda291320bd73b45aa31c84e7756ad51c93713c9 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 8 Jun 2021 09:10:52 +0200 Subject: [PATCH 2/2] Try with uppercase "Bar" --- src/de.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/de.rs b/src/de.rs index 82bac8a9..97db57a0 100644 --- a/src/de.rs +++ b/src/de.rs @@ -481,7 +481,7 @@ mod tests { #[test] fn test_unreachable_reachable_not_panicing_1() { let working_config = r#" - e.bar.filename = "blah" + e.Bar.filename = "blah" "#; let mut c = Config::default(); @@ -492,7 +492,7 @@ mod tests { #[test] fn test_unreachable_reachable_not_panicing_2() { let working_config = r#" - e = "foo" + e = "Foo" "#; let mut c = Config::default(); @@ -505,7 +505,7 @@ mod tests { #[should_panic] fn test_unreachable_reachable_panicing() { let panicing_config = r#" - e = "bar" + e = "Bar" "#; let mut c = Config::default();