diff --git a/cvte.go b/cvte.go index 198b526..c654272 100644 --- a/cvte.go +++ b/cvte.go @@ -57,11 +57,11 @@ func deepStructValues(rv reflect.Value) (sl []interface{}) { func deepStructFields(rt reflect.Type) (sl []string) { rt = ptrType(rt) - type fff struct { + type field struct { level int8 index int } - var exists = make(map[string]fff) + var exists = make(map[string]field) fn := func(v string, level int8) { ff, ok := exists[v] @@ -71,7 +71,7 @@ func deepStructFields(rt reflect.Type) (sl []string) { sl = append(sl[:ff.index], sl[ff.index+1:]...) } sl = append(sl, v) - exists[v] = fff{level, len(sl) - 1} + exists[v] = field{level, len(sl) - 1} } // sort by field definition order, include embed field diff --git a/slice_test.go b/slice_test.go index 24af2fe..b7c78be 100644 --- a/slice_test.go +++ b/slice_test.go @@ -369,9 +369,10 @@ func TestKeysE(t *testing.T) { isErr bool }{ // map - {map[int]map[string]interface{}{1: {"1": 111, "DDD": 12.3}, 2: {"2": 222, "DDD": "321"}, 3: {"DDD": nil}}, []interface{}{1, 2, 3}, false}, + {map[int]map[string]interface{}{1: {"1": 111, "DDD": 12.3}, -2: {"2": 222, "DDD": "321"}, 3: {"DDD": nil}}, []interface{}{-2, 1, 3}, false}, {map[string]interface{}{"A": 1, "2": 2}, []interface{}{"2", "A"}, false}, - {map[float64]TestStructD{1: {11}, 2: {22}}, []interface{}{float64(1), float64(2)}, false}, + {map[float64]float64{0.1: -0.1, -1.2: 1.2}, []interface{}{-1.2, 0.1}, false}, + {map[float64]TestStructD{-1: {11}, 2: {22}}, []interface{}{float64(-1), float64(2)}, false}, {map[interface{}]interface{}{1: 1, 2.2: 2.22, "A": "A"}, []interface{}{1, 2.2, "A"}, false}, // struct