forked from clbanning/mxj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
struct_test.go
86 lines (72 loc) · 1.87 KB
/
struct_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
package mxj
import (
"fmt"
"testing"
)
func TestStructHeader(t *testing.T) {
fmt.Println("\n---------------- struct_test.go ...")
}
/*
func TestNewMapStruct(t *testing.T) {
type str struct {
IntVal int `json:"int"`
StrVal string `json:"str"`
FloatVal float64 `json:"float"`
BoolVal bool `json:"bool"`
private string
}
s := str{IntVal: 4, StrVal: "now's the time", FloatVal: 3.14159, BoolVal: true, private: "It's my party"}
m, merr := NewMapStruct(s)
if merr != nil {
t.Fatal("merr:", merr.Error())
}
fmt.Printf("NewMapStruct, s: %#v\n", s)
fmt.Printf("NewMapStruct, m: %#v\n", m)
m, merr = NewMapStruct(s)
if merr != nil {
t.Fatal("merr:", merr.Error())
}
fmt.Printf("NewMapStruct, s: %#v\n", s)
fmt.Printf("NewMapStruct, m: %#v\n", m)
}
func TestNewMapStructError(t *testing.T) {
var s string
_, merr := NewMapStruct(s)
if merr == nil {
t.Fatal("NewMapStructError, merr is nil")
}
fmt.Println("NewMapStructError, merr:", merr.Error())
}
*/
func TestStruct(t *testing.T) {
type str struct {
IntVal int `json:"int"`
StrVal string `json:"str"`
FloatVal float64 `json:"float"`
BoolVal bool `json:"bool"`
private string
}
var s str
m := Map{"int": 4, "str": "now's the time", "float": 3.14159, "bool": true, "private": "Somewhere over the rainbow"}
mverr := m.Struct(&s)
if mverr != nil {
t.Fatal("mverr:", mverr.Error())
}
fmt.Printf("Struct, m: %#v\n", m)
fmt.Printf("Struct, s: %#v\n", s)
}
func TestStructError(t *testing.T) {
type str struct {
IntVal int `json:"int"`
StrVal string `json:"str"`
FloatVal float64 `json:"float"`
BoolVal bool `json:"bool"`
}
var s str
mv := Map{"int": 4, "str": "now's the time", "float": 3.14159, "bool": true}
mverr := mv.Struct(s)
if mverr == nil {
t.Fatal("StructError, no error returned")
}
fmt.Println("StructError, mverr:", mverr.Error())
}