(t *testing.T)
| 986 | } |
| 987 | |
| 988 | func TestContainsNotContains(t *testing.T) { |
| 989 | |
| 990 | type A struct { |
| 991 | Name, Value string |
| 992 | } |
| 993 | list := []string{"Foo", "Bar"} |
| 994 | |
| 995 | complexList := []*A{ |
| 996 | {"b", "c"}, |
| 997 | {"d", "e"}, |
| 998 | {"g", "h"}, |
| 999 | {"j", "k"}, |
| 1000 | } |
| 1001 | simpleMap := map[interface{}]interface{}{"Foo": "Bar"} |
| 1002 | var zeroMap map[interface{}]interface{} |
| 1003 | |
| 1004 | cases := []struct { |
| 1005 | expected interface{} |
| 1006 | actual interface{} |
| 1007 | result bool |
| 1008 | }{ |
| 1009 | {"Hello World", "Hello", true}, |
| 1010 | {"Hello World", "Salut", false}, |
| 1011 | {list, "Bar", true}, |
| 1012 | {list, "Salut", false}, |
| 1013 | {complexList, &A{"g", "h"}, true}, |
| 1014 | {complexList, &A{"g", "e"}, false}, |
| 1015 | {simpleMap, "Foo", true}, |
| 1016 | {simpleMap, "Bar", false}, |
| 1017 | {zeroMap, "Bar", false}, |
| 1018 | } |
| 1019 | |
| 1020 | for _, c := range cases { |
| 1021 | t.Run(fmt.Sprintf("Contains(%#v, %#v)", c.expected, c.actual), func(t *testing.T) { |
| 1022 | mockT := new(testing.T) |
| 1023 | res := Contains(mockT, c.expected, c.actual) |
| 1024 | |
| 1025 | if res != c.result { |
| 1026 | if res { |
| 1027 | t.Errorf("Contains(%#v, %#v) should return true:\n\t%#v contains %#v", c.expected, c.actual, c.expected, c.actual) |
| 1028 | } else { |
| 1029 | t.Errorf("Contains(%#v, %#v) should return false:\n\t%#v does not contain %#v", c.expected, c.actual, c.expected, c.actual) |
| 1030 | } |
| 1031 | } |
| 1032 | }) |
| 1033 | } |
| 1034 | |
| 1035 | for _, c := range cases { |
| 1036 | t.Run(fmt.Sprintf("NotContains(%#v, %#v)", c.expected, c.actual), func(t *testing.T) { |
| 1037 | mockT := new(testing.T) |
| 1038 | res := NotContains(mockT, c.expected, c.actual) |
| 1039 | |
| 1040 | // NotContains should be inverse of Contains. If it's not, something is wrong |
| 1041 | if res == Contains(mockT, c.expected, c.actual) { |
| 1042 | if res { |
| 1043 | t.Errorf("NotContains(%#v, %#v) should return true:\n\t%#v does not contains %#v", c.expected, c.actual, c.expected, c.actual) |
| 1044 | } else { |
| 1045 | t.Errorf("NotContains(%#v, %#v) should return false:\n\t%#v contains %#v", c.expected, c.actual, c.expected, c.actual) |
nothing calls this directly
no test coverage detected