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{})
| 255 | // array := NewArray(t, []interface{}{"foo", "123"}) |
| 256 | // array.NotHasValue(1, 234) |
| 257 | func (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. |
| 303 | func (a *Array) First() *Value { |