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

Method Value

array.go:163–187  ·  view source on GitHub ↗

Value returns a new Value instance with array element for given index. If index is out of array bounds, Value reports failure and returns empty (but non-nil) instance. Example: array := NewArray(t, []interface{}{"foo", 123}) array.Value(0).String().IsEqual("foo") array.Value(1).Number().IsEqua

(index int)

Source from the content-addressed store, hash-verified

161// array.Value(0).String().IsEqual("foo")
162// array.Value(1).Number().IsEqual(123)
163func (a *Array) Value(index int) *Value {
164 opChain := a.chain.enter("Value(%d)", index)
165 defer opChain.leave()
166
167 if opChain.failed() {
168 return newValue(opChain, nil)
169 }
170
171 if index < 0 || index >= len(a.value) {
172 opChain.fail(AssertionFailure{
173 Type: AssertInRange,
174 Actual: &AssertionValue{index},
175 Expected: &AssertionValue{AssertionRange{
176 Min: 0,
177 Max: len(a.value) - 1,
178 }},
179 Errors: []error{
180 errors.New("expected: valid element index"),
181 },
182 })
183 return newValue(opChain, nil)
184 }
185
186 return newValue(opChain, a.value[index])
187}
188
189// Deprecated: use Value instead.
190func (a *Array) Element(index int) *Value {

Callers 15

ElementMethod · 0.95
TestArray_GettersFunction · 0.95
TestExpect_PropagationFunction · 0.95
TestCookie_FailedChainFunction · 0.45
TestCookie_ConstructorsFunction · 0.45
TestArray_FailedChainFunction · 0.45
TestExpect_TraverseFunction · 0.45
TestExpect_BranchesFunction · 0.45
TestExpect_InheritanceFunction · 0.45
TestObject_FailedChainFunction · 0.45
TestIrisThingsFunction · 0.45

Calls 5

newValueFunction · 0.85
enterMethod · 0.80
leaveMethod · 0.80
failedMethod · 0.80
failMethod · 0.80

Tested by 15

TestArray_GettersFunction · 0.76
TestExpect_PropagationFunction · 0.76
TestCookie_FailedChainFunction · 0.36
TestCookie_ConstructorsFunction · 0.36
TestArray_FailedChainFunction · 0.36
TestExpect_TraverseFunction · 0.36
TestExpect_BranchesFunction · 0.36
TestExpect_InheritanceFunction · 0.36
TestObject_FailedChainFunction · 0.36
TestIrisThingsFunction · 0.36
TestIrisRedirectFunction · 0.36