-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexec_OliveagleJsonpath.go
More file actions
51 lines (45 loc) · 854 Bytes
/
exec_OliveagleJsonpath.go
File metadata and controls
51 lines (45 loc) · 854 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/oliveagle/jsonpath"
)
func Execute_oliveagle_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
}
pat, err := jsonpath.Compile(jsonPath)
if err != nil {
b.Skip(err)
return
}
value, err := pat.Lookup(src)
if err != nil {
b.Skip(err)
return
}
result, ok := value.([]any)
if ok {
if len(result) == 1 {
_result, ok := result[0].([]any)
if ok {
result = _result
}
}
} else {
result = []any{result}
}
if ok, reason := expect.validateSlice(result); !ok {
if reason != "" {
b.Skipf("precheck failed: %s", reason)
} else {
b.Skip("precheck failed")
}
return
}
for b.Loop() {
pat.Lookup(src)
}
}