-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser_test.go
105 lines (88 loc) · 2.29 KB
/
parser_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
package json5
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestParseJSON5Object(t *testing.T) {
input := `{
"name": "John Doe",
"age": 42,
"married": true,
"children": null,
hexadecimal: 0xdecaf,
"address": {
"city": "New York",
"zipcode": 10001
},
lineBreaks: "line 1\nline 2
line 3",
unicode: "Hello beauty! -\U{0x1F600}-",
"favorites": ["pizza", 42, false, null, {"item": "book", price: 10.99, "in_stock": true,}]
}`
result, err := UnMarshal(input)
if err != nil {
t.Fatalf("Error parsing JSON5 object: %v", err)
}
if result == nil {
t.Fatalf("Expected non-nil result")
}
expected := map[string]interface{}{
"address": map[string]interface{}{"city": "New York", "zipcode": 10001},
"age": 42,
"children": nil,
"favorites": []interface{}{"pizza", 42, false, nil, map[string]interface{}{"in_stock": true, "item": "book", "price": 10.99}},
"married": true,
"name": "John Doe", "hexadecimal": 912559, "lineBreaks": "line 1\nline 2\n\t\tline 3",
"unicode": "Hello beauty! -😀-"}
assert.Equal(t, expected, result)
}
func TestParseJSON5Array(t *testing.T) {
input := `["a", 'b', 1]`
result, err := UnMarshal(input)
if err != nil {
t.Fatalf("Error parsing JSON5 array: %v", err)
}
if result == nil {
t.Fatalf("Expected non-nil result")
}
}
func TestParseJSON5String(t *testing.T) {
input := `'a'`
result, err := UnMarshal(input)
if err != nil {
t.Fatalf("Error parsing JSON5 string: %v", err)
}
if result == nil {
t.Fatalf("Expected non-nil result")
}
}
func TestParseJSON5Number(t *testing.T) {
input := `42`
result, err := UnMarshal(input)
if err != nil {
t.Fatalf("Error parsing JSON5 number: %v", err)
}
if result == nil {
t.Fatalf("Expected non-nil result")
}
}
func BenchmarkJSON(b *testing.B) {
input := `{
"name": "John Doe",
"age": 42,
"married": true,
"children": null,
hexadecimal: 0xdecaf,
"address": {
"city": "New York",
"zipcode": 10001
},
lineBreaks: "line 1\nline 2
line 3",
unicode: "Hello beauty! -\U{0x1F600}-",
"favorites": ["pizza", 42, false, null, {"item": "book", price: 10.99, "in_stock": true,}]
}`
for i := 0; i < b.N; i++ {
UnMarshal(input)
}
}