-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
int_test.go
62 lines (55 loc) · 898 Bytes
/
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
package nulls_test
import (
"testing"
"github.com/gobuffalo/nulls"
"github.com/stretchr/testify/require"
)
func Test_IntUnmarshalJSON(t *testing.T) {
r := require.New(t)
cases := []struct {
Input []byte
Value int
Valid bool
}{
{
Input: []byte{'0'},
Value: 0,
Valid: true,
},
{
Input: []byte{'4', '2'},
Value: 42,
Valid: true,
},
{
Input: []byte{'n', 'u', 'l', 'l'},
Value: 0,
Valid: false,
},
}
for _, c := range cases {
i := nulls.Int{}
r.NoError(i.UnmarshalJSON(c.Input))
r.Equal(c.Value, i.Int)
r.Equal(c.Valid, i.Valid)
}
}
func Test_IntUnmarshalJSON_Errors(t *testing.T) {
r := require.New(t)
cases := []struct {
Input []byte
}{
{
Input: []byte{'a'},
},
{
Input: []byte{},
},
}
for _, c := range cases {
i := nulls.Int{}
r.Error(i.UnmarshalJSON(c.Input))
r.Equal(0, i.Int)
r.False(i.Valid)
}
}