-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfloat32_test.go
109 lines (91 loc) · 2.74 KB
/
float32_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"
)
// TestNewFloat32 tests NewFloat32.
func TestNewFloat32(t *testing.T) {
f := NewFloat32(32)
assert.True(t, f.Valid, "should be valid")
assert.EqualValues(t, 32, f.Float32, "should contain correct value")
}
// Float32MarshalJSONSuite tests Float32.MarshalJSON.
type Float32MarshalJSONSuite struct {
suite.Suite
}
func (suite *Float32MarshalJSONSuite) TestNotValid() {
f := Float32{Float32: 32}
raw, err := json.Marshal(f)
suite.Require().NoError(err, "should not fail")
suite.Equal(jsonNull, raw, "should return correct value")
}
func (suite *Float32MarshalJSONSuite) TestOK() {
f := NewFloat32(32)
raw, err := json.Marshal(f)
suite.Require().NoError(err, "should not fail")
suite.Equal(marshalMust(32), raw, "should return correct value")
}
func TestFloat32_MarshalJSON(t *testing.T) {
suite.Run(t, new(Float32MarshalJSONSuite))
}
// Float32UnmarshalJSONSuite tests Float32.UnmarshalJSON.
type Float32UnmarshalJSONSuite struct {
suite.Suite
}
func (suite *Float32UnmarshalJSONSuite) TestNull() {
var f Float32
err := json.Unmarshal(jsonNull, &f)
suite.Require().NoError(err, "should not fail")
suite.False(f.Valid, "should not be valid")
}
func (suite *Float32UnmarshalJSONSuite) TestOK() {
var f Float32
err := json.Unmarshal(marshalMust(32), &f)
suite.Require().NoError(err, "should not fail")
suite.True(f.Valid, "should be valid")
suite.EqualValues(32, f.Float32, "should unmarshal correct value")
}
func TestFloat32_UnmarshalJSON(t *testing.T) {
suite.Run(t, new(Float32UnmarshalJSONSuite))
}
// Float32ScanSuite tests Float32.Scan.
type Float32ScanSuite struct {
suite.Suite
}
func (suite *Float32ScanSuite) TestNull() {
var f Float32
err := f.Scan(nil)
suite.Require().NoError(err, "should not fail")
suite.False(f.Valid, "should not be valid")
}
func (suite *Float32ScanSuite) TestOK() {
var f Float32
err := f.Scan(float64(64))
suite.Require().NoError(err, "should not fail")
suite.True(f.Valid, "should be valid")
suite.EqualValues(64, f.Float32, "should scan correct value")
}
func TestFloat32_Scan(t *testing.T) {
suite.Run(t, new(Float32ScanSuite))
}
// Float32ValueSuite tests Float32.Value.
type Float32ValueSuite struct {
suite.Suite
}
func (suite *Float32ValueSuite) TestNull() {
f := Float32{Float32: 32}
raw, err := f.Value()
suite.Require().NoError(err, "should not fail")
suite.Nil(raw, "should return correct value")
}
func (suite *Float32ValueSuite) TestOK() {
f := NewFloat32(32)
raw, err := f.Value()
suite.Require().NoError(err, "should not fail")
suite.Equal(float64(32), raw, "should return correct value")
}
func TestFloat32_Value(t *testing.T) {
suite.Run(t, new(Float32ValueSuite))
}