-
Notifications
You must be signed in to change notification settings - Fork 17
/
text_marshaler_test.go
113 lines (84 loc) · 1.42 KB
/
text_marshaler_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
package goobjfmt
import (
"math"
"testing"
)
type MyCar int32
const (
MyCar_Monkey MyCar = 1
MyCar_Monk MyCar = 2
MyCar_Pig MyCar = 3
)
type MyData struct {
Stream []byte
Name string
Type MyCar
Int32 int32
Uint32 uint32
Int64 int64
Uint64 uint64
}
type PhoneNumber struct {
Number string
Type int32
}
type Person struct {
Name string
Id int32
Email string
Phone []*PhoneNumber
}
type AddressBook struct {
Person []*Person
PersonByName map[string]*Person
}
func TestNumber(t *testing.T) {
input := &MyData{
Stream: []byte{1, 2, 3, 4},
Name: "genji",
Type: MyCar_Pig,
Uint32: math.MaxUint32,
Int64: math.MaxInt64,
Uint64: math.MaxUint64,
}
t.Log(CompactTextString(input))
}
func TestString(t *testing.T) {
t.Log(CompactTextString(&MyData{Name: "源氏"}))
}
func TestPhone(t *testing.T) {
input := &AddressBook{
Person: []*Person{
{
Name: "Alice",
Id: int32(10000),
Phone: []*PhoneNumber{
{
Number: "123456789",
Type: 1,
},
{
Number: "87654321",
Type: 2,
},
},
},
{
Name: "Bob",
Id: int32(20000),
Phone: []*PhoneNumber{
{
Number: "01234567890",
Type: int32(3),
},
},
},
},
}
input.PersonByName = make(map[string]*Person)
for _, v := range input.Person {
input.PersonByName[v.Name] = v
}
t.Log(CompactTextString(input))
t.Log(MarshalTextString(input))
}