-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoption_test.go
More file actions
55 lines (50 loc) · 964 Bytes
/
option_test.go
File metadata and controls
55 lines (50 loc) · 964 Bytes
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
package fun_test
import (
"encoding/json"
"testing"
"github.com/rprtr258/assert"
"github.com/rprtr258/fun"
)
func TestOptionJSONMarshal(t *testing.T) {
for name, test := range map[string]struct {
opt fun.Option[int]
want string
}{
"valid": {
opt: fun.Valid(1),
want: "1",
},
"invalid": {
opt: fun.Invalid[int](),
want: "null",
},
} {
t.Run(name, func(t *testing.T) {
got, err := json.Marshal(test.opt)
assert.NoError(t, err)
assert.Equal(t, test.want, string(got))
})
}
}
func TestOptionJSONUnmarshal(t *testing.T) {
for name, test := range map[string]struct {
opt string
want fun.Option[int]
}{
"valid": {
opt: "1",
want: fun.Valid(1),
},
"invalid": {
opt: "null",
want: fun.Invalid[int](),
},
} {
t.Run(name, func(t *testing.T) {
var opt fun.Option[int]
err := json.Unmarshal([]byte(test.opt), &opt)
assert.NoError(t, err)
assert.Equal(t, test.want, opt)
})
}
}