HasValue succeeds if array's value at the given index is 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.HasValue(1, 123)
(index int, value interface{})
| 201 | // array := NewArray(t, []interface{}{"foo", "123"}) |
| 202 | // array.HasValue(1, 123) |
| 203 | func (a *Array) HasValue(index int, value interface{}) *Array { |
| 204 | opChain := a.chain.enter("HasValue(%d)", index) |
| 205 | defer opChain.leave() |
| 206 | |
| 207 | if opChain.failed() { |
| 208 | return a |
| 209 | } |
| 210 | |
| 211 | if index < 0 || index >= len(a.value) { |
| 212 | opChain.fail(AssertionFailure{ |
| 213 | Type: AssertInRange, |
| 214 | Actual: &AssertionValue{index}, |
| 215 | Expected: &AssertionValue{AssertionRange{ |
| 216 | Min: 0, |
| 217 | Max: len(a.value) - 1, |
| 218 | }}, |
| 219 | Errors: []error{ |
| 220 | errors.New("expected: valid element index"), |
| 221 | }, |
| 222 | }) |
| 223 | return a |
| 224 | } |
| 225 | |
| 226 | expected, ok := canonValue(opChain, value) |
| 227 | if !ok { |
| 228 | return a |
| 229 | } |
| 230 | |
| 231 | if !reflect.DeepEqual(expected, a.value[index]) { |
| 232 | opChain.fail(AssertionFailure{ |
| 233 | Type: AssertEqual, |
| 234 | Actual: &AssertionValue{a.value[index]}, |
| 235 | Expected: &AssertionValue{value}, |
| 236 | Errors: []error{ |
| 237 | fmt.Errorf( |
| 238 | "expected: array value at index %d is equal to given value", |
| 239 | index), |
| 240 | }, |
| 241 | }) |
| 242 | return a |
| 243 | } |
| 244 | |
| 245 | return a |
| 246 | } |
| 247 | |
| 248 | // NotHasValue succeeds if array's value at the given index is not equal to given value. |
| 249 | // |