@@ -50,6 +50,10 @@ type BasicSquash struct {
50
50
Test Basic `mapstructure:",squash"`
51
51
}
52
52
53
+ type BasicJSONInline struct {
54
+ Test Basic `json:",inline"`
55
+ }
56
+
53
57
type Embedded struct {
54
58
Basic
55
59
Vunique string
@@ -488,6 +492,62 @@ func TestDecodeFrom_BasicSquash(t *testing.T) {
488
492
}
489
493
}
490
494
495
+ func TestDecode_BasicJSONInline (t * testing.T ) {
496
+ t .Parallel ()
497
+
498
+ input := map [string ]interface {}{
499
+ "vstring" : "foo" ,
500
+ }
501
+
502
+ var result BasicJSONInline
503
+ d , err := NewDecoder (& DecoderConfig {TagName : "json" , SquashTagOption : "inline" , Result : & result })
504
+ if err != nil {
505
+ t .Fatalf ("got an err: %s" , err .Error ())
506
+ }
507
+
508
+ if err := d .Decode (input ); err != nil {
509
+ t .Fatalf ("got an err: %s" , err .Error ())
510
+ }
511
+
512
+ if result .Test .Vstring != "foo" {
513
+ t .Errorf ("vstring value should be 'foo': %#v" , result .Test .Vstring )
514
+ }
515
+ }
516
+
517
+ func TestDecodeFrom_BasicJSONInline (t * testing.T ) {
518
+ t .Parallel ()
519
+
520
+ var v interface {}
521
+ var ok bool
522
+
523
+ input := BasicJSONInline {
524
+ Test : Basic {
525
+ Vstring : "foo" ,
526
+ },
527
+ }
528
+
529
+ var result map [string ]interface {}
530
+ d , err := NewDecoder (& DecoderConfig {TagName : "json" , SquashTagOption : "inline" , Result : & result })
531
+ if err != nil {
532
+ t .Fatalf ("got an err: %s" , err .Error ())
533
+ }
534
+
535
+ if err := d .Decode (input ); err != nil {
536
+ t .Fatalf ("got an err: %s" , err .Error ())
537
+ }
538
+
539
+ if _ , ok = result ["Test" ]; ok {
540
+ t .Error ("test should not be present in map" )
541
+ }
542
+
543
+ v , ok = result ["Vstring" ]
544
+ if ! ok {
545
+ t .Error ("vstring should be present in map" )
546
+ } else if ! reflect .DeepEqual (v , "foo" ) {
547
+ t .Errorf ("vstring value should be 'foo': %#v" , v )
548
+ }
549
+ }
550
+
491
551
func TestDecode_Embedded (t * testing.T ) {
492
552
t .Parallel ()
493
553
0 commit comments