File tree Expand file tree Collapse file tree 1 file changed +55
-0
lines changed
Expand file tree Collapse file tree 1 file changed +55
-0
lines changed Original file line number Diff line number Diff line change @@ -463,3 +463,58 @@ 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 :: Config ;
471+ use crate :: File ;
472+ use crate :: FileFormat ;
473+
474+ #[ derive( Deserialize ) ]
475+ struct CFG {
476+ e : EnumConfig ,
477+ }
478+
479+ #[ derive( Deserialize ) ]
480+ enum EnumConfig {
481+ Foo ,
482+ Bar { filename : std:: path:: PathBuf } ,
483+ }
484+
485+ #[ test]
486+ fn test_unreachable_reachable_not_panicing_1 ( ) {
487+ let working_config = r#"
488+ e.bar.filename = "blah"
489+ "# ;
490+
491+ let mut c = Config :: default ( ) ;
492+ c. merge ( File :: from_str ( working_config, FileFormat :: Toml ) )
493+ . 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 ) )
504+ . unwrap ( ) ;
505+ let c: CFG = c. try_into ( ) . unwrap ( ) ;
506+ }
507+
508+ #[ test]
509+ #[ should_panic]
510+ fn test_unreachable_reachable_panicing ( ) {
511+ let panicing_config = r#"
512+ e = "bar"
513+ "# ;
514+
515+ let mut c = Config :: default ( ) ;
516+ c. merge ( File :: from_str ( panicing_config, FileFormat :: Toml ) )
517+ . unwrap ( ) ;
518+ let c: CFG = c. try_into ( ) . unwrap ( ) ;
519+ }
520+ }
You can’t perform that action at this time.
0 commit comments