forked from amatsagu/tempest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsonnet_test.go
68 lines (60 loc) · 1.19 KB
/
sonnet_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
package tempest
import (
"testing"
"github.com/sugawarayuuta/sonnet"
)
func TestSonnet(t *testing.T) {
type exyyy struct {
Message string `json:"message"`
}
type exxxx struct {
Test map[Snowflake]exyyy `json:"test"`
}
// Try simple
var data1 exxxx
body1 := []byte(`{
"test": {
"1010": {"message": "hello"}
}
}`)
if err := sonnet.Unmarshal(body1, &data1); err != nil {
t.Error(err)
}
// Try advanced
var data2 CommandInteractionData
body2 := []byte(`{
"guild_id": "76543210987654321",
"id": "1151765326615289907",
"name": "hello",
"options": [
{
"name": "message",
"type": 3,
"value": "<@12345678901234567> is great"
}
],
"resolved": {
"members": {
"12345678901234567": {
"avatar": null,
"communication_disabled_until": null,
"flags": 0,
"joined_at": "2022-01-01T06:21:57.248000+00:00",
"nick": "Drew",
"pending": false,
"permissions": "562949953421311",
"premium_since": null,
"roles": [
"12345678901234568",
"12345678901234569"
],
"unusual_dm_activity_until": null
}
}
},
"users": {}
}`)
if err := sonnet.Unmarshal(body2, &data2); err != nil {
t.Error(err)
}
}