Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed incorrect result for obj.Value().MSI() getter #65

Merged
merged 11 commits into from
May 27, 2018
4 changes: 4 additions & 0 deletions type_specific_codegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,14 @@ func (v *Value) CollectInter(collector func(int, interface{}) interface{}) *Valu

// MSI gets the value as a map[string]interface{}, returns the optionalDefault
// value or a system default object if the value is the wrong type.
// TODO: Find a better solution for the Map type as this code is autogenerated
func (v *Value) MSI(optionalDefault ...map[string]interface{}) map[string]interface{} {
if s, ok := v.data.(map[string]interface{}); ok {
return s
}
if s, ok := v.data.(Map); ok {
hanzei marked this conversation as resolved.
Show resolved Hide resolved
return map[string]interface{}(s)
}
if len(optionalDefault) == 1 {
return optionalDefault[0]
}
Expand Down
1 change: 1 addition & 0 deletions type_specific_codegen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ func TestMSI(t *testing.T) {
val := map[string]interface{}(map[string]interface{}{"name": "Tyler"})
m := objx.Map{"value": val, "nothing": nil}

assert.Equal(t, map[string]interface{}{"value": val, "nothing": nil}, m.Value().MSI())
assert.Equal(t, val, m.Get("value").MSI())
assert.Equal(t, val, m.Get("value").MustMSI())
assert.Equal(t, map[string]interface{}(nil), m.Get("nothing").MSI())
Expand Down