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
|
package parser
import (
"reflect"
"testing"
"go.neonxp.dev/json/model"
)
func TestParse(t *testing.T) {
type args struct {
json string
}
tests := []struct {
name string
args args
want *model.Node
wantErr bool
}{
{
name: "complex",
args: args{
json: `{
"string key": "string value",
"number key": 1337,
"float key": 123.3,
"object key": {
"ab": "cd"
},
"array key": [
1,
2,
"three"
],
"null key":null,
"boolean key":true
}`,
},
want: model.NewNode(
model.NodeObjectValue{
"string key": model.NewNode("string value"),
"number key": model.NewNode(1337),
"float key": model.NewNode(123.3),
"object key": model.NewNode(model.NodeObjectValue{
"ab": model.NewNode("cd"),
}),
"array key": model.NewNode(model.NodeArrayValue{
model.NewNode(1),
model.NewNode(2),
model.NewNode("three"),
}),
"null key": model.NewNode(nil),
"boolean key": model.NewNode(true),
},
),
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := Parse(tt.args.json)
if (err != nil) != tt.wantErr {
t.Errorf("Parse() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("Parse() = %v, want %v", got, tt.want)
}
})
}
}
|