@@ -51,6 +51,10 @@ type BasicSquash struct {
5151 Test Basic `mapstructure:",squash"`
5252}
5353
54+ type BasicJSONInline struct {
55+ Test Basic `json:",inline"`
56+ }
57+
5458type Embedded struct {
5559 Basic
5660 Vunique string
@@ -489,6 +493,62 @@ func TestDecodeFrom_BasicSquash(t *testing.T) {
489493 }
490494}
491495
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+
492552func TestDecode_Embedded (t * testing.T ) {
493553 t .Parallel ()
494554
0 commit comments