-
Notifications
You must be signed in to change notification settings - Fork 0
/
nullable_test.go
52 lines (46 loc) · 1012 Bytes
/
nullable_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
package json
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestNullBool(t *testing.T) {
type v struct {
NullBool Nullable[bool] `json:"null_bool"`
}
cases := []struct {
input Nullable[bool]
data string
}{
{Null[bool](), `{"null_bool":null}`},
{NewNullable(true), `{"null_bool":true}`},
{NewNullable(false), `{"null_bool":false}`},
}
for _, c := range cases {
data, err := Marshal(v{
NullBool: c.input,
})
assert.NoError(t, err)
assert.Equal(t, c.data, string(data))
}
}
func TestNullBoolPtr(t *testing.T) {
type v struct {
NullBool *Nullable[bool] `json:"null_bool,omitempty"`
}
cases := []struct {
input *Nullable[bool]
data string
}{
{nil, `{}`},
{NullPtr[bool](), `{"null_bool":null}`},
{NewNullablePtr(true), `{"null_bool":true}`},
{NewNullablePtr(false), `{"null_bool":false}`},
}
for _, c := range cases {
data, err := Marshal(v{
NullBool: c.input,
})
assert.NoError(t, err)
assert.Equal(t, c.data, string(data))
}
}