@@ -816,7 +816,6 @@ func Subset(t TestingT, list, subset interface{}, msgAndArgs ...interface{}) (ok
816816 return true // we consider nil to be equal to the nil set
817817 }
818818
819- subsetValue := reflect .ValueOf (subset )
820819 defer func () {
821820 if e := recover (); e != nil {
822821 ok = false
@@ -826,14 +825,32 @@ func Subset(t TestingT, list, subset interface{}, msgAndArgs ...interface{}) (ok
826825 listKind := reflect .TypeOf (list ).Kind ()
827826 subsetKind := reflect .TypeOf (subset ).Kind ()
828827
829- if listKind != reflect .Array && listKind != reflect .Slice {
828+ if listKind != reflect .Array && listKind != reflect .Slice && listKind != reflect . Map {
830829 return Fail (t , fmt .Sprintf ("%q has an unsupported type %s" , list , listKind ), msgAndArgs ... )
831830 }
832831
833- if subsetKind != reflect .Array && subsetKind != reflect .Slice {
832+ if subsetKind != reflect .Array && subsetKind != reflect .Slice && listKind != reflect . Map {
834833 return Fail (t , fmt .Sprintf ("%q has an unsupported type %s" , subset , subsetKind ), msgAndArgs ... )
835834 }
836835
836+ subsetValue := reflect .ValueOf (subset )
837+ if subsetKind == reflect .Map && listKind == reflect .Map {
838+ listValue := reflect .ValueOf (list )
839+ subsetKeys := subsetValue .MapKeys ()
840+
841+ for i := 0 ; i < len (subsetKeys ); i ++ {
842+ subsetKey := subsetKeys [i ]
843+ subsetElement := subsetValue .MapIndex (subsetKey ).Interface ()
844+ listElement := listValue .MapIndex (subsetKey ).Interface ()
845+
846+ if ! ObjectsAreEqual (subsetElement , listElement ) {
847+ return Fail (t , fmt .Sprintf ("\" %s\" does not contain \" %s\" " , list , subsetElement ), msgAndArgs ... )
848+ }
849+ }
850+
851+ return true
852+ }
853+
837854 for i := 0 ; i < subsetValue .Len (); i ++ {
838855 element := subsetValue .Index (i ).Interface ()
839856 ok , found := containsElement (list , element )
@@ -860,7 +877,6 @@ func NotSubset(t TestingT, list, subset interface{}, msgAndArgs ...interface{})
860877 return Fail (t , "nil is the empty set which is a subset of every set" , msgAndArgs ... )
861878 }
862879
863- subsetValue := reflect .ValueOf (subset )
864880 defer func () {
865881 if e := recover (); e != nil {
866882 ok = false
@@ -870,14 +886,32 @@ func NotSubset(t TestingT, list, subset interface{}, msgAndArgs ...interface{})
870886 listKind := reflect .TypeOf (list ).Kind ()
871887 subsetKind := reflect .TypeOf (subset ).Kind ()
872888
873- if listKind != reflect .Array && listKind != reflect .Slice {
889+ if listKind != reflect .Array && listKind != reflect .Slice && listKind != reflect . Map {
874890 return Fail (t , fmt .Sprintf ("%q has an unsupported type %s" , list , listKind ), msgAndArgs ... )
875891 }
876892
877- if subsetKind != reflect .Array && subsetKind != reflect .Slice {
893+ if subsetKind != reflect .Array && subsetKind != reflect .Slice && listKind != reflect . Map {
878894 return Fail (t , fmt .Sprintf ("%q has an unsupported type %s" , subset , subsetKind ), msgAndArgs ... )
879895 }
880896
897+ subsetValue := reflect .ValueOf (subset )
898+ if subsetKind == reflect .Map && listKind == reflect .Map {
899+ listValue := reflect .ValueOf (list )
900+ subsetKeys := subsetValue .MapKeys ()
901+
902+ for i := 0 ; i < len (subsetKeys ); i ++ {
903+ subsetKey := subsetKeys [i ]
904+ subsetElement := subsetValue .MapIndex (subsetKey ).Interface ()
905+ listElement := listValue .MapIndex (subsetKey ).Interface ()
906+
907+ if ! ObjectsAreEqual (subsetElement , listElement ) {
908+ return true
909+ }
910+ }
911+
912+ return Fail (t , fmt .Sprintf ("%q is a subset of %q" , subset , list ), msgAndArgs ... )
913+ }
914+
881915 for i := 0 ; i < subsetValue .Len (); i ++ {
882916 element := subsetValue .Index (i ).Interface ()
883917 ok , found := containsElement (list , element )
0 commit comments