-
Notifications
You must be signed in to change notification settings - Fork 0
/
bool_test.go
152 lines (127 loc) · 3.69 KB
/
bool_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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package nulls
import (
"encoding/json"
"github.com/stretchr/testify/suite"
"testing"
)
// NewBoolSuite tests NewBool.
type NewBoolSuite struct {
suite.Suite
}
func (suite *NewBoolSuite) TestNewTrue() {
b := NewBool(true)
suite.True(b.Valid, "should be valid")
suite.True(b.Bool, "should have correct value")
}
func (suite *NewBoolSuite) TestNewFalse() {
b := NewBool(false)
suite.True(b.Valid, "should be valid")
suite.False(b.Bool, "should have correct value")
}
func TestNewBool(t *testing.T) {
suite.Run(t, new(NewBoolSuite))
}
// BoolMarshalJSONSuite tests Bool.MarshalJSON.
type BoolMarshalJSONSuite struct {
suite.Suite
}
func (suite *BoolMarshalJSONSuite) TestNotValid() {
b := Bool{Bool: true, Valid: false}
raw, err := json.Marshal(b)
suite.Require().NoError(err, "should not fail")
suite.Equal(jsonNull, raw, "should return correct value")
}
func (suite *BoolMarshalJSONSuite) TestOK1() {
b := NewBool(true)
raw, err := json.Marshal(b)
suite.Require().NoError(err, "should not fail")
suite.Equal(marshalMust(true), raw, "should return correct value")
}
func (suite *BoolMarshalJSONSuite) TestOK2() {
b := NewBool(false)
raw, err := json.Marshal(b)
suite.Require().NoError(err, "should not fail")
suite.Equal(marshalMust(false), raw, "should return correct value")
}
func TestBool_MarshalJSON(t *testing.T) {
suite.Run(t, new(BoolMarshalJSONSuite))
}
// BoolUnmarshalJSONSuite tests Bool.UnmarshalJSON.
type BoolUnmarshalJSONSuite struct {
suite.Suite
}
func (suite *BoolUnmarshalJSONSuite) TestNull() {
var b Bool
err := json.Unmarshal(jsonNull, &b)
suite.Require().NoError(err, "should not fail")
suite.False(b.Valid, "should not be valid")
}
func (suite *BoolUnmarshalJSONSuite) TestOK1() {
var b Bool
err := json.Unmarshal([]byte("true"), &b)
suite.Require().NoError(err, "should not fail")
suite.True(b.Valid, "should be valid")
suite.True(b.Bool, "should unmarshal correct value")
}
func (suite *BoolUnmarshalJSONSuite) TestOK2() {
var b Bool
err := json.Unmarshal([]byte("false"), &b)
suite.Require().NoError(err, "should not fail")
suite.True(b.Valid, "should be valid")
suite.False(b.Bool, "should unmarshal correct value")
}
func TestBool_UnmarshalJSON(t *testing.T) {
suite.Run(t, new(BoolUnmarshalJSONSuite))
}
// BoolScanSuite tests Bool.Scan.
type BoolScanSuite struct {
suite.Suite
}
func (suite *BoolScanSuite) TestNull() {
var b Bool
err := b.Scan(nil)
suite.Require().NoError(err, "should not fail")
suite.False(b.Valid, "should not be valid")
}
func (suite *BoolScanSuite) TestOK1() {
var b Bool
err := b.Scan([]byte("true"))
suite.Require().NoError(err, "should not fail")
suite.True(b.Valid, "should be valid")
suite.True(b.Bool, "should return correct value")
}
func (suite *BoolScanSuite) TestOK2() {
var b Bool
err := b.Scan([]byte("false"))
suite.Require().NoError(err, "should not fail")
suite.True(b.Valid, "should be valid")
suite.False(b.Bool, "should return correct value")
}
func TestBool_Scan(t *testing.T) {
suite.Run(t, new(BoolScanSuite))
}
// BoolValueSuite tests Bool.Value.
type BoolValueSuite struct {
suite.Suite
}
func (suite *BoolValueSuite) TestNull() {
b := Bool{Valid: false}
v, err := b.Value()
suite.Require().NoError(err, "should not fail")
suite.Nil(v, "should return correct value")
}
func (suite *BoolValueSuite) TestOK1() {
b := NewBool(true)
v, err := b.Value()
suite.Require().NoError(err, "should not fail")
suite.EqualValues(true, v, "should return correct value")
}
func (suite *BoolValueSuite) TestOK2() {
b := NewBool(false)
v, err := b.Value()
suite.Require().NoError(err, "should not fail")
suite.EqualValues(false, v, "should not fail")
}
func TestBool_Value(t *testing.T) {
suite.Run(t, new(BoolValueSuite))
}