MCPcopy Index your code
hub / github.com/expr-lang/expr / TestContainsNotContains

Function TestContainsNotContains

internal/testify/assert/assertions_test.go:918–980  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

916}
917
918func 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)

Callers

nothing calls this directly

Calls 5

RunMethod · 0.80
SprintfMethod · 0.80
ContainsFunction · 0.70
NotContainsFunction · 0.70
ErrorfMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…