-
Notifications
You must be signed in to change notification settings - Fork 1
/
jogo_test.go
119 lines (108 loc) · 1.88 KB
/
jogo_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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package jogo
import (
"testing"
"github.com/akshitgrover/jogo/jogo"
)
const (
exampleJson = `{
"widget": {
"debug": "on",
"window": {
"title": "Sample Konfabulator Widget",
"name": "main_window",
"width": 500,
"height": 500
},
"image": {
"src": "Images/Sun.png",
"hOffset": 250,
"vOffset": 250,
"alignment": "center"
},
"text": {
"data": "Click Here",
"size": 36,
"style": "bold",
"vOffset": 100,
"alignment": "center",
"onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;"
}
}
}`
)
var benchPaths = []string{
"widget.window.name",
"widget.image.hOffset",
"widget.text.onMouseUp",
}
func BenchmarkJoGOGet(t *testing.B) {
t.ReportAllocs()
exp, _, _ := jogo.Export(exampleJson)
for i := 0; i < t.N; i++ {
for _, v := range benchPaths {
_, _ = exp.Get(v)
}
}
t.N *= len(benchPaths)
}
func TestInt(t *testing.T) {
_, r, _ := jogo.Export(`7`)
if r.Type != "NUMBER" {
t.FailNow()
}
num := r.Int()
if num != 7 {
t.FailNow()
}
}
func TestIntNested(t *testing.T) {
exp, _, err := jogo.Export(`{"helloworld":{"number":7}}`)
if err != nil {
t.FailNow()
}
r, err := exp.Get("helloworld.number")
if err != nil {
t.FailNow()
}
if r.Type != "NUMBER" {
t.FailNow()
}
num := r.Int()
if num != 7 {
t.FailNow()
}
}
func TestStringNested(t *testing.T) {
exp, _, err := jogo.Export(`{"hello":"world"}`)
r, _ := exp.Get("hello")
if err != nil {
t.FailNow()
}
if r.Type != "STRING" {
t.Log(r.Type)
t.FailNow()
}
str := r.String()
if str != "world" {
t.FailNow()
}
}
func TestRFunc(t *testing.T) {
exp, _, err := jogo.Export(exampleJson)
if err != nil {
t.FailNow()
}
r, _ := exp.Get("widget.window")
if r.Type != "OBJECT" {
t.Log(r.Type)
t.FailNow()
}
obj := r.Object()
for _, v := range obj {
fR := jogo.R(v)
if fR.Type != "FLOAT64" && fR.Type != "STRING" {
t.Log(fR.Type)
t.FailNow()
}
}
}