Skip to content

Commit

Permalink
add KeysE() test case for negative number
Browse files Browse the repository at this point in the history
  • Loading branch information
shockerli committed Nov 26, 2021
1 parent 44ba0dc commit 1644815
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 3 additions & 3 deletions cvte.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions slice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1644815

Please sign in to comment.