-
Notifications
You must be signed in to change notification settings - Fork 318
/
issue263_test.go
91 lines (80 loc) · 2.3 KB
/
issue263_test.go
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package issue_test
import (
`bytes`
`testing`
`github.com/bytedance/sonic/ast`
`github.com/bytedance/sonic/decoder`
`github.com/davecgh/go-spew/spew`
)
type Response struct {
Menu Menu `json:"menu"`
}
type Menu struct {
Items []*Item `json:"items"`
}
type Item struct {
ID string `json:"id"`
}
func (i *Item) UnmarshalJSON(buf []byte) error { return nil
}
func TestName(t *testing.T) {
q := `{
"menu": {
"items": [{
"id": "carrotcake",
"name": {
"en": "CarrotCake Name"
},
"operational_name": "carrotCake-op",
"description": null,
"plu": "carrotCake45",
"ian": "carrotCake_ian_45",
"external_data": "",
"image": {
"url": "http://127.0.0.1:50207/image7.jpg"
},
"tax_rate": "20",
"modifier_ids": [
"add-hot-drinks-mod"
],
"contains_alcohol": false,
"max_quantity": null,
"is_eligible_for_substitution": true,
"is_eligible_as_replacement": true
},
{
"id": "cheeseburger",
"name": {
"en": "Cheeseburger Name"
},
"operational_name": "cheeseburger-op",
"description": null,
"plu": "cheeseburger40",
"ian": "cheeseburger_ian_40",
"external_data": "",
"image": {
"url": "http://127.0.0.1:50207/image1.jpg"
},
"tax_rate": "20",
"modifier_ids": [
"add-drinks-mod"
],
"contains_alcohol": false,
"max_quantity": null,
"is_eligible_for_substitution": true,
"is_eligible_as_replacement": true
}
]
}
}`
n, err := ast.NewSearcher(q).GetByPath("menu", "items", 1)
if err != nil {
t.Fatal(err)
}
spew.Dump(n.Interface())
var response Response
err = decoder.NewStreamDecoder(bytes.NewReader([]byte(q))).Decode(&response)
if err != nil {
t.Fatal(err)
}
}