-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexec_YalpJSONPath.go
More file actions
51 lines (44 loc) · 866 Bytes
/
exec_YalpJSONPath.go
File metadata and controls
51 lines (44 loc) · 866 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package jsonpath_benchmark
import (
"encoding/json"
"testing"
"github.com/yalp/jsonpath"
)
func Execute_Yalp_JSONPath(b *testing.B, srcJSON string, jsonPath string, expect *BenchExpect) {
var src any
if err := json.Unmarshal([]byte(srcJSON), &src); err != nil {
b.Skip(err)
return
}
parserFunc, err := jsonpath.Prepare(jsonPath)
if err != nil {
b.Skip(err)
return
}
nodes, err := parserFunc(src)
if err != nil {
b.Skip(err)
return
}
var result []any
switch typedNodes := nodes.(type) {
case []any:
result = typedNodes
case float64:
result = []any{typedNodes}
default:
b.Skip("unexpected result type")
return
}
if ok, reason := expect.validateSlice(result); !ok {
if reason != "" {
b.Skipf("precheck failed: %s", reason)
} else {
b.Skip("precheck failed")
}
return
}
for b.Loop() {
parserFunc(src)
}
}