forked from devfeel/dotweb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjsonutil_test.go
More file actions
55 lines (46 loc) · 776 Bytes
/
jsonutil_test.go
File metadata and controls
55 lines (46 loc) · 776 Bytes
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
package jsonutil
import (
"testing"
)
// 以下是功能测试
type (
colorGroup struct {
ID int
Name string
Colors []string
}
mymap map[string]interface{}
)
func Test_GetJsonString_1(t *testing.T) {
g := newGroup()
json := GetJsonString(g)
t.Log(json)
}
func Test_Marshal_1(t *testing.T) {
g := newGroup()
json, err := Marshal(g)
if err != nil {
t.Error(err)
} else {
t.Log(json)
}
}
func Test_Unmarshal_1(t *testing.T) {
var group colorGroup
g := newGroup()
json := GetJsonString(g)
err := Unmarshal(json, &group)
if err != nil {
t.Error(err)
} else {
t.Log(group)
}
}
func newGroup() colorGroup {
group := colorGroup{
ID: 1,
Name: "Reds",
Colors: []string{"Crimson", "Red", "Ruby", "Maroon"},
}
return group
}