-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathint16_test.go
109 lines (91 loc) · 2.64 KB
/
int16_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"
)
// TestNewInt16 tests NewInt16.
func TestNewInt16(t *testing.T) {
i := NewInt16(16)
assert.True(t, i.Valid, "should be valid")
assert.EqualValues(t, 16, i.Int16, "should contain correct value")
}
// Int16MarshalJSONSuite tests Int16.MarshalJSON.
type Int16MarshalJSONSuite struct {
suite.Suite
}
func (suite *Int16MarshalJSONSuite) TestNotValid() {
i := Int16{Int16: 16}
raw, err := json.Marshal(i)
suite.Require().NoError(err, "should not fail")
suite.Equal(jsonNull, raw, "should return correct value")
}
func (suite *Int16MarshalJSONSuite) TestOK() {
i := NewInt16(16)
raw, err := json.Marshal(i)
suite.Require().NoError(err, "should not fail")
suite.Equal(marshalMust(16), raw, "should return correct value")
}
func TestInt16_MarshalJSON(t *testing.T) {
suite.Run(t, new(Int16MarshalJSONSuite))
}
// Int16UnmarshalJSONSuite tests Int16.UnmarshalJSON.
type Int16UnmarshalJSONSuite struct {
suite.Suite
}
func (suite *Int16UnmarshalJSONSuite) TestNull() {
var i Int16
err := json.Unmarshal(jsonNull, &i)
suite.Require().NoError(err, "should not fail")
suite.False(i.Valid, "should not be valid")
}
func (suite *Int16UnmarshalJSONSuite) TestOK() {
var i Int16
err := json.Unmarshal(marshalMust(16), &i)
suite.Require().NoError(err, "should not fail")
suite.True(i.Valid, "should be valid")
suite.EqualValues(16, i.Int16, "should unmarshal correct value")
}
func TestInt16_UnmarshalJSON(t *testing.T) {
suite.Run(t, new(Int16UnmarshalJSONSuite))
}
// Int16ScanSuite tests Int16.Scan.
type Int16ScanSuite struct {
suite.Suite
}
func (suite *Int16ScanSuite) TestNull() {
var i Int16
err := i.Scan(nil)
suite.Require().NoError(err, "should not fail")
suite.False(i.Valid, "should not be valid")
}
func (suite *Int16ScanSuite) TestOK() {
var i Int16
err := i.Scan(16)
suite.Require().NoError(err, "should not fail")
suite.True(i.Valid, "should be valid")
suite.EqualValues(16, i.Int16, "should scan correct value")
}
func TestInt16_Scan(t *testing.T) {
suite.Run(t, new(Int16ScanSuite))
}
// Int16ValueSuite tests Int.Value.
type Int16ValueSuite struct {
suite.Suite
}
func (suite *Int16ValueSuite) TestNull() {
i := Int16{Int16: 16}
raw, err := i.Value()
suite.Require().NoError(err, "should not fail")
suite.Nil(raw, "should return correct value")
}
func (suite *Int16ValueSuite) TestOK() {
i := NewInt16(16)
raw, err := i.Value()
suite.Require().NoError(err, "should not fail")
suite.EqualValues(16, raw, "should return correct value")
}
func TestInt16_Value(t *testing.T) {
suite.Run(t, new(Int16ValueSuite))
}