diff --git a/util/gconv/gconv_slice_any.go b/util/gconv/gconv_slice_any.go index 7f92062c7..02b3d0ef2 100644 --- a/util/gconv/gconv_slice_any.go +++ b/util/gconv/gconv_slice_any.go @@ -112,22 +112,23 @@ func Interfaces(i interface{}) []interface{} { for i := 0; i < reflectValue.Len(); i++ { array[i] = reflectValue.Index(i).Interface() } - // Eg: {"K1": "v1", "K2": "v2"} => ["K1", "v1", "K2", "v2"] - case reflect.Map: - array = make([]interface{}, 0) - for _, key := range reflectValue.MapKeys() { - array = append(array, key.Interface()) - array = append(array, reflectValue.MapIndex(key).Interface()) - } - // Eg: {"K1": "v1", "K2": "v2"} => ["K1", "v1", "K2", "v2"] - case reflect.Struct: - array = make([]interface{}, 0) - // Note that, it uses the gconv tag name instead of the attribute name if - // the gconv tag is fined in the struct attributes. - for k, v := range Map(reflectValue) { - array = append(array, k) - array = append(array, v) - } + // Deprecated. + //// Eg: {"K1": "v1", "K2": "v2"} => ["K1", "v1", "K2", "v2"] + //case reflect.Map: + // array = make([]interface{}, 0) + // for _, key := range reflectValue.MapKeys() { + // array = append(array, key.Interface()) + // array = append(array, reflectValue.MapIndex(key).Interface()) + // } + //// Eg: {"K1": "v1", "K2": "v2"} => ["K1", "v1", "K2", "v2"] + //case reflect.Struct: + // array = make([]interface{}, 0) + // // Note that, it uses the gconv tag name instead of the attribute name if + // // the gconv tag is fined in the struct attributes. + // for k, v := range Map(reflectValue) { + // array = append(array, k) + // array = append(array, v) + // } default: return []interface{}{i} } diff --git a/util/gconv/gconv_z_unit_all_test.go b/util/gconv/gconv_z_unit_all_test.go index 2b077e0e8..fd027adbd 100644 --- a/util/gconv/gconv_z_unit_all_test.go +++ b/util/gconv/gconv_z_unit_all_test.go @@ -753,11 +753,11 @@ func Test_Slice_PrivateAttribute_All(t *testing.T) { } gtest.C(t, func(t *gtest.T) { user := &User{1, "john", []interface{}{2}} - s := gconv.Interfaces(user) - t.Assert(len(s), 4) - // g.Slice{"id", 1, "ad", g.Slice{2}} - t.Assert(s[0] == "id" || s[0] == "ad", true) - t.Assert(s[1] == 1 || s[3] == 1, true) + array := gconv.Interfaces(user) + t.Assert(len(array), 1) + t.Assert(array[0].(*User).Id, 1) + t.Assert(array[0].(*User).name, "john") + t.Assert(array[0].(*User).Ad, []interface{}{2}) }) } diff --git a/util/gconv/gconv_z_unit_slice_test.go b/util/gconv/gconv_z_unit_slice_test.go index 85fe200ee..4b4769618 100644 --- a/util/gconv/gconv_z_unit_slice_test.go +++ b/util/gconv/gconv_z_unit_slice_test.go @@ -85,7 +85,9 @@ func Test_Slice_Interfaces(t *testing.T) { "id": 1, "name": "john", }) - t.AssertIN(array, []interface{}{"id", 1, "name", "john"}) + t.Assert(len(array), 1) + t.Assert(array[0].(g.Map)["id"], 1) + t.Assert(array[0].(g.Map)["name"], "john") }) // struct gtest.C(t, func(t *gtest.T) { @@ -97,7 +99,9 @@ func Test_Slice_Interfaces(t *testing.T) { Id: 1, Name: "john", }) - t.AssertIN(array, []interface{}{"id", 1, "Name", "john"}) + t.Assert(len(array), 1) + t.Assert(array[0].(*A).Id, 1) + t.Assert(array[0].(*A).Name, "john") }) } @@ -108,7 +112,10 @@ func Test_Slice_PrivateAttribute(t *testing.T) { } gtest.C(t, func(t *gtest.T) { user := &User{1, "john"} - t.Assert(gconv.Interfaces(user), g.Slice{"id", 1}) + array := gconv.Interfaces(user) + t.Assert(len(array), 1) + t.Assert(array[0].(*User).Id, 1) + t.Assert(array[0].(*User).name, "john") }) }