From 1cdf5449fd54db3f439317f62893d2fc194225ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Thu, 31 Aug 2023 21:02:54 +0800 Subject: [PATCH] add test --- tool/json_test.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tool/json_test.go b/tool/json_test.go index b655dd5..3ae4f41 100644 --- a/tool/json_test.go +++ b/tool/json_test.go @@ -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() +}