Object returns a new Object attached to underlying value. If underlying value is not an object (map[string]interface{}), failure is reported and empty (but non-nil) value is returned. Example: value := NewValue(t, map[string]interface{}{"foo": 123}) value.Object().ContainsKey("foo")
()
| 228 | // value := NewValue(t, map[string]interface{}{"foo": 123}) |
| 229 | // value.Object().ContainsKey("foo") |
| 230 | func (v *Value) Object() *Object { |
| 231 | opChain := v.chain.enter("Object()") |
| 232 | defer opChain.leave() |
| 233 | |
| 234 | if opChain.failed() { |
| 235 | return newObject(opChain, nil) |
| 236 | } |
| 237 | |
| 238 | data, ok := v.value.(map[string]interface{}) |
| 239 | |
| 240 | if !ok { |
| 241 | opChain.fail(AssertionFailure{ |
| 242 | Type: AssertValid, |
| 243 | Actual: &AssertionValue{v.value}, |
| 244 | Errors: []error{ |
| 245 | errors.New("expected: value is object"), |
| 246 | }, |
| 247 | }) |
| 248 | return newObject(opChain, nil) |
| 249 | } |
| 250 | |
| 251 | return newObject(opChain, data) |
| 252 | } |
| 253 | |
| 254 | // Array returns a new Array attached to underlying value. |
| 255 | // |