Value returns a new Value instance with value for given key. Example: object := NewObject(t, map[string]interface{}{"foo": 123}) object.Value("foo").Number().IsEqual(123)
(key string)
| 212 | // object := NewObject(t, map[string]interface{}{"foo": 123}) |
| 213 | // object.Value("foo").Number().IsEqual(123) |
| 214 | func (o *Object) Value(key string) *Value { |
| 215 | opChain := o.chain.enter("Value(%q)", key) |
| 216 | defer opChain.leave() |
| 217 | |
| 218 | if opChain.failed() { |
| 219 | return newValue(opChain, nil) |
| 220 | } |
| 221 | |
| 222 | value, ok := o.value[key] |
| 223 | |
| 224 | if !ok { |
| 225 | opChain.fail(AssertionFailure{ |
| 226 | Type: AssertContainsKey, |
| 227 | Actual: &AssertionValue{o.value}, |
| 228 | Expected: &AssertionValue{key}, |
| 229 | Errors: []error{ |
| 230 | errors.New("expected: map contains key"), |
| 231 | }, |
| 232 | }) |
| 233 | return newValue(opChain, nil) |
| 234 | } |
| 235 | |
| 236 | return newValue(opChain, value) |
| 237 | } |
| 238 | |
| 239 | // HasValue succeeds if object's value for given key is equal to given value. |
| 240 | // Before comparison, both values are converted to canonical form. |