| 1176 | } |
| 1177 | |
| 1178 | func TestSubsetNotSubset(t *testing.T) { |
| 1179 | t.Parallel() |
| 1180 | |
| 1181 | cases := []struct { |
| 1182 | list interface{} |
| 1183 | subset interface{} |
| 1184 | result bool |
| 1185 | message string |
| 1186 | }{ |
| 1187 | // cases that are expected to contain |
| 1188 | {[]int{1, 2, 3}, nil, true, `nil is the empty set which is a subset of every set`}, |
| 1189 | {[]int{1, 2, 3}, []int{}, true, `[] is a subset of ['\x01' '\x02' '\x03']`}, |
| 1190 | {[]int{1, 2, 3}, []int{1, 2}, true, `['\x01' '\x02'] is a subset of ['\x01' '\x02' '\x03']`}, |
| 1191 | {[]int{1, 2, 3}, []int{1, 2, 3}, true, `['\x01' '\x02' '\x03'] is a subset of ['\x01' '\x02' '\x03']`}, |
| 1192 | {[]string{"hello", "world"}, []string{"hello"}, true, `["hello"] is a subset of ["hello" "world"]`}, |
| 1193 | {map[string]string{ |
| 1194 | "a": "x", |
| 1195 | "c": "z", |
| 1196 | "b": "y", |
| 1197 | }, map[string]string{ |
| 1198 | "a": "x", |
| 1199 | "b": "y", |
| 1200 | }, true, `map["a":"x" "b":"y"] is a subset of map["a":"x" "b":"y" "c":"z"]`}, |
| 1201 | {[]string{"a", "b", "c"}, map[string]int{"a": 1, "c": 3}, true, `map["a":'\x01' "c":'\x03'] is a subset of ["a" "b" "c"]`}, |
| 1202 | |
| 1203 | // cases that are expected not to contain |
| 1204 | {[]string{"hello", "world"}, []string{"hello", "testify"}, false, `[]string{"hello", "world"} does not contain "testify"`}, |
| 1205 | {[]int{1, 2, 3}, []int{4, 5}, false, `[]int{1, 2, 3} does not contain 4`}, |
| 1206 | {[]int{1, 2, 3}, []int{1, 5}, false, `[]int{1, 2, 3} does not contain 5`}, |
| 1207 | {map[string]string{ |
| 1208 | "a": "x", |
| 1209 | "c": "z", |
| 1210 | "b": "y", |
| 1211 | }, map[string]string{ |
| 1212 | "a": "x", |
| 1213 | "b": "z", |
| 1214 | }, false, `map[string]string{"a":"x", "b":"y", "c":"z"} does not contain map[string]string{"a":"x", "b":"z"}`}, |
| 1215 | {map[string]string{ |
| 1216 | "a": "x", |
| 1217 | "b": "y", |
| 1218 | }, map[string]string{ |
| 1219 | "a": "x", |
| 1220 | "b": "y", |
| 1221 | "c": "z", |
| 1222 | }, false, `map[string]string{"a":"x", "b":"y"} does not contain map[string]string{"a":"x", "b":"y", "c":"z"}`}, |
| 1223 | {[]string{"a", "b", "c"}, map[string]int{"c": 3, "d": 4}, false, `[]string{"a", "b", "c"} does not contain "d"`}, |
| 1224 | } |
| 1225 | |
| 1226 | for _, c := range cases { |
| 1227 | t.Run("SubSet: "+c.message, func(t *testing.T) { |
| 1228 | mockT := new(mockTestingT) |
| 1229 | res := Subset(mockT, c.list, c.subset) |
| 1230 | |
| 1231 | if res != c.result { |
| 1232 | t.Errorf("Subset should return %t: %s", c.result, c.message) |
| 1233 | } |
| 1234 | if !c.result { |
| 1235 | expectedFail := c.message |