-
Notifications
You must be signed in to change notification settings - Fork 2
/
booltype_test.go
71 lines (57 loc) · 1.26 KB
/
booltype_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
package cloudwatcher
import (
"encoding/json"
"testing"
)
func TestBool_MarshalJSON(t *testing.T) {
type X struct {
B Bool
}
x := X{}
err := json.Unmarshal([]byte("{\"B\":\"true\"}"), &x)
if err != nil {
t.Errorf("error during the unmarshalling : %s", err)
}
if x.B == false {
t.Errorf("it should be true")
}
err = json.Unmarshal([]byte("{\"B\":\"1\"}"), &x)
if err != nil {
t.Errorf("error during the unmarshalling : %s", err)
}
if x.B == false {
t.Errorf("it should be true")
}
err = json.Unmarshal([]byte("{\"B\":\"false\"}"), &x)
if err != nil {
t.Errorf("error during the unmarshalling : %s", err)
}
if x.B == true {
t.Errorf("it should be false")
}
err = json.Unmarshal([]byte("{\"B\":false}"), &x)
if err == nil {
t.Errorf("it should return an error")
}
}
func TestBool_UnmarshalJSON(t *testing.T) {
type X struct {
B Bool
}
x := X{true}
j, err := json.Marshal(x)
if err != nil {
t.Errorf("error during the marshalling : %s", err)
}
if string(j) != "{\"B\":true}" {
t.Errorf("marshalling didn't work correctly")
}
x.B = false
j, err = json.Marshal(x)
if err != nil {
t.Errorf("error during the marshalling : %s", err)
}
if string(j) != "{\"B\":false}" {
t.Errorf("marshalling didn't work correctly")
}
}