增加多维数组的测试

This commit is contained in:
白茶清欢 2024-11-27 16:15:37 +08:00
parent 435edb0ea3
commit 33815072ea

View File

@ -10,6 +10,7 @@ package gjson_hack
import (
"encoding/json"
"fmt"
"github.com/tidwall/gjson"
"testing"
)
@ -49,8 +50,27 @@ func TestPathOnlyFinallyPath(t *testing.T) {
"email": "xxx@xxx.com",
},
"sex": "man",
"user_list": [][]map[string]any{
[]map[string]any{
{"name": "zhang", "age": 10},
{"name": "li", "age": 20},
{"name": "wang", "age": 30},
},
[]map[string]any{
{"name": "zhang", "age": 20},
{"name": "li", "age": 20},
{"name": "wang", "age": 30},
},
[]map[string]any{
{"name": "zhang", "age": 30},
{"name": "li", "age": 20},
{"name": "wang", "age": 30},
},
},
}
byteData, _ := json.Marshal(mapData)
fmt.Println(gjson.GetBytes(byteData, "user_list.#.#.age"))
fmt.Println(gjson.GetBytes(byteData, "user_list.0.0.age"))
pathRes, err := Path(string(byteData), &PathOption{
UnfoldArray: false,
MaxDeep: 0,
@ -77,6 +97,23 @@ func TestPathOnlyFinallyPathWithUnfoldArray(t *testing.T) {
"email": "xxx@xxx.com",
},
"sex": "man",
"user_list": [][]map[string]any{
[]map[string]any{
{"name": "zhang", "age": 10},
{"name": "li", "age": 20},
{"name": "wang", "age": 30},
},
[]map[string]any{
{"name": "zhang", "age": 10},
{"name": "li", "age": 20},
{"name": "wang", "age": 30},
},
[]map[string]any{
{"name": "zhang", "age": 10},
{"name": "li", "age": 20},
{"name": "wang", "age": 30},
},
},
}
byteData, _ := json.Marshal(mapData)
pathRes, err := Path(string(byteData), &PathOption{