-
Notifications
You must be signed in to change notification settings - Fork 1
/
json_test.go
77 lines (59 loc) · 1.26 KB
/
json_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
package gg_test
import (
"encoding/json"
"testing"
"github.com/mitranim/gg"
"github.com/mitranim/gg/gtest"
)
func Benchmark_json_Marshal(b *testing.B) {
var val SomeModel
for ind := 0; ind < b.N; ind++ {
gg.Nop1(gg.Try1(json.Marshal(val)))
}
}
func BenchmarkJsonBytes(b *testing.B) {
var val SomeModel
for ind := 0; ind < b.N; ind++ {
gg.Nop1(gg.JsonBytes(val))
}
}
func Benchmark_json_Marshal_string(b *testing.B) {
var val SomeModel
for ind := 0; ind < b.N; ind++ {
gg.Nop1(string(gg.Try1(json.Marshal(val))))
}
}
func BenchmarkJsonString(b *testing.B) {
var val SomeModel
for ind := 0; ind < b.N; ind++ {
gg.Nop1(gg.JsonString(val))
}
}
func Benchmark_json_Unmarshal(b *testing.B) {
var val int
for ind := 0; ind < b.N; ind++ {
gg.Try(json.Unmarshal(gg.ToBytes(`123`), &val))
}
}
func BenchmarkJsonDecodeTo(b *testing.B) {
for ind := 0; ind < b.N; ind++ {
gg.Nop1(gg.JsonDecodeTo[int](`123`))
}
}
func BenchmarkJsonDecode(b *testing.B) {
var val int
for ind := 0; ind < b.N; ind++ {
gg.JsonDecode(`123`, &val)
}
}
func TestJsonDecodeTo(t *testing.T) {
gtest.Catch(t)
gtest.Eq(
gg.JsonDecodeTo[SomeModel](`{"id":10}`),
SomeModel{Id: 10},
)
gtest.Eq(
gg.JsonDecodeTo[SomeModel]([]byte(`{"id":10}`)),
SomeModel{Id: 10},
)
}