File tree Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Original file line number Diff line number Diff line change @@ -463,3 +463,57 @@ impl<'de> de::Deserializer<'de> for Config {
463
463
identifier ignored_any unit_struct tuple_struct tuple
464
464
}
465
465
}
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
+ }
You can’t perform that action at this time.
0 commit comments