add test
This commit is contained in:
parent
81f9c552dd
commit
1cdf5449fd
@ -275,3 +275,26 @@ func TestDataFilterDiffArr(t *testing.T) {
|
||||
filter.Filter()
|
||||
//fmt.Println()
|
||||
}
|
||||
|
||||
// TestDataFilterRootArr ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 20:45 2023/8/31
|
||||
func TestDataFilterRootArr(t *testing.T) {
|
||||
source := []map[string]interface{}{
|
||||
{"user_list": []interface{}{map[string]interface{}{"name": "alex", "age": 18, "number": 1}}},
|
||||
{"user_list": []interface{}{map[string]interface{}{"name": "bob", "age": 28, "number": 2}}},
|
||||
{"user_list": []interface{}{map[string]interface{}{"name": "andy", "age": 28, "number": 2}}},
|
||||
}
|
||||
rule := []*FilterDataRule{
|
||||
// {SourceKey: "name", MapKey: "slice.[]", DefaultValue: "用户姓名默认值"},
|
||||
{SourceKey: "[].user_list.[].name", MapKey: "user_list.[].detail.name", DefaultValue: "用户姓名默认值"},
|
||||
{SourceKey: "[].user_list.[].age", MapKey: "user_list.[].detail.age", DefaultValue: "用户姓名默认值"},
|
||||
}
|
||||
byteData, _ := json.Marshal(source)
|
||||
filter := NewDataFilter(string(byteData), rule)
|
||||
filter.UserItemToSlice()
|
||||
filter.Filter()
|
||||
//fmt.Println()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user