MCPcopy Create free account
hub / github.com/jmespath/go-jmespath / includeElement

Function includeElement

internal/testify/assert/assertions.go:702–735  ·  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

700// return (true, false) if element was not found.
701// return (true, true) if element was found.
702func includeElement(list interface{}, element interface{}) (ok, found bool) {
703
704 listValue := reflect.ValueOf(list)
705 listKind := reflect.TypeOf(list).Kind()
706 defer func() {
707 if e := recover(); e != nil {
708 ok = false
709 found = false
710 }
711 }()
712
713 if listKind == reflect.String {
714 elementValue := reflect.ValueOf(element)
715 return true, strings.Contains(listValue.String(), elementValue.String())
716 }
717
718 if listKind == reflect.Map {
719 mapKeys := listValue.MapKeys()
720 for i := 0; i < len(mapKeys); i++ {
721 if ObjectsAreEqual(mapKeys[i].Interface(), element) {
722 return true, true
723 }
724 }
725 return true, false
726 }
727
728 for i := 0; i < listValue.Len(); i++ {
729 if ObjectsAreEqual(listValue.Index(i).Interface(), element) {
730 return true, true
731 }
732 }
733 return true, false
734
735}
736
737// Contains asserts that the specified string, list(array, slice...) or map contains the
738// specified substring or element.

Callers 5

Test_includeElementFunction · 0.85
ContainsFunction · 0.85
NotContainsFunction · 0.85
SubsetFunction · 0.85
NotSubsetFunction · 0.85

Calls 4

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

Tested by 1

Test_includeElementFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…