| 1122 | } |
| 1123 | |
| 1124 | func TestSubsetNotSubset(t *testing.T) { |
| 1125 | cases := []struct { |
| 1126 | list interface{} |
| 1127 | subset interface{} |
| 1128 | result bool |
| 1129 | message string |
| 1130 | }{ |
| 1131 | // cases that are expected to contain |
| 1132 | {[]int{1, 2, 3}, nil, true, `nil is the empty set which is a subset of every set`}, |
| 1133 | {[]int{1, 2, 3}, []int{}, true, `[] is a subset of ['\x01' '\x02' '\x03']`}, |
| 1134 | {[]int{1, 2, 3}, []int{1, 2}, true, `['\x01' '\x02'] is a subset of ['\x01' '\x02' '\x03']`}, |
| 1135 | {[]int{1, 2, 3}, []int{1, 2, 3}, true, `['\x01' '\x02' '\x03'] is a subset of ['\x01' '\x02' '\x03']`}, |
| 1136 | {[]string{"hello", "world"}, []string{"hello"}, true, `["hello"] is a subset of ["hello" "world"]`}, |
| 1137 | {map[string]string{ |
| 1138 | "a": "x", |
| 1139 | "c": "z", |
| 1140 | "b": "y", |
| 1141 | }, map[string]string{ |
| 1142 | "a": "x", |
| 1143 | "b": "y", |
| 1144 | }, true, `map["a":"x" "b":"y"] is a subset of map["a":"x" "b":"y" "c":"z"]`}, |
| 1145 | |
| 1146 | // cases that are expected not to contain |
| 1147 | {[]string{"hello", "world"}, []string{"hello", "testify"}, false, `[]string{"hello", "world"} does not contain "testify"`}, |
| 1148 | {[]int{1, 2, 3}, []int{4, 5}, false, `[]int{1, 2, 3} does not contain 4`}, |
| 1149 | {[]int{1, 2, 3}, []int{1, 5}, false, `[]int{1, 2, 3} does not contain 5`}, |
| 1150 | {map[string]string{ |
| 1151 | "a": "x", |
| 1152 | "c": "z", |
| 1153 | "b": "y", |
| 1154 | }, map[string]string{ |
| 1155 | "a": "x", |
| 1156 | "b": "z", |
| 1157 | }, false, `map[string]string{"a":"x", "b":"y", "c":"z"} does not contain map[string]string{"a":"x", "b":"z"}`}, |
| 1158 | {map[string]string{ |
| 1159 | "a": "x", |
| 1160 | "b": "y", |
| 1161 | }, map[string]string{ |
| 1162 | "a": "x", |
| 1163 | "b": "y", |
| 1164 | "c": "z", |
| 1165 | }, false, `map[string]string{"a":"x", "b":"y"} does not contain map[string]string{"a":"x", "b":"y", "c":"z"}`}, |
| 1166 | } |
| 1167 | |
| 1168 | for _, c := range cases { |
| 1169 | t.Run("SubSet: "+c.message, func(t *testing.T) { |
| 1170 | |
| 1171 | mockT := new(mockTestingT) |
| 1172 | res := Subset(mockT, c.list, c.subset) |
| 1173 | |
| 1174 | if res != c.result { |
| 1175 | t.Errorf("Subset should return %t: %s", c.result, c.message) |
| 1176 | } |
| 1177 | if !c.result { |
| 1178 | expectedFail := c.message |
| 1179 | actualFail := mockT.errorString() |
| 1180 | if !strings.Contains(actualFail, expectedFail) { |
| 1181 | t.Log(actualFail) |