@@ -80,43 +80,8 @@ func Test_Concat_OneEmptyObservable(t *testing.T) {
80
80
Assert (context .Background (), t , obs , HasItems (1 , 2 , 3 ))
81
81
}
82
82
83
- func Test_Empty (t * testing.T ) {
84
- obs := Empty ()
85
- Assert (context .Background (), t , obs , HasNoItems ())
86
- }
87
-
88
- func Test_FromChannel (t * testing.T ) {
89
- ch := make (chan Item )
90
- go func () {
91
- ch <- Of (1 )
92
- ch <- Of (2 )
93
- ch <- Of (3 )
94
- close (ch )
95
- }()
96
- obs := FromChannel (ch )
97
- Assert (context .Background (), t , obs , HasItems (1 , 2 , 3 ), HasNotRaisedError ())
98
- }
99
-
100
- func Test_FromChannel_SimpleCapacity (t * testing.T ) {
101
- ch := FromChannel (make (chan Item , 10 )).Observe (WithBufferedChannel (11 ))
102
- assert .Equal (t , 10 , cap (ch ))
103
- }
104
-
105
- func Test_FromChannel_ComposedCapacity (t * testing.T ) {
106
- obs1 := FromChannel (make (chan Item , 10 )).
107
- Map (func (_ interface {}) (interface {}, error ) {
108
- return 1 , nil
109
- }, WithBufferedChannel (11 ))
110
- assert .Equal (t , 11 , cap (obs1 .Observe (WithBufferedChannel (13 ))))
111
-
112
- obs2 := obs1 .Map (func (_ interface {}) (interface {}, error ) {
113
- return 1 , nil
114
- }, WithBufferedChannel (12 ))
115
- assert .Equal (t , 12 , cap (obs2 .Observe (WithBufferedChannel (13 ))))
116
- }
117
-
118
- func Test_FromFuncs (t * testing.T ) {
119
- obs := FromFuncs (func (ctx context.Context , next chan <- Item , done func ()) {
83
+ func Test_Defer (t * testing.T ) {
84
+ obs := Defer (func (ctx context.Context , next chan <- Item , done func ()) {
120
85
next <- Of (1 )
121
86
next <- Of (2 )
122
87
next <- Of (3 )
@@ -125,8 +90,8 @@ func Test_FromFuncs(t *testing.T) {
125
90
Assert (context .Background (), t , obs , HasItems (1 , 2 , 3 ), HasNotRaisedError ())
126
91
}
127
92
128
- func Test_FromFuncs_Multiple (t * testing.T ) {
129
- obs := FromFuncs (func (ctx context.Context , next chan <- Item , done func ()) {
93
+ func Test_Defer_Multiple (t * testing.T ) {
94
+ obs := Defer (func (ctx context.Context , next chan <- Item , done func ()) {
130
95
next <- Of (1 )
131
96
next <- Of (2 )
132
97
done ()
@@ -138,8 +103,8 @@ func Test_FromFuncs_Multiple(t *testing.T) {
138
103
Assert (context .Background (), t , obs , HasItemsNoParticularOrder (1 , 2 , 10 , 20 ), HasNotRaisedError ())
139
104
}
140
105
141
- func Test_FromFuncs_Close (t * testing.T ) {
142
- obs := FromFuncs (func (ctx context.Context , next chan <- Item , done func ()) {
106
+ func Test_Defer_Close (t * testing.T ) {
107
+ obs := Defer (func (ctx context.Context , next chan <- Item , done func ()) {
143
108
next <- Of (1 )
144
109
next <- Of (2 )
145
110
next <- Of (3 )
@@ -148,8 +113,8 @@ func Test_FromFuncs_Close(t *testing.T) {
148
113
Assert (context .Background (), t , obs , HasItems (1 , 2 , 3 ), HasNotRaisedError ())
149
114
}
150
115
151
- func Test_FromFuncs_SingleDup (t * testing.T ) {
152
- obs := FromFuncs (func (ctx context.Context , next chan <- Item , done func ()) {
116
+ func Test_Defer_SingleDup (t * testing.T ) {
117
+ obs := Defer (func (ctx context.Context , next chan <- Item , done func ()) {
153
118
next <- Of (1 )
154
119
next <- Of (2 )
155
120
next <- Of (3 )
@@ -159,8 +124,8 @@ func Test_FromFuncs_SingleDup(t *testing.T) {
159
124
Assert (context .Background (), t , obs , HasItems (1 , 2 , 3 ), HasNotRaisedError ())
160
125
}
161
126
162
- func Test_FromFuncs_ComposedDup (t * testing.T ) {
163
- obs := FromFuncs (func (ctx context.Context , next chan <- Item , done func ()) {
127
+ func Test_Defer_ComposedDup (t * testing.T ) {
128
+ obs := Defer (func (ctx context.Context , next chan <- Item , done func ()) {
164
129
next <- Of (1 )
165
130
next <- Of (2 )
166
131
next <- Of (3 )
@@ -174,8 +139,8 @@ func Test_FromFuncs_ComposedDup(t *testing.T) {
174
139
Assert (context .Background (), t , obs , HasItems (3 , 4 , 5 ), HasNotRaisedError ())
175
140
}
176
141
177
- func Test_FromFuncs_ComposedDup_EagerObservation (t * testing.T ) {
178
- obs := FromFuncs (func (ctx context.Context , next chan <- Item , done func ()) {
142
+ func Test_Defer_ComposedDup_EagerObservation (t * testing.T ) {
143
+ obs := Defer (func (ctx context.Context , next chan <- Item , done func ()) {
179
144
next <- Of (1 )
180
145
next <- Of (2 )
181
146
next <- Of (3 )
@@ -186,13 +151,13 @@ func Test_FromFuncs_ComposedDup_EagerObservation(t *testing.T) {
186
151
return i .(int ) + 1 , nil
187
152
})
188
153
Assert (context .Background (), t , obs , HasItems (3 , 4 , 5 ), HasNotRaisedError ())
189
- // In the case of an eager observation, we already consumed the items produced by FromFuncs
154
+ // In the case of an eager observation, we already consumed the items produced by Defer
190
155
// So if we create another subscription, it will be empty
191
156
Assert (context .Background (), t , obs , HasNoItem (), HasNotRaisedError ())
192
157
}
193
158
194
- func Test_FromFuncs_Error (t * testing.T ) {
195
- obs := FromFuncs (func (ctx context.Context , next chan <- Item , done func ()) {
159
+ func Test_Defer_Error (t * testing.T ) {
160
+ obs := Defer (func (ctx context.Context , next chan <- Item , done func ()) {
196
161
next <- Of (1 )
197
162
next <- Of (2 )
198
163
next <- Error (errFoo )
@@ -201,15 +166,15 @@ func Test_FromFuncs_Error(t *testing.T) {
201
166
Assert (context .Background (), t , obs , HasItems (1 , 2 ), HasRaisedError (errFoo ))
202
167
}
203
168
204
- func Test_FromFuncs_SimpleCapacity (t * testing.T ) {
205
- ch := FromFuncs (func (_ context.Context , _ chan <- Item , done func ()) {
169
+ func Test_Defer_SimpleCapacity (t * testing.T ) {
170
+ ch := Defer (func (_ context.Context , _ chan <- Item , done func ()) {
206
171
done ()
207
172
}).Observe (WithBufferedChannel (5 ))
208
173
assert .Equal (t , 5 , cap (ch ))
209
174
}
210
175
211
- func Test_FromFuncs_ComposedCapacity (t * testing.T ) {
212
- obs1 := FromFuncs (func (_ context.Context , _ chan <- Item , done func ()) {
176
+ func Test_Defer_ComposedCapacity (t * testing.T ) {
177
+ obs1 := Defer (func (_ context.Context , _ chan <- Item , done func ()) {
213
178
done ()
214
179
}).Map (func (_ interface {}) (interface {}, error ) {
215
180
return 1 , nil
@@ -222,6 +187,41 @@ func Test_FromFuncs_ComposedCapacity(t *testing.T) {
222
187
assert .Equal (t , 12 , cap (obs2 .Observe (WithBufferedChannel (13 ))))
223
188
}
224
189
190
+ func Test_Empty (t * testing.T ) {
191
+ obs := Empty ()
192
+ Assert (context .Background (), t , obs , HasNoItems ())
193
+ }
194
+
195
+ func Test_FromChannel (t * testing.T ) {
196
+ ch := make (chan Item )
197
+ go func () {
198
+ ch <- Of (1 )
199
+ ch <- Of (2 )
200
+ ch <- Of (3 )
201
+ close (ch )
202
+ }()
203
+ obs := FromChannel (ch )
204
+ Assert (context .Background (), t , obs , HasItems (1 , 2 , 3 ), HasNotRaisedError ())
205
+ }
206
+
207
+ func Test_FromChannel_SimpleCapacity (t * testing.T ) {
208
+ ch := FromChannel (make (chan Item , 10 )).Observe (WithBufferedChannel (11 ))
209
+ assert .Equal (t , 10 , cap (ch ))
210
+ }
211
+
212
+ func Test_FromChannel_ComposedCapacity (t * testing.T ) {
213
+ obs1 := FromChannel (make (chan Item , 10 )).
214
+ Map (func (_ interface {}) (interface {}, error ) {
215
+ return 1 , nil
216
+ }, WithBufferedChannel (11 ))
217
+ assert .Equal (t , 11 , cap (obs1 .Observe (WithBufferedChannel (13 ))))
218
+
219
+ obs2 := obs1 .Map (func (_ interface {}) (interface {}, error ) {
220
+ return 1 , nil
221
+ }, WithBufferedChannel (12 ))
222
+ assert .Equal (t , 12 , cap (obs2 .Observe (WithBufferedChannel (13 ))))
223
+ }
224
+
225
225
func Test_FromItem (t * testing.T ) {
226
226
single := JustItem (Of (1 ))
227
227
Assert (context .Background (), t , single , HasItem (1 ), HasNotRaisedError ())
0 commit comments