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

Method NotHasValue

array.go:257–300  ·  view source on GitHub ↗

NotHasValue succeeds if array's value at the given index is not equal to given value. Before comparison, both values are converted to canonical form. value should be map[string]interface{} or struct. Example: array := NewArray(t, []interface{}{"foo", "123"}) array.NotHasValue(1, 234)

(index int, value interface{})

Source from the content-addressed store, hash-verified

255// array := NewArray(t, []interface{}{"foo", "123"})
256// array.NotHasValue(1, 234)
257func (a *Array) NotHasValue(index int, value interface{}) *Array {
258 opChain := a.chain.enter("NotHasValue(%d)", index)
259 defer opChain.leave()
260
261 if opChain.failed() {
262 return a
263 }
264
265 if index < 0 || index >= len(a.value) {
266 opChain.fail(AssertionFailure{
267 Type: AssertInRange,
268 Actual: &AssertionValue{index},
269 Expected: &AssertionValue{AssertionRange{
270 Min: 0,
271 Max: len(a.value) - 1,
272 }},
273 Errors: []error{
274 errors.New("expected: valid element index"),
275 },
276 })
277 return a
278 }
279
280 expected, ok := canonValue(opChain, value)
281 if !ok {
282 return a
283 }
284
285 if reflect.DeepEqual(expected, a.value[index]) {
286 opChain.fail(AssertionFailure{
287 Type: AssertNotEqual,
288 Actual: &AssertionValue{a.value[index]},
289 Expected: &AssertionValue{value},
290 Errors: []error{
291 fmt.Errorf(
292 "expected: array value at index %d is not equal to given value",
293 index),
294 },
295 })
296 return a
297 }
298
299 return a
300}
301
302// Deprecated: use Value or HasValue instead.
303func (a *Array) First() *Value {

Callers 4

TestArray_FailedChainFunction · 0.45
TestArray_HasValueFunction · 0.45
TestObject_FailedChainFunction · 0.45
TestObject_HasValueFunction · 0.45

Calls 6

canonValueFunction · 0.85
enterMethod · 0.80
leaveMethod · 0.80
failedMethod · 0.80
failMethod · 0.80
ErrorfMethod · 0.65

Tested by 4

TestArray_FailedChainFunction · 0.36
TestArray_HasValueFunction · 0.36
TestObject_FailedChainFunction · 0.36
TestObject_HasValueFunction · 0.36