-
Notifications
You must be signed in to change notification settings - Fork 1
/
anysetter_test.go
67 lines (62 loc) · 1.25 KB
/
anysetter_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
package jaws
import (
"reflect"
"sync/atomic"
"testing"
)
var _ AnySetter = (*testSetter[any])(nil)
func Test_makeAnySetter(t *testing.T) {
val := float64(12.34)
var av atomic.Value
av.Store(val)
ts := newTestSetter(any(val))
tests := []struct {
name string
v any
want AnySetter
in any
out any
err error
tag any
}{
{
name: "AnySetter",
v: ts,
want: ts,
out: val,
tag: ts,
},
{
name: "read-only",
v: val,
want: anyGetter{val},
in: -val,
out: val,
err: ErrValueNotSettable,
tag: nil,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := makeAnySetter(tt.v)
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("makeAnySetter() = %v, want %v", got, tt.want)
}
if out := got.JawsGetAny(nil); out != tt.out {
t.Errorf("makeAnySetter().JawsGetAny() = %v, want %v", out, tt.out)
}
if tt.in != nil {
if err := got.JawsSetAny(nil, tt.in); err != tt.err {
t.Errorf("makeAnySetter().JawsSetAny() = %v, want %v", err, tt.err)
}
}
gotTag := any(got)
if tg, ok := got.(TagGetter); ok {
gotTag = tg.JawsGetTag(nil)
}
if gotTag != tt.tag {
t.Errorf("makeAnySetter().tag = %v, want %v", gotTag, tt.tag)
}
})
}
}