-
Notifications
You must be signed in to change notification settings - Fork 3
/
todef_test.go
111 lines (89 loc) · 3.28 KB
/
todef_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
package ptr
import (
"testing"
"time"
)
func TestToDef(t *testing.T) {
equal(t, int(10), ToDef(Int(10), 0))
equal(t, int(5), ToDef(nil, 5))
}
func TestToIntDef(t *testing.T) {
equal(t, int(10), ToIntDef(Int(10), 0))
equal(t, int(5), ToIntDef(nil, 5))
}
func TestToInt8Def(t *testing.T) {
equal(t, int8(10), ToInt8Def(Int8(10), 5))
equal(t, int8(5), ToInt8Def(nil, 5))
}
func TestToInt16Def(t *testing.T) {
equal(t, int16(10), ToInt16Def(Int16(10), 5))
equal(t, int16(5), ToInt16Def(nil, 5))
}
func TestToInt32Def(t *testing.T) {
equal(t, int32(10), ToInt32Def(Int32(10), 5))
equal(t, int32(5), ToInt32Def(nil, 5))
}
func TestToInt64Def(t *testing.T) {
equal(t, int64(10), ToInt64Def(Int64(10), 5))
equal(t, int64(5), ToInt64Def(nil, 5))
}
func TestToUIntDef(t *testing.T) {
equal(t, uint(10), ToUIntDef(UInt(10), 5))
equal(t, uint(5), ToUIntDef(nil, 5))
}
func TestToUInt8Def(t *testing.T) {
equal(t, uint8(10), ToUInt8Def(UInt8(10), 5))
equal(t, uint8(5), ToUInt8Def(nil, 5))
}
func TestToUInt16Def(t *testing.T) {
equal(t, uint16(10), ToUInt16Def(UInt16(10), 5))
equal(t, uint16(5), ToUInt16Def(nil, 5))
}
func TestToUInt32Def(t *testing.T) {
equal(t, uint32(10), ToUInt32Def(UInt32(10), 5))
equal(t, uint32(5), ToUInt32Def(nil, 5))
}
func TestToUInt64Def(t *testing.T) {
equal(t, uint64(10), ToUInt64Def(UInt64(10), 5))
equal(t, uint64(5), ToUInt64Def(nil, 5))
}
func TestToByteDef(t *testing.T) {
equal(t, byte(10), ToByteDef(Byte(10), 5))
equal(t, byte(5), ToByteDef(nil, 5))
}
func TestToRuneDef(t *testing.T) {
equal(t, rune('🤔'), ToRuneDef(Rune('🤔'), '😏'))
equal(t, rune('😏'), ToRuneDef(nil, '😏'))
}
func TestToBoolDef(t *testing.T) {
equal(t, bool(true), ToBoolDef(Bool(true), false))
equal(t, bool(false), ToBoolDef(nil, false))
}
func TestToStringDef(t *testing.T) {
equal(t, string("🤔"), ToStringDef(String("🤔"), "😏"))
equal(t, string("😏"), ToStringDef(nil, "😏"))
}
func TestToFloat32Def(t *testing.T) {
equal(t, float32(10.1), ToFloat32Def(Float32(10.1), 5.1))
equal(t, float32(5.1), ToFloat32Def(nil, 5.1))
}
func TestToFloat64Def(t *testing.T) {
equal(t, float64(10.1), ToFloat64Def(Float64(10.1), 5.1))
equal(t, float64(5.1), ToFloat64Def(nil, 5.1))
}
func TestToComplex64Def(t *testing.T) {
equal(t, complex(float32(10.0), float32(100.0)), ToComplex64Def(Complex64(complex(float32(10.0), float32(100.0))), complex(float32(5.0), float32(50.0))))
equal(t, complex(float32(5.0), float32(50.0)), ToComplex64Def(nil, complex(float32(5.0), float32(50.0))))
}
func TestToComplex128Def(t *testing.T) {
equal(t, complex(float64(10.0), float64(100.0)), ToComplex128Def(Complex128(complex(float64(10.0), float64(100.0))), complex(float64(5.0), float64(50.0))))
equal(t, complex(float64(5.0), float64(50.0)), ToComplex128Def(nil, complex(float64(5.0), float64(50.0))))
}
func TestToDurationDef(t *testing.T) {
equal(t, time.Second, ToDurationDef(Duration(time.Second), time.Minute))
equal(t, time.Minute, ToDurationDef(nil, time.Minute))
}
func TestToTimeDef(t *testing.T) {
equal(t, time.Date(2001, 2, 3, 4, 5, 6, 7, time.UTC), ToTimeDef(Time(time.Date(2001, 2, 3, 4, 5, 6, 7, time.UTC)), time.Date(1990, 2, 3, 4, 5, 6, 7, time.UTC)))
equal(t, time.Date(1990, 2, 3, 4, 5, 6, 7, time.UTC), ToTimeDef(nil, time.Date(1990, 2, 3, 4, 5, 6, 7, time.UTC)))
}