更新单元测试

This commit is contained in:
白茶清欢 2024-11-30 17:22:16 +08:00
parent 0ca808c4fb
commit c1775552cc

View File

@ -12,6 +12,8 @@ import (
"fmt"
"testing"
"github.com/tidwall/sjson"
"github.com/tidwall/gjson"
)
@ -168,6 +170,12 @@ func TestExpandArrayPath(t *testing.T) {
PathList: nil,
PathMap: nil,
}
ExpandArrayPath(jsonStr, "user_list.{{idx}}.{{idx}}.age", "", pathExpendRes)
fmt.Println(pathExpendRes)
ExpandArrayPath(jsonStr, "user_list.{{idx}}.{{idx}}.age", "a.{{idx}}.{{idx}}.b", pathExpendRes)
ExpandArrayPath(jsonStr, "user_list.{{idx}}.{{idx}}.name", "a.{{idx}}.{{idx}}.c", pathExpendRes)
ExpandArrayPath(jsonStr, "user_list.{{idx}}.{{idx}}.sex", "a.{{idx}}.{{idx}}.c", pathExpendRes)
res := ""
for _, item := range pathExpendRes.PathList {
res, _ = sjson.Set(res, pathExpendRes.PathMap[item], gjson.Get(jsonStr, item).Value())
}
fmt.Println(res)
}