From de7cf3a5658e6913aab568287b0e6de948f975fa Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 19 Mar 2021 10:08:53 +0100 Subject: [PATCH] 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 c4fdeb23..d6e64030 100644 --- a/src/de.rs +++ b/src/de.rs @@ -463,3 +463,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(); + } +}