-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtarget_test.go
59 lines (44 loc) · 1.19 KB
/
target_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
package optionutils_test
import (
"github.com/mandelsoft/goutils/optionutils"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
type OrigOptions struct {
Orig string
}
type DerivedOptions struct {
OrigOptions
Derived string
}
type orig string
func (o orig) ApplyTo(opts *OrigOptions) {
opts.Orig = string(o)
}
func WithOrig(s string) optionutils.Option[*OrigOptions] {
return orig(s)
}
type derived string
func (o derived) ApplyTo(opts *DerivedOptions) {
opts.Derived = string(o)
}
func WithDerived(s string) optionutils.Option[*DerivedOptions] {
return derived(s)
}
func WithOrigDerived(s string) optionutils.Option[*DerivedOptions] {
return optionutils.MapOptionTarget[*DerivedOptions, *OrigOptions](WithOrig(s))
}
var _ = Describe("Mapped Options Test Environment", func() {
It("", func() {
var opts DerivedOptions
list := []optionutils.Option[*DerivedOptions]{
WithDerived("d"),
WithOrigDerived("o"),
}
optionutils.ApplyOptions(&opts, list...)
Expect(opts.Derived).To(Equal("d"))
Expect(opts.Orig).To(Equal(""))
optionutils.ApplyOptions(&opts.OrigOptions, optionutils.FilterMappedOptions[*OrigOptions](list...)...)
Expect(opts.Orig).To(Equal("o"))
})
})