Skip to content

Commit

Permalink
test option IterStructByName
Browse files Browse the repository at this point in the history
  • Loading branch information
AsterDY committed Jul 28, 2023
1 parent fdc238e commit 703c19f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
18 changes: 12 additions & 6 deletions thrift/generic/iter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ import (
)

func TestForeach(t *testing.T) {
var iterOpts = &Options{}
var iterOpts = &Options{
IterateStructByName: true,
}

desc := getExampleDesc()
data := getExampleData()
Expand Down Expand Up @@ -98,16 +100,20 @@ func TestForeach(t *testing.T) {
}
require.NoError(t, root.Foreach(handler, iterOpts))

handler2 := func(path Path, val Value) bool {
require.True(t, path.Type() == PathFieldName)
t.Logf("handler2: %v", path)
return true
}
vv := root.GetByPath(NewPathFieldName("InnerBase"))
require.Nil(t, vv.Check())
require.NoError(t, vv.Foreach(handler2, iterOpts))

cout := 0
handler3 := func(path Path, val Value) bool {
cout += 1
return false
}
vv := root.GetByPath(NewPathFieldName("InnerBase"))
require.Nil(t, vv.Check())
require.NoError(t, vv.Foreach(handler3, iterOpts))
require.Equal(t, 1, cout)

cout = 0
vv = root.GetByPath(PathExampleListInt32...)
require.Nil(t, vv.Check())
Expand Down
2 changes: 1 addition & 1 deletion thrift/generic/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type Options struct {
// WARNING: this will promote performance when thrift value to be skipped is large, but may decrease preformance when thrift value is small.
UseNativeSkip bool

// MapStructById indicates to use field id as map key instead of when call Node.Interface() on STRUCT type.
// MapStructById indicates to use FieldId instead of int as map key instead of when call Node.Interface() on STRUCT type.
MapStructById bool

// CastStringAsBinary indicates to cast STRING type to []byte when call Node.Interface()/Map().
Expand Down

0 comments on commit 703c19f

Please sign in to comment.