@@ -50,6 +50,10 @@ type BasicSquash struct {
5050 Test Basic `mapstructure:",squash"`
5151}
5252
53+ type BasicJSONInline struct {
54+ Test Basic `json:",inline"`
55+ }
56+
5357type Embedded struct {
5458 Basic
5559 Vunique string
@@ -488,6 +492,62 @@ func TestDecodeFrom_BasicSquash(t *testing.T) {
488492 }
489493}
490494
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+
491551func TestDecode_Embedded (t * testing.T ) {
492552 t .Parallel ()
493553
0 commit comments