-
Notifications
You must be signed in to change notification settings - Fork 4
/
gohelper_test.go
84 lines (79 loc) · 1.7 KB
/
gohelper_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
package genus
import "testing"
func TestStringWithDefault(t *testing.T) {
type args struct {
v string
d string
}
tests := []struct {
name string
args args
want string
}{
{"OK", args{"", "d"}, "d"},
{"OK", args{"v", "d"}, "v"},
{"OK", args{"v", ""}, "v"},
}
for _, tt := range tests {
if got := StringWithDefault(tt.args.v, tt.args.d); got != tt.want {
t.Errorf("%q. StringWithDefault() = %v, want %v", tt.name, got, tt.want)
}
}
}
func Test_once_Has(t *testing.T) {
type args struct {
s string
}
tests := []struct {
name string
o once
args args
want bool
}{
{"OK - has => true", once{"a": struct{}{}}, args{"a"}, true},
{"OK - has => false", once{"a": struct{}{}}, args{"b"}, false},
}
for _, tt := range tests {
if got := tt.o.Has(tt.args.s); got != tt.want {
t.Errorf("%q. once.Has() = %v, want %v", tt.name, got, tt.want)
}
}
}
func Test_once_Put(t *testing.T) {
type args struct {
s string
}
tests := []struct {
name string
o once
args args
want bool
}{
{"OK - true", once{"a": struct{}{}}, args{"a"}, false},
{"OK - false", once{"a": struct{}{}}, args{"b"}, true},
}
for _, tt := range tests {
if got := tt.o.Put(tt.args.s); got != tt.want {
t.Errorf("%q. once.Put() = %v, want %v", tt.name, got, tt.want)
}
}
}
func TestBoolWithDefault(t *testing.T) {
type args struct {
v bool
d bool
}
tests := []struct {
name string
args args
want bool
}{
{"OK - true + true", args{true, true}, true},
{"OK - false + true", args{false, true}, true},
}
for _, tt := range tests {
if got := BoolWithDefault(tt.args.v, tt.args.d); got != tt.want {
t.Errorf("%q. BoolWithDefault() = %v, want %v", tt.name, got, tt.want)
}
}
}