MCPcopy Index your code
hub / github.com/gavv/httpexpect / TestArray_FindAll

Function TestArray_FindAll

array_test.go:2010–2165  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2008}
2009
2010func TestArray_FindAll(t *testing.T) {
2011 t.Run("elements of same type", func(t *testing.T) {
2012 reporter := newMockReporter(t)
2013 array := NewArray(reporter, []interface{}{1, 2, 3, 4, 5, 6})
2014
2015 foundValues := array.FindAll(func(index int, value *Value) bool {
2016 return value.Raw() == 2.0 || value.Raw() == 5.0
2017 })
2018
2019 actual := []interface{}{}
2020 for _, value := range foundValues {
2021 actual = append(actual, value.Raw())
2022 }
2023
2024 assert.Equal(t, []interface{}{2.0, 5.0}, actual)
2025 assert.Equal(t, array.Raw(), []interface{}{1.0, 2.0, 3.0, 4.0, 5.0, 6.0})
2026
2027 array.chain.assert(t, success)
2028 for _, value := range foundValues {
2029 value.chain.assert(t, success)
2030 }
2031 })
2032
2033 t.Run("elements of different types", func(t *testing.T) {
2034 reporter := newMockReporter(t)
2035 array := NewArray(reporter, []interface{}{1.0, "foo", true, "bar"})
2036
2037 foundValues := array.FindAll(func(index int, value *Value) bool {
2038 stringifiedValue := value.String().Raw()
2039 return stringifiedValue != ""
2040 })
2041
2042 actual := []interface{}{}
2043 for _, value := range foundValues {
2044 actual = append(actual, value.Raw())
2045 }
2046
2047 assert.Equal(t, []interface{}{"foo", "bar"}, actual)
2048 assert.Equal(t, array.Raw(), []interface{}{1.0, "foo", true, "bar"})
2049
2050 array.chain.assert(t, success)
2051 for _, value := range foundValues {
2052 value.chain.assert(t, success)
2053 }
2054 })
2055
2056 t.Run("no match", func(t *testing.T) {
2057 reporter := newMockReporter(t)
2058 array := NewArray(reporter, []interface{}{1.0, "foo", true, "bar"})
2059
2060 foundValues := array.FindAll(func(index int, value *Value) bool {
2061 return value.Raw() == 2.0
2062 })
2063
2064 actual := []interface{}{}
2065 for _, value := range foundValues {
2066 actual = append(actual, value.Raw())
2067 }

Callers

nothing calls this directly

Calls 8

FindAllMethod · 0.95
RawMethod · 0.95
newMockReporterFunction · 0.85
NewArrayFunction · 0.85
assertMethod · 0.80
RawMethod · 0.45
EqualMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…