| 1052 | } |
| 1053 | |
| 1054 | func TestSubsetNotSubset(t *testing.T) { |
| 1055 | cases := []struct { |
| 1056 | list interface{} |
| 1057 | subset interface{} |
| 1058 | result bool |
| 1059 | message string |
| 1060 | }{ |
| 1061 | // cases that are expected to contain |
| 1062 | {[]int{1, 2, 3}, nil, true, `nil is the empty set which is a subset of every set`}, |
| 1063 | {[]int{1, 2, 3}, []int{}, true, `[] is a subset of ['\x01' '\x02' '\x03']`}, |
| 1064 | {[]int{1, 2, 3}, []int{1, 2}, true, `['\x01' '\x02'] is a subset of ['\x01' '\x02' '\x03']`}, |
| 1065 | {[]int{1, 2, 3}, []int{1, 2, 3}, true, `['\x01' '\x02' '\x03'] is a subset of ['\x01' '\x02' '\x03']`}, |
| 1066 | {[]string{"hello", "world"}, []string{"hello"}, true, `["hello"] is a subset of ["hello" "world"]`}, |
| 1067 | {map[string]string{ |
| 1068 | "a": "x", |
| 1069 | "c": "z", |
| 1070 | "b": "y", |
| 1071 | }, map[string]string{ |
| 1072 | "a": "x", |
| 1073 | "b": "y", |
| 1074 | }, true, `map["a":"x" "b":"y"] is a subset of map["a":"x" "b":"y" "c":"z"]`}, |
| 1075 | |
| 1076 | // cases that are expected not to contain |
| 1077 | {[]string{"hello", "world"}, []string{"hello", "testify"}, false, `[]string{"hello", "world"} does not contain "testify"`}, |
| 1078 | {[]int{1, 2, 3}, []int{4, 5}, false, `[]int{1, 2, 3} does not contain 4`}, |
| 1079 | {[]int{1, 2, 3}, []int{1, 5}, false, `[]int{1, 2, 3} does not contain 5`}, |
| 1080 | {map[string]string{ |
| 1081 | "a": "x", |
| 1082 | "c": "z", |
| 1083 | "b": "y", |
| 1084 | }, map[string]string{ |
| 1085 | "a": "x", |
| 1086 | "b": "z", |
| 1087 | }, false, `map[string]string{"a":"x", "b":"y", "c":"z"} does not contain map[string]string{"a":"x", "b":"z"}`}, |
| 1088 | {map[string]string{ |
| 1089 | "a": "x", |
| 1090 | "b": "y", |
| 1091 | }, map[string]string{ |
| 1092 | "a": "x", |
| 1093 | "b": "y", |
| 1094 | "c": "z", |
| 1095 | }, false, `map[string]string{"a":"x", "b":"y"} does not contain map[string]string{"a":"x", "b":"y", "c":"z"}`}, |
| 1096 | } |
| 1097 | |
| 1098 | for _, c := range cases { |
| 1099 | t.Run("SubSet: "+c.message, func(t *testing.T) { |
| 1100 | |
| 1101 | mockT := new(mockTestingT) |
| 1102 | res := Subset(mockT, c.list, c.subset) |
| 1103 | |
| 1104 | if res != c.result { |
| 1105 | t.Errorf("Subset should return %t: %s", c.result, c.message) |
| 1106 | } |
| 1107 | if !c.result { |
| 1108 | expectedFail := c.message |
| 1109 | actualFail := mockT.errorString() |
| 1110 | if !strings.Contains(actualFail, expectedFail) { |
| 1111 | t.Log(actualFail) |