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

Function containsElement

internal/testify/assert/assertions.go:881–918  ·  view source on GitHub ↗

containsElement try loop over the list check if the list includes the element. return (false, false) if impossible. return (true, false) if element was not found. return (true, true) if element was found.

(list interface{}, element interface{})

Source from the content-addressed store, hash-verified

879// return (true, false) if element was not found.
880// return (true, true) if element was found.
881func containsElement(list interface{}, element interface{}) (ok, found bool) {
882
883 listValue := reflect.ValueOf(list)
884 listType := reflect.TypeOf(list)
885 if listType == nil {
886 return false, false
887 }
888 listKind := listType.Kind()
889 defer func() {
890 if e := recover(); e != nil {
891 ok = false
892 found = false
893 }
894 }()
895
896 if listKind == reflect.String {
897 elementValue := reflect.ValueOf(element)
898 return true, strings.Contains(listValue.String(), elementValue.String())
899 }
900
901 if listKind == reflect.Map {
902 mapKeys := listValue.MapKeys()
903 for i := 0; i < len(mapKeys); i++ {
904 if ObjectsAreEqual(mapKeys[i].Interface(), element) {
905 return true, true
906 }
907 }
908 return true, false
909 }
910
911 for i := 0; i < listValue.Len(); i++ {
912 if ObjectsAreEqual(listValue.Index(i).Interface(), element) {
913 return true, true
914 }
915 }
916 return true, false
917
918}
919
920// Contains asserts that the specified string, list(array, slice...) or map contains the
921// specified substring or element.

Callers 5

Test_containsElementFunction · 0.85
ContainsFunction · 0.85
NotContainsFunction · 0.85
SubsetFunction · 0.85
NotSubsetFunction · 0.85

Calls 4

ObjectsAreEqualFunction · 0.85
StringMethod · 0.65
ContainsMethod · 0.45
LenMethod · 0.45

Tested by 1

Test_containsElementFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…