-
Notifications
You must be signed in to change notification settings - Fork 1
/
testsetter_test.go
196 lines (178 loc) · 3.28 KB
/
testsetter_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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
package jaws
import (
"github.com/linkdata/deadlock"
)
type testSetter[T comparable] struct {
mu deadlock.Mutex
val T
err error
setCount int
setCalled chan struct{}
getCount int
getCalled chan struct{}
}
func newTestSetter[T comparable](val T) *testSetter[T] {
return &testSetter[T]{
val: val,
setCalled: make(chan struct{}),
getCalled: make(chan struct{}),
}
}
func (ts *testSetter[T]) Get() (s T) {
ts.mu.Lock()
s = ts.val
ts.mu.Unlock()
return
}
func (ts *testSetter[T]) Set(s T) {
ts.mu.Lock()
ts.val = s
ts.mu.Unlock()
}
func (ts *testSetter[T]) SetCount() (n int) {
ts.mu.Lock()
n = ts.setCount
ts.mu.Unlock()
return
}
func (ts *testSetter[T]) GetCount() (n int) {
ts.mu.Lock()
n = ts.getCount
ts.mu.Unlock()
return
}
func (ts *testSetter[T]) JawsGetTime(e *Element) (val T) {
ts.mu.Lock()
defer ts.mu.Unlock()
ts.getCount++
if ts.getCount == 1 {
close(ts.getCalled)
}
val = ts.val
return
}
func (ts *testSetter[T]) JawsSetTime(e *Element, val T) (err error) {
ts.mu.Lock()
defer ts.mu.Unlock()
ts.setCount++
if ts.setCount == 1 {
close(ts.setCalled)
}
if err = ts.err; err == nil {
if ts.val == val {
err = ErrValueUnchanged
}
ts.val = val
}
return
}
func (ts *testSetter[string]) JawsGetString(e *Element) (val string) {
ts.mu.Lock()
defer ts.mu.Unlock()
ts.getCount++
if ts.getCount == 1 {
close(ts.getCalled)
}
val = ts.val
return
}
func (ts *testSetter[string]) JawsSetString(e *Element, val string) (err error) {
ts.mu.Lock()
defer ts.mu.Unlock()
ts.setCount++
if ts.setCount == 1 {
close(ts.setCalled)
}
if err = ts.err; err == nil {
if ts.val == val {
err = ErrValueUnchanged
}
ts.val = val
}
return
}
func (ts *testSetter[bool]) JawsGetBool(e *Element) (val bool) {
ts.mu.Lock()
defer ts.mu.Unlock()
ts.getCount++
if ts.getCount == 1 {
close(ts.getCalled)
}
val = ts.val
return
}
func (ts *testSetter[bool]) JawsSetBool(e *Element, val bool) (err error) {
ts.mu.Lock()
defer ts.mu.Unlock()
ts.setCount++
if ts.setCount == 1 {
close(ts.setCalled)
}
if err = ts.err; err == nil {
if ts.val == val {
err = ErrValueUnchanged
}
ts.val = val
}
return
}
func (ts *testSetter[float64]) JawsGetFloat(e *Element) (val float64) {
ts.mu.Lock()
defer ts.mu.Unlock()
ts.getCount++
if ts.getCount == 1 {
close(ts.getCalled)
}
val = ts.val
return
}
func (ts *testSetter[float64]) JawsSetFloat(e *Element, val float64) (err error) {
ts.mu.Lock()
defer ts.mu.Unlock()
ts.setCount++
if ts.setCount == 1 {
close(ts.setCalled)
}
if err = ts.err; err == nil {
if ts.val == val {
err = ErrValueUnchanged
}
ts.val = val
}
return
}
func (ts *testSetter[any]) JawsGetAny(e *Element) (val any) {
ts.mu.Lock()
defer ts.mu.Unlock()
ts.getCount++
if ts.getCount == 1 {
close(ts.getCalled)
}
val = ts.val
return
}
func (ts *testSetter[any]) JawsSetAny(e *Element, val any) (err error) {
ts.mu.Lock()
defer ts.mu.Unlock()
ts.setCount++
if ts.setCount == 1 {
close(ts.setCalled)
}
if err = ts.err; err == nil {
if ts.val == val {
err = ErrValueUnchanged
}
ts.val = val
}
return
}
func (ts *testSetter[T]) JawsGetHtml(e *Element) (val T) {
ts.mu.Lock()
defer ts.mu.Unlock()
ts.getCount++
if ts.getCount == 1 {
close(ts.getCalled)
}
val = ts.val
return
}