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 @@ -459,3 +459,58 @@ impl<'de> de::Deserializer<'de> for Config {
459
459
identifier ignored_any unit_struct tuple_struct tuple
460
460
}
461
461
}
462
+
463
+ #[ cfg( test) ]
464
+ mod tests {
465
+ use super :: * ;
466
+ use crate :: Config ;
467
+ use crate :: File ;
468
+ use crate :: FileFormat ;
469
+
470
+ #[ derive( Deserialize ) ]
471
+ struct CFG {
472
+ e : EnumConfig ,
473
+ }
474
+
475
+ #[ derive( Deserialize ) ]
476
+ enum EnumConfig {
477
+ Foo ,
478
+ Bar { filename : std:: path:: PathBuf } ,
479
+ }
480
+
481
+ #[ test]
482
+ fn test_unreachable_reachable_not_panicing_1 ( ) {
483
+ let working_config = r#"
484
+ e.bar.filename = "blah"
485
+ "# ;
486
+
487
+ let mut c = Config :: default ( ) ;
488
+ c. merge ( File :: from_str ( working_config, FileFormat :: Toml ) )
489
+ . unwrap ( ) ;
490
+ let c: CFG = c. try_into ( ) . unwrap ( ) ;
491
+ }
492
+ #[ test]
493
+ fn test_unreachable_reachable_not_panicing_2 ( ) {
494
+ let working_config = r#"
495
+ e = "foo"
496
+ "# ;
497
+
498
+ let mut c = Config :: default ( ) ;
499
+ c. merge ( File :: from_str ( working_config, FileFormat :: Toml ) )
500
+ . unwrap ( ) ;
501
+ let c: CFG = c. try_into ( ) . unwrap ( ) ;
502
+ }
503
+
504
+ #[ test]
505
+ #[ should_panic]
506
+ fn test_unreachable_reachable_panicing ( ) {
507
+ let panicing_config = r#"
508
+ e = "bar"
509
+ "# ;
510
+
511
+ let mut c = Config :: default ( ) ;
512
+ c. merge ( File :: from_str ( panicing_config, FileFormat :: Toml ) )
513
+ . unwrap ( ) ;
514
+ let c: CFG = c. try_into ( ) . unwrap ( ) ;
515
+ }
516
+ }
You can’t perform that action at this time.
0 commit comments