-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopts_test.go
More file actions
57 lines (48 loc) · 881 Bytes
/
opts_test.go
File metadata and controls
57 lines (48 loc) · 881 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
56
57
package opts
import "testing"
type defaulter struct {
Str string
Int int
Float float32
Bool bool
}
func (d defaulter) DefaultOptions() defaulter {
return defaulter{
Str: "1",
Int: 2,
Float: 3.0,
}
}
func withStr(s string) Opt[defaulter] {
return func(o *defaulter) {
o.Str = s
}
}
func withBool(b bool) Opt[defaulter] {
return func(o *defaulter) {
o.Bool = b
}
}
func withInt(i int) Opt[defaulter] {
return func(o *defaulter) {
o.Int = i
}
}
func withFloat(f float32) Opt[defaulter] {
return func(o *defaulter) {
o.Float = f
}
}
func TestDefaultApply(t *testing.T) {
expected := defaulter{
Str: "1",
Int: 5,
Float: 2.0,
Bool: true,
}
actual := DefaultApply(withFloat(expected.Float), withInt(expected.Int), withBool(true))
if expected != actual {
t.Errorf("Expected %v but got %v", expected, actual)
t.Fail()
}
}