...
1 package mxj
2
3 import (
4 "fmt"
5 "testing"
6 )
7
8 func TestStructHeader(t *testing.T) {
9 fmt.Println("\n---------------- struct_test.go ...")
10 }
11
12
50
51 func TestStruct(t *testing.T) {
52 type str struct {
53 IntVal int `json:"int"`
54 StrVal string `json:"str"`
55 FloatVal float64 `json:"float"`
56 BoolVal bool `json:"bool"`
57 private string
58 }
59 var s str
60 m := Map{"int": 4, "str": "now's the time", "float": 3.14159, "bool": true, "private": "Somewhere over the rainbow"}
61
62 mverr := m.Struct(&s)
63 if mverr != nil {
64 t.Fatal("mverr:", mverr.Error())
65 }
66
67 fmt.Printf("Struct, m: %#v\n", m)
68 fmt.Printf("Struct, s: %#v\n", s)
69 }
70
71 func TestStructError(t *testing.T) {
72 type str struct {
73 IntVal int `json:"int"`
74 StrVal string `json:"str"`
75 FloatVal float64 `json:"float"`
76 BoolVal bool `json:"bool"`
77 }
78 var s str
79 mv := Map{"int": 4, "str": "now's the time", "float": 3.14159, "bool": true}
80
81 mverr := mv.Struct(s)
82 if mverr == nil {
83 t.Fatal("StructError, no error returned")
84 }
85 fmt.Println("StructError, mverr:", mverr.Error())
86 }
87
View as plain text