-
Notifications
You must be signed in to change notification settings - Fork 0
/
int32_test.go
109 lines (91 loc) · 2.64 KB
/
int32_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
package nulls
import (
"encoding/json"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"testing"
)
// TestNewInt32 tests NewInt32.
func TestNewInt32(t *testing.T) {
i := NewInt32(64)
assert.True(t, i.Valid, "should be valid")
assert.EqualValues(t, 64, i.Int32, "should contain correct value")
}
// Int32MarshalJSONSuite tests Int32.MarshalJSON.
type Int32MarshalJSONSuite struct {
suite.Suite
}
func (suite *Int32MarshalJSONSuite) TestNotValid() {
i := Int32{Int32: 64}
raw, err := json.Marshal(i)
suite.Require().NoError(err, "should not fail")
suite.Equal(jsonNull, raw, "should return correct value")
}
func (suite *Int32MarshalJSONSuite) TestOK() {
i := NewInt32(64)
raw, err := json.Marshal(i)
suite.Require().NoError(err, "should not fail")
suite.Equal(marshalMust(64), raw, "should return correct value")
}
func TestInt32_MarshalJSON(t *testing.T) {
suite.Run(t, new(Int32MarshalJSONSuite))
}
// Int32UnmarshalJSONSuite tests Int32.UnmarshalJSON.
type Int32UnmarshalJSONSuite struct {
suite.Suite
}
func (suite *Int32UnmarshalJSONSuite) TestNull() {
var i Int32
err := json.Unmarshal(jsonNull, &i)
suite.Require().NoError(err, "should not fail")
suite.False(i.Valid, "should not be valid")
}
func (suite *Int32UnmarshalJSONSuite) TestOK() {
var i Int32
err := json.Unmarshal(marshalMust(64), &i)
suite.Require().NoError(err, "should not fail")
suite.True(i.Valid, "should be valid")
suite.EqualValues(64, i.Int32, "should unmarshal correct value")
}
func TestInt32_UnmarshalJSON(t *testing.T) {
suite.Run(t, new(Int32UnmarshalJSONSuite))
}
// Int32ScanSuite tests Int32.Scan.
type Int32ScanSuite struct {
suite.Suite
}
func (suite *Int32ScanSuite) TestNull() {
var i Int32
err := i.Scan(nil)
suite.Require().NoError(err, "should not fail")
suite.False(i.Valid, "should not be valid")
}
func (suite *Int32ScanSuite) TestOK() {
var i Int32
err := i.Scan(64)
suite.Require().NoError(err, "should not fail")
suite.True(i.Valid, "should be valid")
suite.EqualValues(64, i.Int32, "should scan correct value")
}
func TestInt32_Scan(t *testing.T) {
suite.Run(t, new(Int32ScanSuite))
}
// Int32ValueSuite tests Int.Value.
type Int32ValueSuite struct {
suite.Suite
}
func (suite *Int32ValueSuite) TestNull() {
i := Int32{Int32: 64}
raw, err := i.Value()
suite.Require().NoError(err, "should not fail")
suite.Nil(raw, "should return correct value")
}
func (suite *Int32ValueSuite) TestOK() {
i := NewInt32(64)
raw, err := i.Value()
suite.Require().NoError(err, "should not fail")
suite.EqualValues(64, raw, "should return correct value")
}
func TestInt32_Value(t *testing.T) {
suite.Run(t, new(Int32ValueSuite))
}