-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnone_test.go
116 lines (109 loc) · 2.39 KB
/
none_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
110
111
112
113
114
115
116
package option
import (
"github.com/stretchr/testify/assert"
"reflect"
"testing"
)
func TestNone_Empty(t *testing.T) {
tests := []struct {
name string
want bool
}{
{name: "None[T] Empty() returns true", want: true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
n := None[int]()
if got := n.Empty(); got != tt.want {
t.Errorf("Empty() = %v, want %v", got, tt.want)
}
})
}
}
func TestNone_Get(t *testing.T) {
tests := []struct {
name string
want int
}{
{name: "None[T] Get throws an exception"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
n := None[int]()
assert.Panics(t, func() { n.Get() })
})
}
}
func TestNone_GetOrElse(t *testing.T) {
type args struct {
v int
}
tests := []struct {
name string
args args
want int
}{
{name: "None[T] GetOrElse() returns else value", args: args{v: 2}, want: 2},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
n := None[int]()
if got := n.GetOrElse(tt.args.v); !reflect.DeepEqual(got, tt.want) {
t.Errorf("GetOrElse() = %v, want %v", got, tt.want)
}
})
}
}
func TestNone_NonEmpty(t *testing.T) {
tests := []struct {
name string
want bool
}{
{name: "None[T] Empty() returns false", want: false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
n := None[int]()
if got := n.NonEmpty(); got != tt.want {
t.Errorf("NonEmpty() = %v, want %v", got, tt.want)
}
})
}
}
func TestNone_OrElse(t *testing.T) {
type args struct {
opt Option[int]
}
tests := []struct {
name string
args args
want Option[int]
}{
{name: "None[T] OrElse() returns None if else condition is None", args: args{opt: None[int]()}, want: None[int]()},
{name: "None[T] OrElse() returns Some if else condition is Some", args: args{opt: Some[int](2)}, want: Some[int](2)},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
n := None[int]()
if got := n.OrElse(tt.args.opt); !reflect.DeepEqual(got, tt.want) {
t.Errorf("OrElse() = %v, want %v", got, tt.want)
}
})
}
}
func TestNone_String(t *testing.T) {
tests := []struct {
name string
want string
}{
{name: "None[T] String() returns None", want: "None"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
n := None[int]()
if got := n.String(); got != tt.want {
t.Errorf("String() = %v, want %v", got, tt.want)
}
})
}
}