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