-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexec_BhmjJSONSlice.go
More file actions
48 lines (41 loc) · 825 Bytes
/
exec_BhmjJSONSlice.go
File metadata and controls
48 lines (41 loc) · 825 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
package jsonpath_benchmark
import (
"encoding/json"
"testing"
"github.com/bhmj/jsonslice"
)
func Execute_bhmj_JSON_Slice(b *testing.B, srcJSON string, jsonPath string, expect *BenchExpect) {
var src = []byte(srcJSON)
binaryResult, err := jsonslice.Get(src, jsonPath)
if err != nil {
b.Skip(err)
return
}
var value any
if err := json.Unmarshal(binaryResult, &value); 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{value}
}
if ok, reason := expect.validateSlice(result); !ok {
if reason != "" {
b.Skipf("precheck failed: %s", reason)
} else {
b.Skip("precheck failed")
}
return
}
for b.Loop() {
jsonslice.Get(src, jsonPath)
}
}