(t *testing.T)
| 916 | } |
| 917 | |
| 918 | func TestContainsNotContains(t *testing.T) { |
| 919 | |
| 920 | type A struct { |
| 921 | Name, Value string |
| 922 | } |
| 923 | list := []string{"Foo", "Bar"} |
| 924 | |
| 925 | complexList := []*A{ |
| 926 | {"b", "c"}, |
| 927 | {"d", "e"}, |
| 928 | {"g", "h"}, |
| 929 | {"j", "k"}, |
| 930 | } |
| 931 | simpleMap := map[interface{}]interface{}{"Foo": "Bar"} |
| 932 | var zeroMap map[interface{}]interface{} |
| 933 | |
| 934 | cases := []struct { |
| 935 | expected interface{} |
| 936 | actual interface{} |
| 937 | result bool |
| 938 | }{ |
| 939 | {"Hello World", "Hello", true}, |
| 940 | {"Hello World", "Salut", false}, |
| 941 | {list, "Bar", true}, |
| 942 | {list, "Salut", false}, |
| 943 | {complexList, &A{"g", "h"}, true}, |
| 944 | {complexList, &A{"g", "e"}, false}, |
| 945 | {simpleMap, "Foo", true}, |
| 946 | {simpleMap, "Bar", false}, |
| 947 | {zeroMap, "Bar", false}, |
| 948 | } |
| 949 | |
| 950 | for _, c := range cases { |
| 951 | t.Run(fmt.Sprintf("Contains(%#v, %#v)", c.expected, c.actual), func(t *testing.T) { |
| 952 | mockT := new(testing.T) |
| 953 | res := Contains(mockT, c.expected, c.actual) |
| 954 | |
| 955 | if res != c.result { |
| 956 | if res { |
| 957 | t.Errorf("Contains(%#v, %#v) should return true:\n\t%#v contains %#v", c.expected, c.actual, c.expected, c.actual) |
| 958 | } else { |
| 959 | t.Errorf("Contains(%#v, %#v) should return false:\n\t%#v does not contain %#v", c.expected, c.actual, c.expected, c.actual) |
| 960 | } |
| 961 | } |
| 962 | }) |
| 963 | } |
| 964 | |
| 965 | for _, c := range cases { |
| 966 | t.Run(fmt.Sprintf("NotContains(%#v, %#v)", c.expected, c.actual), func(t *testing.T) { |
| 967 | mockT := new(testing.T) |
| 968 | res := NotContains(mockT, c.expected, c.actual) |
| 969 | |
| 970 | // NotContains should be inverse of Contains. If it's not, something is wrong |
| 971 | if res == Contains(mockT, c.expected, c.actual) { |
| 972 | if res { |
| 973 | t.Errorf("NotContains(%#v, %#v) should return true:\n\t%#v does not contains %#v", c.expected, c.actual, c.expected, c.actual) |
| 974 | } else { |
| 975 | 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
searching dependent graphs…