-
Notifications
You must be signed in to change notification settings - Fork 11
/
nan_test.go
99 lines (91 loc) · 2.14 KB
/
nan_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
package nan
import (
"testing"
"time"
"github.com/mailru/easyjson"
"github.com/stretchr/testify/require"
)
func TestNanValidator(t *testing.T) {
nullValues := []Validator{
NullInt64{},
NullInt32{},
NullInt16{},
NullInt8{},
NullInt{},
NullBool{},
NullFloat64{},
NullFloat32{},
NullString{},
NullTime{},
NullUint64{},
NullUint32{},
NullUint16{},
NullUint8{},
NullUint{},
}
nonnullvalues := []Validator{
NullInt64{Valid: true, Int64: 1},
NullInt32{Valid: true, Int32: 1},
NullInt16{Valid: true, Int16: 1},
NullInt8{Valid: true, Int8: 1},
NullInt{Valid: true, Int: 1},
NullBool{Valid: true, Bool: true},
NullFloat64{Valid: true, Float64: 1},
NullFloat32{Valid: true, Float32: 1},
NullString{Valid: true, String: "1"},
NullTime{Valid: true, Time: time.Now()},
NullUint64{Valid: true, Uint64: 1},
NullUint32{Valid: true, Uint32: 1},
NullUint16{Valid: true, Uint16: 1},
NullUint8{Valid: true, Uint8: 1},
NullUint{Valid: true, Uint: 1},
}
for _, v := range nullValues {
require.False(t, v.IsValid())
}
for _, v := range nonnullvalues {
require.True(t, v.IsValid())
}
}
func TestNanDefined(t *testing.T) {
nullValues := []easyjson.Optional{
NullInt64{},
NullInt32{},
NullInt16{},
NullInt8{},
NullInt{},
NullBool{},
NullFloat64{},
NullFloat32{},
NullString{},
NullTime{},
NullUint64{},
NullUint32{},
NullUint16{},
NullUint8{},
NullUint{},
}
nonnullvalues := []easyjson.Optional{
NullInt64{Valid: true, Int64: 1},
NullInt32{Valid: true, Int32: 1},
NullInt16{Valid: true, Int16: 1},
NullInt8{Valid: true, Int8: 1},
NullInt{Valid: true, Int: 1},
NullBool{Valid: true, Bool: true},
NullFloat64{Valid: true, Float64: 1},
NullFloat32{Valid: true, Float32: 1},
NullString{Valid: true, String: "1"},
NullTime{Valid: true, Time: time.Now()},
NullUint64{Valid: true, Uint64: 1},
NullUint32{Valid: true, Uint32: 1},
NullUint16{Valid: true, Uint16: 1},
NullUint8{Valid: true, Uint8: 1},
NullUint{Valid: true, Uint: 1},
}
for _, v := range nullValues {
require.False(t, v.IsDefined())
}
for _, v := range nonnullvalues {
require.True(t, v.IsDefined())
}
}