Skip to content

Commit fbbfdc2

Browse files
committed
Add test whether unreachable is reachable
Signed-off-by: Matthias Beyer <[email protected]>
1 parent 975d715 commit fbbfdc2

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

src/de.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,3 +463,57 @@ impl<'de> de::Deserializer<'de> for Config {
463463
identifier ignored_any unit_struct tuple_struct tuple
464464
}
465465
}
466+
467+
#[cfg(test)]
468+
mod tests {
469+
use super::*;
470+
use crate::File;
471+
use crate::FileFormat;
472+
use crate::Config;
473+
474+
475+
#[derive(Deserialize)]
476+
struct CFG {
477+
e: EnumConfig,
478+
}
479+
480+
#[derive(Deserialize)]
481+
enum EnumConfig {
482+
Foo,
483+
Bar { filename: std::path::PathBuf },
484+
}
485+
486+
#[test]
487+
fn test_unreachable_reachable_not_panicing_1() {
488+
let working_config = r#"
489+
e.bar.filename = "blah"
490+
"#;
491+
492+
let mut c = Config::default();
493+
c.merge(File::from_str(working_config, FileFormat::Toml)).unwrap();
494+
let c: CFG = c.try_into().unwrap();
495+
}
496+
#[test]
497+
fn test_unreachable_reachable_not_panicing_2() {
498+
let working_config = r#"
499+
e = "foo"
500+
"#;
501+
502+
let mut c = Config::default();
503+
c.merge(File::from_str(working_config, FileFormat::Toml)).unwrap();
504+
let c: CFG = c.try_into().unwrap();
505+
}
506+
507+
#[test]
508+
#[should_panic]
509+
fn test_unreachable_reachable_panicing() {
510+
let panicing_config = r#"
511+
e = "bar"
512+
"#;
513+
514+
let mut c = Config::default();
515+
c.merge(File::from_str(panicing_config, FileFormat::Toml)).unwrap();
516+
let c: CFG = c.try_into().unwrap();
517+
}
518+
519+
}

0 commit comments

Comments
 (0)