-
Notifications
You must be signed in to change notification settings - Fork 7
/
convert_asBool_test.go
116 lines (97 loc) · 1.85 KB
/
convert_asBool_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
114
115
116
package generic
import "testing"
func TestAsBoolInt(t *testing.T) {
i := 100
asBoolTest(i, t)
}
func TestAsBoolInt8(t *testing.T) {
var i int8 = 100
asBoolTest(i, t)
}
func TestAsBoolInt16(t *testing.T) {
var i int16 = 100
asBoolTest(i, t)
}
func TestAsBoolInt32(t *testing.T) {
var i int32 = 100
asBoolTest(i, t)
}
func TestAsBoolInt64(t *testing.T) {
var i int64 = 100
asBoolTest(i, t)
}
func TestAsBoolUint(t *testing.T) {
var u uint = 100
asBoolTest(u, t)
}
func TestAsBoolUint8(t *testing.T) {
var u uint8 = 100
asBoolTest(u, t)
}
func TestAsBoolUint16(t *testing.T) {
var u uint16 = 100
asBoolTest(u, t)
}
func TestAsBoolUint32(t *testing.T) {
var u uint32 = 100
asBoolTest(u, t)
}
func TestAsBoolUint64(t *testing.T) {
var u uint64 = 100
asBoolTest(u, t)
}
func TestAsBoolFloat32(t *testing.T) {
var f float32 = 1.0001
asBoolTest(f, t)
}
func TestAsBoolFloat64(t *testing.T) {
f := 1.0001
asBoolTest(f, t)
}
func TestAsBoolTrue(t *testing.T) {
b := true
asBoolTest(b, t)
}
func TestAsBoolFalse(t *testing.T) {
b := false
r, v, err := asBool(b)
if err != nil {
t.Errorf("Not Expected error. error:%s", err.Error())
}
if !v {
t.Error("expected: true, actual: false")
}
if r {
t.Error("expected: false, actual: true")
}
}
func TestAsBoolNumericString(t *testing.T) {
s := "1"
asBoolTest(s, t)
}
func TestAsBoolUnumericString(t *testing.T) {
s := "abd"
_, _, err := asBool(s)
if err == nil {
t.Error("Expected error")
}
}
func TestAsBoolInvalidType(t *testing.T) {
bs := []byte("true")
_, _, err := asBool(bs)
if err == nil {
t.Error("Expected error")
}
}
func asBoolTest(x interface{}, t *testing.T) {
r, v, err := asBool(x)
if err != nil {
t.Errorf("Not Expected error. error:%s", err.Error())
}
if !v {
t.Error("expected: true, actual: false")
}
if !r {
t.Error("expected: true, actual: false")
}
}