-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathint_test.go
109 lines (91 loc) · 2.55 KB
/
int_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"
)
// TestNewInt tests NewInt.
func TestNewInt(t *testing.T) {
i := NewInt(64)
assert.True(t, i.Valid, "should be valid")
assert.EqualValues(t, 64, i.Int, "should contain correct value")
}
// IntMarshalJSONSuite tests Int.MarshalJSON.
type IntMarshalJSONSuite struct {
suite.Suite
}
func (suite *IntMarshalJSONSuite) TestNotValid() {
i := Int{Int: 64}
raw, err := json.Marshal(i)
suite.Require().NoError(err, "should not fail")
suite.Equal(jsonNull, raw, "should return correct value")
}
func (suite *IntMarshalJSONSuite) TestOK() {
i := NewInt(64)
raw, err := json.Marshal(i)
suite.Require().NoError(err, "should not fail")
suite.Equal(marshalMust(64), raw, "should return correct value")
}
func TestInt_MarshalJSON(t *testing.T) {
suite.Run(t, new(IntMarshalJSONSuite))
}
// IntUnmarshalJSONSuite tests Int.UnmarshalJSON.
type IntUnmarshalJSONSuite struct {
suite.Suite
}
func (suite *IntUnmarshalJSONSuite) TestNull() {
var i Int
err := json.Unmarshal(jsonNull, &i)
suite.Require().NoError(err, "should not fail")
suite.False(i.Valid, "should not be valid")
}
func (suite *IntUnmarshalJSONSuite) TestOK() {
var i Int
err := json.Unmarshal(marshalMust(64), &i)
suite.Require().NoError(err, "should not fail")
suite.True(i.Valid, "should be valid")
suite.EqualValues(64, i.Int, "should unmarshal correct value")
}
func TestInt_UnmarshalJSON(t *testing.T) {
suite.Run(t, new(IntUnmarshalJSONSuite))
}
// IntScanSuite tests Int.Scan.
type IntScanSuite struct {
suite.Suite
}
func (suite *IntScanSuite) TestNull() {
var i Int
err := i.Scan(nil)
suite.Require().NoError(err, "should not fail")
suite.False(i.Valid, "should not be valid")
}
func (suite *IntScanSuite) TestOK() {
var i Int
err := i.Scan(64)
suite.Require().NoError(err, "should not fail")
suite.True(i.Valid, "should be valid")
suite.EqualValues(64, i.Int, "should scan correct value")
}
func TestInt_Scan(t *testing.T) {
suite.Run(t, new(IntScanSuite))
}
// IntValueSuite tests Int.Value.
type IntValueSuite struct {
suite.Suite
}
func (suite *IntValueSuite) TestNull() {
i := Int{Int: 64}
raw, err := i.Value()
suite.Require().NoError(err, "should not fail")
suite.Nil(raw, "should return correct value")
}
func (suite *IntValueSuite) TestOK() {
i := NewInt(64)
raw, err := i.Value()
suite.Require().NoError(err, "should not fail")
suite.EqualValues(64, raw, "should return correct value")
}
func TestInt_Value(t *testing.T) {
suite.Run(t, new(IntValueSuite))
}