merge_enum 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/merge_enum/merge_enumerable.rb +44 -16
- data/lib/merge_enum/version.rb +1 -1
- data/spec/merge_enum/merge_enumerable_spec.rb +970 -368
- metadata +3 -3
@@ -3,470 +3,1072 @@ require File.expand_path(File.join('../', 'spec_helper'), File.dirname(__FILE__)
|
|
3
3
|
|
4
4
|
describe MergeEnum::MergeEnumerable do
|
5
5
|
|
6
|
-
|
7
|
-
it "count" do
|
8
|
-
enum = MergeEnum::MergeEnumerable.new
|
9
|
-
expect(enum.count).to be 0
|
10
|
-
end
|
6
|
+
Target = MergeEnum::MergeEnumerable
|
11
7
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
8
|
+
def self.test_empty ctx, lt, options = {}
|
9
|
+
test_all ctx, lt, [], options
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.test_all ctx, lt, ary, options = {}
|
13
|
+
test_equal ctx, lt, ary, options
|
14
|
+
test_interrupt ctx, lt, ary, options
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.test_equal ctx, lt, ary, options = {}
|
18
|
+
line = options[:line]
|
19
|
+
ctx.instance_eval do
|
20
|
+
_line = line ? " <at:#{line}>" : ""
|
21
|
+
context "#count#{_line}" do
|
22
|
+
subject { send(lt).count }
|
23
|
+
it { is_expected.to be ary.count }
|
24
24
|
end
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
context "#to_a#{_line}" do
|
26
|
+
subject { send(lt).to_a }
|
27
|
+
it { is_expected.to eq ary.to_a }
|
28
28
|
end
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.test_interrupt ctx, lt, ary, options = {}
|
33
|
+
line = options[:line]
|
34
|
+
ctx.instance_eval do
|
35
|
+
_line = line ? " <at:#{line}>" : ""
|
36
|
+
context "#none?#{_line}" do
|
37
|
+
subject { send(lt).none? }
|
38
|
+
it { is_expected.to be ary.none? }
|
32
39
|
end
|
33
|
-
|
34
|
-
|
35
|
-
|
40
|
+
context "#any?#{_line}" do
|
41
|
+
subject { send(lt).any? }
|
42
|
+
it { is_expected.to be ary.any? }
|
36
43
|
end
|
37
44
|
end
|
45
|
+
end
|
38
46
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
expect(enum.count).to be 0
|
47
|
+
def self.test_error ctx, lt, options = {}
|
48
|
+
line = options[:line]
|
49
|
+
ctx.instance_eval do
|
50
|
+
_line = line ? " <at:#{line}>" : ""
|
51
|
+
context "#count#{_line}" do
|
52
|
+
subject { send(lt).count }
|
53
|
+
it { expect{ is_expected }.to raise_error }
|
47
54
|
end
|
48
|
-
|
49
|
-
|
50
|
-
expect
|
55
|
+
context "#to_a#{_line}" do
|
56
|
+
subject { send(lt).to_a }
|
57
|
+
it { expect{ is_expected }.to raise_error }
|
51
58
|
end
|
52
|
-
|
53
|
-
|
54
|
-
expect
|
59
|
+
context "#none?#{_line}" do
|
60
|
+
subject { send(lt).none? }
|
61
|
+
it { expect{ is_expected }.to raise_error }
|
55
62
|
end
|
56
|
-
|
57
|
-
|
58
|
-
expect
|
63
|
+
context "#any?#{_line}" do
|
64
|
+
subject { send(lt).any? }
|
65
|
+
it { expect{ is_expected }.to raise_error }
|
59
66
|
end
|
60
67
|
end
|
61
68
|
end
|
62
69
|
|
63
|
-
describe "
|
64
|
-
|
65
|
-
|
66
|
-
|
70
|
+
describe ".new nil" do
|
71
|
+
let(:enum) { Target.new nil }
|
72
|
+
test_error self, :enum, line: __LINE__
|
73
|
+
end
|
74
|
+
|
75
|
+
["hoge", "foo", "bar"].each do |val|
|
76
|
+
describe ".new '#{val}'" do
|
77
|
+
let(:enum) { Target.new val }
|
78
|
+
test_error self, :enum, line: __LINE__
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe ".new [], nil" do
|
83
|
+
let(:enum) { Target.new [], nil }
|
84
|
+
test_error self, :enum, line: __LINE__
|
85
|
+
end
|
86
|
+
|
87
|
+
describe ".new" do
|
88
|
+
|
89
|
+
describe "{}" do
|
90
|
+
let(:enum) { Target.new }
|
91
|
+
|
92
|
+
test_empty self, :enum, line: __LINE__
|
67
93
|
end
|
68
94
|
|
69
|
-
describe "
|
70
|
-
|
71
|
-
|
72
|
-
|
95
|
+
describe "first:" do
|
96
|
+
let(:enum) { Target.new first: first }
|
97
|
+
|
98
|
+
describe "0" do
|
99
|
+
let(:first) { 0 }
|
100
|
+
subject { enum }
|
101
|
+
|
102
|
+
test_empty self, :enum, line: __LINE__
|
73
103
|
end
|
74
|
-
|
75
|
-
|
76
|
-
|
104
|
+
|
105
|
+
context "<positive>" do
|
106
|
+
[1, 2, 50].each do |val|
|
107
|
+
describe "#{val}" do
|
108
|
+
let(:first) { val }
|
109
|
+
test_empty self, :enum, line: __LINE__
|
110
|
+
end
|
111
|
+
end
|
77
112
|
end
|
78
|
-
|
79
|
-
|
80
|
-
|
113
|
+
|
114
|
+
context "<negative>" do
|
115
|
+
[-1, -2, -50].each do |val|
|
116
|
+
describe "#{val}" do
|
117
|
+
let(:first) { val }
|
118
|
+
test_empty self, :enum, line: __LINE__
|
119
|
+
end
|
120
|
+
end
|
81
121
|
end
|
82
|
-
|
83
|
-
|
84
|
-
|
122
|
+
|
123
|
+
describe "nil" do
|
124
|
+
let(:first) { nil }
|
125
|
+
test_empty self, :enum, line: __LINE__
|
85
126
|
end
|
86
|
-
|
87
|
-
|
88
|
-
|
127
|
+
|
128
|
+
describe "false" do
|
129
|
+
let(:first) { false }
|
130
|
+
test_empty self, :enum, line: __LINE__
|
89
131
|
end
|
90
|
-
|
91
|
-
|
92
|
-
|
132
|
+
|
133
|
+
describe "true" do
|
134
|
+
let(:first) { true }
|
135
|
+
test_error self, :enum, line: __LINE__
|
93
136
|
end
|
94
|
-
|
95
|
-
|
96
|
-
|
137
|
+
|
138
|
+
context "<illegal>" do
|
139
|
+
["hoge", "foo", "bar"].each do |val|
|
140
|
+
describe "'#{val}'" do
|
141
|
+
let(:first) { val }
|
142
|
+
test_empty self, :enum, line: __LINE__
|
143
|
+
end
|
144
|
+
end
|
97
145
|
end
|
98
146
|
end
|
99
147
|
|
100
|
-
describe "
|
101
|
-
|
102
|
-
|
103
|
-
|
148
|
+
describe "compact:" do
|
149
|
+
let(:enum) { Target.new compact: compact }
|
150
|
+
|
151
|
+
describe "true" do
|
152
|
+
let(:compact) { true }
|
153
|
+
test_empty self, :enum, line: __LINE__
|
104
154
|
end
|
105
|
-
|
106
|
-
|
107
|
-
|
155
|
+
|
156
|
+
describe "false" do
|
157
|
+
let(:compact) { false }
|
158
|
+
test_empty self, :enum, line: __LINE__
|
108
159
|
end
|
109
|
-
|
110
|
-
|
111
|
-
|
160
|
+
|
161
|
+
describe "nil" do
|
162
|
+
let(:compact) { nil }
|
163
|
+
test_empty self, :enum, line: __LINE__
|
112
164
|
end
|
113
|
-
|
114
|
-
|
115
|
-
|
165
|
+
|
166
|
+
describe "Proc.new {}" do
|
167
|
+
let(:compact) { Proc.new {} }
|
168
|
+
test_empty self, :enum, line: __LINE__
|
116
169
|
end
|
117
|
-
|
118
|
-
|
119
|
-
|
170
|
+
|
171
|
+
describe "-> {}" do
|
172
|
+
let(:compact) { -> {} }
|
173
|
+
test_empty self, :enum, line: __LINE__
|
120
174
|
end
|
121
175
|
end
|
122
|
-
end
|
123
176
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
177
|
+
describe "select:" do
|
178
|
+
let(:enum) { Target.new select: select }
|
179
|
+
|
180
|
+
describe "true" do
|
181
|
+
let(:select) { true }
|
182
|
+
test_error self, :enum, line: __LINE__
|
183
|
+
end
|
184
|
+
|
185
|
+
describe "false" do
|
186
|
+
let(:select) { false }
|
187
|
+
test_empty self, :enum, line: __LINE__
|
188
|
+
end
|
189
|
+
|
190
|
+
describe "nil" do
|
191
|
+
let(:select) { nil }
|
192
|
+
test_empty self, :enum, line: __LINE__
|
193
|
+
end
|
194
|
+
|
195
|
+
describe "Proc.new {}" do
|
196
|
+
let(:select) { Proc.new {} }
|
197
|
+
test_empty self, :enum, line: __LINE__
|
198
|
+
end
|
199
|
+
|
200
|
+
describe "-> {}" do
|
201
|
+
let(:select) { -> {} }
|
202
|
+
test_empty self, :enum, line: __LINE__
|
203
|
+
end
|
128
204
|
end
|
129
205
|
end
|
130
206
|
|
131
|
-
describe "
|
132
|
-
|
133
|
-
|
134
|
-
|
207
|
+
describe ".new []," do
|
208
|
+
|
209
|
+
describe "{}" do
|
210
|
+
let(:enum) { Target.new [], {} }
|
211
|
+
|
212
|
+
test_empty self, :enum, line: __LINE__
|
135
213
|
end
|
136
214
|
|
137
|
-
describe "
|
138
|
-
|
139
|
-
|
140
|
-
|
215
|
+
describe "first:" do
|
216
|
+
let(:enum) { Target.new [], first: first }
|
217
|
+
|
218
|
+
describe "0" do
|
219
|
+
let(:first) { 0 }
|
220
|
+
test_empty self, :enum, line: __LINE__
|
141
221
|
end
|
142
|
-
|
143
|
-
|
144
|
-
|
222
|
+
|
223
|
+
context "<positive>" do
|
224
|
+
[1, 2, 50].each do |val|
|
225
|
+
describe "#{val}" do
|
226
|
+
let(:first) { val }
|
227
|
+
test_empty self, :enum, line: __LINE__
|
228
|
+
end
|
229
|
+
end
|
145
230
|
end
|
146
|
-
end
|
147
231
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
232
|
+
context "<negative>" do
|
233
|
+
[-1, -2, -50].each do |val|
|
234
|
+
describe "#{val}" do
|
235
|
+
let(:first) { val }
|
236
|
+
test_empty self, :enum, line: __LINE__
|
237
|
+
end
|
238
|
+
end
|
155
239
|
end
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
240
|
+
|
241
|
+
describe "nil" do
|
242
|
+
let(:first) { nil }
|
243
|
+
test_empty self, :enum, line: __LINE__
|
160
244
|
end
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
245
|
+
|
246
|
+
describe "false" do
|
247
|
+
let(:first) { false }
|
248
|
+
test_empty self, :enum, line: __LINE__
|
165
249
|
end
|
166
|
-
it "Proc with no args" do
|
167
|
-
ary = (0...100).map { |e| e.odd? ? e : nil }
|
168
|
-
_proc = Proc.new { true }
|
169
|
-
enum = MergeEnum::MergeEnumerable.new ary, compact: _proc
|
170
|
-
expect(enum.count).to be 0
|
171
250
|
|
172
|
-
|
173
|
-
|
174
|
-
|
251
|
+
describe "true" do
|
252
|
+
let(:first) { true }
|
253
|
+
test_error self, :enum, line: __LINE__
|
175
254
|
end
|
176
|
-
it "Proc with args" do
|
177
|
-
ary = (0...100).map { |e| e.odd? ? e : nil }
|
178
|
-
_proc = Proc.new { |e| e.nil? }
|
179
|
-
enum = MergeEnum::MergeEnumerable.new ary, compact: _proc
|
180
|
-
expect(enum.count).to be 50
|
181
255
|
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
expect(enum.count).to be 0
|
192
|
-
_proc = -> { false }
|
193
|
-
enum = MergeEnum::MergeEnumerable.new ary, compact: _proc
|
194
|
-
expect(enum.count).to be 100
|
195
|
-
end
|
196
|
-
it "Lambda with args" do
|
197
|
-
ary = (0...100).map { |e| e.odd? ? e : nil }
|
198
|
-
_proc = -> (e) { e.nil? }
|
199
|
-
enum = MergeEnum::MergeEnumerable.new ary, compact: _proc
|
200
|
-
expect(enum.count).to be 50
|
256
|
+
context "<illegal>" do
|
257
|
+
["hoge", "foo", "bar"].each do |val|
|
258
|
+
describe "'#{val}'" do
|
259
|
+
let(:first) { val }
|
260
|
+
test_empty self, :enum, line: __LINE__
|
261
|
+
end
|
262
|
+
end
|
263
|
+
end
|
264
|
+
end
|
201
265
|
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
266
|
+
describe "compact:" do
|
267
|
+
let(:enum) { Target.new [], compact: compact }
|
268
|
+
|
269
|
+
describe "true" do
|
270
|
+
let(:compact) { true }
|
271
|
+
test_empty self, :enum, line: __LINE__
|
206
272
|
end
|
207
|
-
it "with option_first" do
|
208
|
-
ary = (0...100).map { |e| e.odd? ? e : nil }
|
209
|
-
_proc = -> (e) { e.nil? }
|
210
|
-
enum = MergeEnum::MergeEnumerable.new ary, first: 30, compact: _proc
|
211
|
-
expect(enum.count).to be 30
|
212
273
|
|
213
|
-
|
214
|
-
|
274
|
+
describe "false" do
|
275
|
+
let(:compact) { false }
|
276
|
+
test_empty self, :enum, line: __LINE__
|
215
277
|
end
|
216
|
-
end
|
217
|
-
end
|
218
278
|
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
279
|
+
describe "nil" do
|
280
|
+
let(:compact) { nil }
|
281
|
+
test_empty self, :enum, line: __LINE__
|
282
|
+
end
|
283
|
+
|
284
|
+
describe "Proc.new {}" do
|
285
|
+
let(:compact) { Proc.new {} }
|
286
|
+
test_empty self, :enum, line: __LINE__
|
287
|
+
end
|
288
|
+
|
289
|
+
describe "-> {}" do
|
290
|
+
let(:compact) { -> {} }
|
291
|
+
test_empty self, :enum, line: __LINE__
|
292
|
+
end
|
223
293
|
end
|
224
294
|
|
225
|
-
describe "
|
226
|
-
|
227
|
-
|
228
|
-
|
295
|
+
describe "select:" do
|
296
|
+
let(:enum) { Target.new select: select }
|
297
|
+
|
298
|
+
describe "true" do
|
299
|
+
let(:select) { true }
|
300
|
+
test_error self, :enum, line: __LINE__
|
229
301
|
end
|
230
|
-
|
231
|
-
|
232
|
-
|
302
|
+
|
303
|
+
describe "false" do
|
304
|
+
let(:select) { false }
|
305
|
+
test_empty self, :enum, line: __LINE__
|
306
|
+
end
|
307
|
+
|
308
|
+
describe "nil" do
|
309
|
+
let(:select) { nil }
|
310
|
+
test_empty self, :enum, line: __LINE__
|
311
|
+
end
|
312
|
+
|
313
|
+
describe "Proc.new {}" do
|
314
|
+
let(:select) { Proc.new {} }
|
315
|
+
test_empty self, :enum, line: __LINE__
|
233
316
|
end
|
234
|
-
|
235
|
-
|
236
|
-
|
317
|
+
|
318
|
+
describe "-> {}" do
|
319
|
+
let(:select) { -> {} }
|
320
|
+
test_empty self, :enum, line: __LINE__
|
237
321
|
end
|
238
322
|
end
|
239
323
|
end
|
240
324
|
|
241
|
-
describe "
|
242
|
-
|
243
|
-
|
244
|
-
|
325
|
+
describe ".new" do
|
326
|
+
let(:enum) { Target.new ary }
|
327
|
+
|
328
|
+
describe "0...100" do
|
329
|
+
let(:ary) { 0...100 }
|
330
|
+
test_all self, :enum, 0...100, line: __LINE__
|
245
331
|
end
|
332
|
+
end
|
333
|
+
|
334
|
+
describe ".new" do
|
335
|
+
let(:enum) { Target.new ary, first: first }
|
336
|
+
|
337
|
+
describe "0...100," do
|
338
|
+
let(:ary) { 0...100 }
|
339
|
+
|
340
|
+
describe "first:" do
|
341
|
+
describe "50" do
|
342
|
+
let(:first) { 50 }
|
343
|
+
test_all self, :enum, 0...50, line: __LINE__
|
344
|
+
end
|
246
345
|
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
346
|
+
describe "200" do
|
347
|
+
let(:first) { 200 }
|
348
|
+
test_all self, :enum, 0...100, line: __LINE__
|
349
|
+
end
|
350
|
+
|
351
|
+
describe "'hoge'" do
|
352
|
+
let(:first) { "hoge" }
|
353
|
+
test_all self, :enum, 0...0, line: __LINE__
|
354
|
+
end
|
355
|
+
|
356
|
+
describe "'10hoge'" do
|
357
|
+
let(:first) { "10hoge" }
|
358
|
+
test_all self, :enum, 0...10, line: __LINE__
|
359
|
+
end
|
251
360
|
end
|
252
|
-
|
253
|
-
|
254
|
-
|
361
|
+
end
|
362
|
+
end
|
363
|
+
|
364
|
+
describe ".new" do
|
365
|
+
let(:enum) { Target.new ary, compact: compact }
|
366
|
+
|
367
|
+
describe "(0...100).map { |e| e.odd? ? e : nil }," do
|
368
|
+
let(:ary) { (0...100).map { |e| e.odd? ? e : nil } }
|
369
|
+
|
370
|
+
describe "compact:" do
|
371
|
+
describe "true" do
|
372
|
+
let(:compact) { true }
|
373
|
+
test_all self, :enum, (1...100).step(2), line: __LINE__
|
374
|
+
end
|
375
|
+
|
376
|
+
describe "false" do
|
377
|
+
let(:compact) { false }
|
378
|
+
test_all self, :enum, (0...100).map { |e| e.odd? ? e : nil }, line: __LINE__
|
379
|
+
end
|
380
|
+
|
381
|
+
describe "nil" do
|
382
|
+
let(:compact) { nil }
|
383
|
+
test_all self, :enum, (0...100).map { |e| e.odd? ? e : nil }, line: __LINE__
|
384
|
+
end
|
385
|
+
|
386
|
+
describe "Proc.new { true }" do
|
387
|
+
let(:compact) { Proc.new { true } }
|
388
|
+
test_all self, :enum, [], line: __LINE__
|
389
|
+
end
|
390
|
+
|
391
|
+
describe "Proc.new { false }" do
|
392
|
+
let(:compact) { Proc.new { false } }
|
393
|
+
test_all self, :enum, (0...100).map { |e| e.odd? ? e : nil }, line: __LINE__
|
394
|
+
end
|
395
|
+
|
396
|
+
describe "Proc.new { |e| e.nil? }" do
|
397
|
+
let(:compact) { Proc.new { |e| e.nil? } }
|
398
|
+
test_all self, :enum, (1...100).step(2), line: __LINE__
|
399
|
+
end
|
400
|
+
|
401
|
+
describe "Proc.new { |e| e.nil? or e < 30 }" do
|
402
|
+
let(:compact) { Proc.new { |e| e.nil? or e < 30 } }
|
403
|
+
test_all self, :enum, (31...100).step(2), line: __LINE__
|
404
|
+
end
|
405
|
+
|
406
|
+
describe "-> { true }" do
|
407
|
+
let(:compact) { -> { true } }
|
408
|
+
test_all self, :enum, [], line: __LINE__
|
409
|
+
end
|
410
|
+
|
411
|
+
describe "-> { false }" do
|
412
|
+
let(:compact) { -> { false } }
|
413
|
+
test_all self, :enum, (0...100).map { |e| e.odd? ? e : nil }, line: __LINE__
|
414
|
+
end
|
415
|
+
|
416
|
+
describe "-> (e) { e.nil? }" do
|
417
|
+
let(:compact) { -> (e) { e.nil? } }
|
418
|
+
test_all self, :enum, (1...100).step(2), line: __LINE__
|
419
|
+
end
|
420
|
+
|
421
|
+
describe "-> (e) { e.nil? or e < 30 }" do
|
422
|
+
let(:compact) { -> (e) { e.nil? or e < 30 } }
|
423
|
+
test_all self, :enum, (31...100).step(2), line: __LINE__
|
424
|
+
end
|
255
425
|
end
|
256
|
-
|
257
|
-
|
258
|
-
|
426
|
+
end
|
427
|
+
end
|
428
|
+
|
429
|
+
describe ".new" do
|
430
|
+
let(:enum) { Target.new ary, compact: compact, first: first }
|
431
|
+
describe "(0...100).map { |e| e.odd? ? e : nil }," do
|
432
|
+
let(:ary) { (0...100).map { |e| e.odd? ? e : nil } }
|
433
|
+
describe "compact:" do
|
434
|
+
describe "-> (e) { e.nil? }," do
|
435
|
+
let(:compact) { -> (e) { e.nil? } }
|
436
|
+
|
437
|
+
describe "first:" do
|
438
|
+
describe "30" do
|
439
|
+
let(:first) { 30 }
|
440
|
+
test_all self, :enum, (1...60).step(2), line: __LINE__
|
441
|
+
end
|
442
|
+
|
443
|
+
describe "60" do
|
444
|
+
let(:first) { 60 }
|
445
|
+
test_all self, :enum, (1...100).step(2), line: __LINE__
|
446
|
+
end
|
447
|
+
end
|
448
|
+
end
|
259
449
|
end
|
260
|
-
|
261
|
-
|
262
|
-
|
450
|
+
end
|
451
|
+
end
|
452
|
+
|
453
|
+
describe ".new" do
|
454
|
+
let(:enum) { Target.new ary, select: select }
|
455
|
+
|
456
|
+
describe "(0...100).map { |e| e.odd? ? e : nil }," do
|
457
|
+
let(:ary) { (0...100).map { |e| e.odd? ? e : nil } }
|
458
|
+
|
459
|
+
describe "select:" do
|
460
|
+
describe "nil" do
|
461
|
+
let(:select) { nil }
|
462
|
+
test_all self, :enum, (0...100).map { |e| e.odd? ? e : nil }, line: __LINE__
|
463
|
+
end
|
464
|
+
|
465
|
+
describe "Proc.new { true }" do
|
466
|
+
let(:select) { Proc.new { true } }
|
467
|
+
test_all self, :enum, (0...100).map { |e| e.odd? ? e : nil }, line: __LINE__
|
468
|
+
end
|
469
|
+
|
470
|
+
describe "Proc.new { false }" do
|
471
|
+
let(:select) { Proc.new { false } }
|
472
|
+
test_all self, :enum, [], line: __LINE__
|
473
|
+
end
|
474
|
+
|
475
|
+
describe "Proc.new { |e| e.nil? }" do
|
476
|
+
let(:select) { Proc.new { |e| e.nil? } }
|
477
|
+
test_all self, :enum, Array.new(50, nil), line: __LINE__
|
478
|
+
end
|
479
|
+
|
480
|
+
describe "Proc.new { |e| not e.nil? and e < 30 }" do
|
481
|
+
let(:select) { Proc.new { |e| not e.nil? and e < 30 } }
|
482
|
+
test_all self, :enum, (1...30).step(2), line: __LINE__
|
483
|
+
end
|
484
|
+
|
485
|
+
describe "-> { true }" do
|
486
|
+
let(:select) { -> { true } }
|
487
|
+
test_all self, :enum, (0...100).map { |e| e.odd? ? e : nil }, line: __LINE__
|
488
|
+
end
|
489
|
+
|
490
|
+
describe "-> { false }" do
|
491
|
+
let(:select) { -> { false } }
|
492
|
+
test_all self, :enum, [], line: __LINE__
|
493
|
+
end
|
494
|
+
|
495
|
+
describe "-> (e) { e.nil? }" do
|
496
|
+
let(:select) { -> (e) { e.nil? } }
|
497
|
+
test_all self, :enum, Array.new(50, nil), line: __LINE__
|
498
|
+
end
|
499
|
+
|
500
|
+
describe "-> (e) { not e.nil? and e < 30 }" do
|
501
|
+
let(:select) { -> (e) { not e.nil? and e < 30 } }
|
502
|
+
test_all self, :enum, (1...30).step(2), line: __LINE__
|
503
|
+
end
|
263
504
|
end
|
264
505
|
end
|
265
506
|
end
|
266
507
|
|
267
|
-
describe "
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
508
|
+
describe ".new" do
|
509
|
+
let(:enum) { Target.new ary, select: select, first: first }
|
510
|
+
describe "(0...100).map { |e| e.odd? ? e : nil }," do
|
511
|
+
let(:ary) { (0...100).map { |e| e.odd? ? e : nil } }
|
512
|
+
describe "select:" do
|
513
|
+
describe "-> (e) { e.nil? }," do
|
514
|
+
let(:select) { -> (e) { e.nil? } }
|
515
|
+
|
516
|
+
describe "first:" do
|
517
|
+
describe "30" do
|
518
|
+
let(:first) { 30 }
|
519
|
+
test_all self, :enum, Array.new(30, nil), line: __LINE__
|
520
|
+
end
|
521
|
+
|
522
|
+
describe "60" do
|
523
|
+
let(:first) { 60 }
|
524
|
+
test_all self, :enum, Array.new(50, nil), line: __LINE__
|
525
|
+
end
|
526
|
+
end
|
527
|
+
end
|
284
528
|
end
|
285
529
|
end
|
286
530
|
end
|
287
531
|
|
288
|
-
describe "
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
enum = MergeEnum::MergeEnumerable.new(
|
304
|
-
-> (c) { arg1 = c; 0...100 },
|
305
|
-
-> (c) { arg2 = c; 200...250 },
|
306
|
-
first: 200
|
307
|
-
)
|
308
|
-
expect(enum.count).to be 150
|
309
|
-
expect(arg1).to be 200
|
310
|
-
expect(arg2).to be 100
|
532
|
+
describe ".new" do
|
533
|
+
let(:enum) { Target.new ary, compact: compact, select: select }
|
534
|
+
describe "(0...100).map { |e| e.odd? ? e : nil }," do
|
535
|
+
let(:ary) { (0...100).map { |e| e.odd? ? e : nil } }
|
536
|
+
describe "compact:" do
|
537
|
+
describe "true," do
|
538
|
+
let(:compact) { true }
|
539
|
+
|
540
|
+
describe "select:" do
|
541
|
+
describe "Proc.new { |e| e.to_i < 30 }" do
|
542
|
+
let(:select) { Proc.new{ |e| e.to_i < 30 } }
|
543
|
+
test_all self, :enum, (1...30).step(2), line: __LINE__
|
544
|
+
end
|
545
|
+
end
|
546
|
+
end
|
311
547
|
end
|
312
548
|
end
|
313
549
|
end
|
314
550
|
|
315
|
-
describe "
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
551
|
+
describe ".new" do
|
552
|
+
let(:enum) { Target.new ary1, ary2 }
|
553
|
+
describe "0...100, 200...250" do
|
554
|
+
let(:ary1) { 0...100 }
|
555
|
+
let(:ary2) { 200...250 }
|
556
|
+
test_all self, :enum, (0...100).to_a + (200...250).to_a, line: __LINE__
|
557
|
+
end
|
558
|
+
end
|
559
|
+
|
560
|
+
describe ".new" do
|
561
|
+
let(:enum) { Target.new ary1, ary2, first: first }
|
562
|
+
describe "0...100, 200...250," do
|
563
|
+
let(:ary1) { 0...100 }
|
564
|
+
let(:ary2) { 200...250 }
|
565
|
+
|
566
|
+
describe "first:" do
|
567
|
+
describe "50" do
|
568
|
+
let(:first) { 50 }
|
569
|
+
test_all self, :enum, 0...50, line: __LINE__
|
570
|
+
end
|
571
|
+
|
572
|
+
describe "130" do
|
573
|
+
let(:first) { 130 }
|
574
|
+
test_all self, :enum, (0...100).to_a + (200...230).to_a, line: __LINE__
|
575
|
+
end
|
576
|
+
|
577
|
+
describe "200" do
|
578
|
+
let(:first) { 200 }
|
579
|
+
test_all self, :enum, (0...100).to_a + (200...250).to_a, line: __LINE__
|
580
|
+
end
|
581
|
+
end
|
582
|
+
end
|
583
|
+
|
584
|
+
describe "Proc.new { 0...100 }, Proc.new { 200...250 }," do
|
585
|
+
let(:ary1) { Proc.new { 0...100 } }
|
586
|
+
let(:ary2) { Proc.new { 200...250 } }
|
587
|
+
|
588
|
+
describe "first:" do
|
589
|
+
describe "50" do
|
590
|
+
let(:first) { 50 }
|
591
|
+
test_all self, :enum, 0...50, line: __LINE__
|
592
|
+
end
|
593
|
+
|
594
|
+
describe "130" do
|
595
|
+
let(:first) { 130 }
|
596
|
+
test_all self, :enum, (0...100).to_a + (200...230).to_a, line: __LINE__
|
597
|
+
end
|
598
|
+
|
599
|
+
describe "200" do
|
600
|
+
let(:first) { 200 }
|
601
|
+
test_all self, :enum, (0...100).to_a + (200...250).to_a, line: __LINE__
|
602
|
+
end
|
603
|
+
end
|
604
|
+
end
|
605
|
+
|
606
|
+
describe "Proc.new { |c| 0...100 }, Proc.new { |c| 200...250 }," do
|
607
|
+
describe "first:" do
|
608
|
+
describe "50" do
|
609
|
+
let(:ary1) {
|
610
|
+
ary = Proc.new { |c| 0...100 }
|
611
|
+
expect(ary).to receive(:call).once.with(50).and_return(0...100)
|
612
|
+
ary
|
613
|
+
}
|
614
|
+
let(:ary2) {
|
615
|
+
ary = Proc.new { |c| 200...250 }
|
616
|
+
expect(ary).to receive(:call).never
|
617
|
+
ary
|
618
|
+
}
|
619
|
+
let(:first) { 50 }
|
620
|
+
test_all self, :enum, 0...50, line: __LINE__
|
621
|
+
end
|
622
|
+
|
623
|
+
describe "130" do
|
624
|
+
let(:ary1) {
|
625
|
+
ary = Proc.new { |c| 0...100 }
|
626
|
+
expect(ary).to receive(:call).once.with(130).and_return(0...100)
|
627
|
+
ary
|
628
|
+
}
|
629
|
+
let(:first) { 130 }
|
630
|
+
|
631
|
+
context "<all>" do
|
632
|
+
let(:ary2) {
|
633
|
+
ary = Proc.new { |c| 200...250 }
|
634
|
+
expect(ary).to receive(:call).once.with(30).and_return(200...250)
|
635
|
+
ary
|
636
|
+
}
|
637
|
+
test_equal self, :enum, (0...100).to_a + (200...230).to_a, line: __LINE__
|
638
|
+
end
|
639
|
+
|
640
|
+
context "<interrupt>" do
|
641
|
+
let(:ary2) {
|
642
|
+
ary = Proc.new { |c| 200...250 }
|
643
|
+
expect(ary).to receive(:call).never
|
644
|
+
ary
|
645
|
+
}
|
646
|
+
test_interrupt self, :enum, (0...100).to_a + (200...230).to_a, line: __LINE__
|
647
|
+
end
|
648
|
+
end
|
649
|
+
|
650
|
+
describe "200" do
|
651
|
+
let(:ary1) {
|
652
|
+
ary = Proc.new { |c| 0...100 }
|
653
|
+
expect(ary).to receive(:call).once.with(200).and_return(0...100)
|
654
|
+
ary
|
655
|
+
}
|
656
|
+
let(:ary2) { Proc.new { |c| 200...250 } }
|
657
|
+
let(:first) { 200 }
|
658
|
+
test_all self, :enum, (0...100).to_a + (200...250).to_a, line: __LINE__
|
659
|
+
end
|
660
|
+
end
|
661
|
+
end
|
662
|
+
|
663
|
+
describe "-> { 0...100 }, -> { 200...250 }," do
|
664
|
+
let(:ary1) { -> { 0...100 } }
|
665
|
+
let(:ary2) { -> { 200...250 } }
|
666
|
+
|
667
|
+
describe "first:" do
|
668
|
+
describe "50" do
|
669
|
+
let(:first) { 50 }
|
670
|
+
test_all self, :enum, 0...50, line: __LINE__
|
671
|
+
end
|
672
|
+
|
673
|
+
describe "130" do
|
674
|
+
let(:first) { 130 }
|
675
|
+
test_all self, :enum, (0...100).to_a + (200...230).to_a, line: __LINE__
|
676
|
+
end
|
677
|
+
|
678
|
+
describe "200" do
|
679
|
+
let(:first) { 200 }
|
680
|
+
test_all self, :enum, (0...100).to_a + (200...250).to_a, line: __LINE__
|
681
|
+
end
|
682
|
+
end
|
683
|
+
end
|
684
|
+
|
685
|
+
describe "-> (c) { 0...100 }, -> (c) { 200...250 }," do
|
686
|
+
describe "first:" do
|
687
|
+
describe "50" do
|
688
|
+
let(:ary1) {
|
689
|
+
ary = -> (c) { 0...100 }
|
690
|
+
expect(ary).to receive(:call).once.with(50).and_return(0...100)
|
691
|
+
ary
|
692
|
+
}
|
693
|
+
let(:ary2) {
|
694
|
+
ary = -> (c) { 200...250 }
|
695
|
+
expect(ary).to receive(:call).never
|
696
|
+
ary
|
697
|
+
}
|
698
|
+
let(:first) { 50 }
|
699
|
+
test_all self, :enum, 0...50, line: __LINE__
|
700
|
+
end
|
701
|
+
|
702
|
+
describe "130" do
|
703
|
+
let(:ary1) {
|
704
|
+
ary = -> (c) { 0...100 }
|
705
|
+
expect(ary).to receive(:call).once.with(130).and_return(0...100)
|
706
|
+
ary
|
707
|
+
}
|
708
|
+
let(:first) { 130 }
|
709
|
+
|
710
|
+
context "<all>" do
|
711
|
+
let(:ary2) {
|
712
|
+
ary = -> (c) { 200...250 }
|
713
|
+
expect(ary).to receive(:call).once.with(30).and_return(200...250)
|
714
|
+
ary
|
715
|
+
}
|
716
|
+
test_equal self, :enum, (0...100).to_a + (200...230).to_a, line: __LINE__
|
717
|
+
end
|
718
|
+
|
719
|
+
context "<interrupt>" do
|
720
|
+
let(:ary2) {
|
721
|
+
ary = -> (c) { 200...250 }
|
722
|
+
expect(ary).to receive(:call).never
|
723
|
+
ary
|
724
|
+
}
|
725
|
+
test_interrupt self, :enum, (0...100).to_a + (200...230).to_a, line: __LINE__
|
726
|
+
end
|
727
|
+
end
|
728
|
+
|
729
|
+
describe "200" do
|
730
|
+
let(:ary1) {
|
731
|
+
ary = -> (c) { 0...100 }
|
732
|
+
expect(ary).to receive(:call).once.with(200).and_return(0...100)
|
733
|
+
ary
|
734
|
+
}
|
735
|
+
let(:ary2) { -> (c) { 200...250 } }
|
736
|
+
let(:first) { 200 }
|
737
|
+
test_all self, :enum, (0...100).to_a + (200...250).to_a, line: __LINE__
|
738
|
+
end
|
332
739
|
end
|
333
740
|
end
|
334
741
|
end
|
335
742
|
|
336
|
-
describe "
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
743
|
+
describe ".new" do
|
744
|
+
let(:enum) { Target.new ary1, ary2, ary3 }
|
745
|
+
describe "0...100, 200...250, 300...330" do
|
746
|
+
let(:ary1) { 0...100 }
|
747
|
+
let(:ary2) { 200...250 }
|
748
|
+
let(:ary3) { 300...330 }
|
749
|
+
test_all self, :enum, (0...100).to_a + (200...250).to_a + (300...330).to_a, line: __LINE__
|
750
|
+
end
|
751
|
+
end
|
752
|
+
|
753
|
+
describe ".new" do
|
754
|
+
let(:enum) { Target.new ary1, ary2, ary3, first: first }
|
755
|
+
describe "0...100, 200...250, 300...330," do
|
756
|
+
let(:ary1) { 0...100 }
|
757
|
+
let(:ary2) { 200...250 }
|
758
|
+
let(:ary3) { 300...330 }
|
759
|
+
|
760
|
+
describe "first:" do
|
761
|
+
describe "50" do
|
762
|
+
let(:first) { 50 }
|
763
|
+
test_all self, :enum, 0...50, line: __LINE__
|
764
|
+
end
|
765
|
+
|
766
|
+
describe "130" do
|
767
|
+
let(:first) { 130 }
|
768
|
+
test_all self, :enum, (0...100).to_a + (200...230).to_a, line: __LINE__
|
769
|
+
end
|
770
|
+
|
771
|
+
describe "170" do
|
772
|
+
let(:first) { 170 }
|
773
|
+
test_all self, :enum, (0...100).to_a + (200...250).to_a + (300...320).to_a, line: __LINE__
|
774
|
+
end
|
775
|
+
|
776
|
+
describe "200" do
|
777
|
+
let(:first) { 200 }
|
778
|
+
test_all self, :enum, (0...100).to_a + (200...250).to_a + (300...330).to_a, line: __LINE__
|
779
|
+
end
|
359
780
|
end
|
360
781
|
end
|
361
782
|
end
|
362
783
|
|
363
|
-
describe "
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
784
|
+
describe ".new" do
|
785
|
+
let(:enum) { Target.new ary1, ary2, ary3, first: first }
|
786
|
+
describe "Proc.new { |c| 0...100 }, Proc.new { |c| 200...250 }, Proc.new { |c| 300...330 }," do
|
787
|
+
describe "first:" do
|
788
|
+
describe "50" do
|
789
|
+
let(:ary1) {
|
790
|
+
ary = Proc.new { |c| 0...100 }
|
791
|
+
expect(ary).to receive(:call).once.with(50).and_return(0...100)
|
792
|
+
ary
|
793
|
+
}
|
794
|
+
let(:ary2) {
|
795
|
+
ary = Proc.new { |c| 200...250 }
|
796
|
+
expect(ary).to receive(:call).never
|
797
|
+
ary
|
798
|
+
}
|
799
|
+
let(:ary3) {
|
800
|
+
ary = Proc.new { |c| 300...330 }
|
801
|
+
expect(ary).to receive(:call).never
|
802
|
+
ary
|
803
|
+
}
|
804
|
+
let(:first) { 50 }
|
805
|
+
test_all self, :enum, 0...50, line: __LINE__
|
806
|
+
end
|
807
|
+
|
808
|
+
describe "130" do
|
809
|
+
let(:ary1) {
|
810
|
+
ary = Proc.new { |c| 0...100 }
|
811
|
+
allow(ary).to receive(:call).once.with(130).and_return 0...100
|
812
|
+
ary
|
813
|
+
}
|
814
|
+
let(:first) { 130 }
|
815
|
+
|
816
|
+
context "<all>" do
|
817
|
+
let(:ary2) {
|
818
|
+
ary = Proc.new { |c| 200...250 }
|
819
|
+
allow(ary).to receive(:call).once.with(30).and_return 200...250
|
820
|
+
ary
|
821
|
+
}
|
822
|
+
let(:ary3) {
|
823
|
+
ary = Proc.new { |c| 300...330 }
|
824
|
+
allow(ary).to receive(:call).never
|
825
|
+
ary
|
826
|
+
}
|
827
|
+
test_equal self, :enum, (0...100).to_a + (200...230).to_a, line: __LINE__
|
828
|
+
end
|
829
|
+
|
830
|
+
context "<interrupt>" do
|
831
|
+
let(:ary2) {
|
832
|
+
ary = Proc.new { |c| 200...250 }
|
833
|
+
allow(ary).to receive(:call).never
|
834
|
+
ary
|
835
|
+
}
|
836
|
+
let(:ary3) {
|
837
|
+
ary = Proc.new { |c| 300...330 }
|
838
|
+
allow(ary).to receive(:call).never
|
839
|
+
ary
|
840
|
+
}
|
841
|
+
test_interrupt self, :enum, (0...100).to_a + (200...230).to_a, line: __LINE__
|
842
|
+
end
|
843
|
+
end
|
844
|
+
|
845
|
+
describe "200" do
|
846
|
+
let(:ary1) {
|
847
|
+
ary = Proc.new { |c| 0...100 }
|
848
|
+
allow(ary).to receive(:call).once.with(200).and_return 0...100
|
849
|
+
ary
|
850
|
+
}
|
851
|
+
let(:first) { 200 }
|
852
|
+
|
853
|
+
context "<all>" do
|
854
|
+
let(:ary2) {
|
855
|
+
ary = Proc.new { |c| 200...250 }
|
856
|
+
allow(ary).to receive(:call).once.with(100).and_return 200...250
|
857
|
+
ary
|
858
|
+
}
|
859
|
+
let(:ary3) {
|
860
|
+
ary = Proc.new { |c| 300...330 }
|
861
|
+
allow(ary).to receive(:call).once.with(50).and_return 300...330
|
862
|
+
ary
|
863
|
+
}
|
864
|
+
test_equal self, :enum, (0...100).to_a + (200...250).to_a + (300...330).to_a, line: __LINE__
|
865
|
+
end
|
866
|
+
|
867
|
+
context "<interrupt>" do
|
868
|
+
let(:ary2) {
|
869
|
+
ary = Proc.new { |c| 200...250 }
|
870
|
+
allow(ary).to receive(:call).never
|
871
|
+
ary
|
872
|
+
}
|
873
|
+
let(:ary3) {
|
874
|
+
ary = Proc.new { |c| 300...330 }
|
875
|
+
allow(ary).to receive(:call).never
|
876
|
+
ary
|
877
|
+
}
|
878
|
+
test_interrupt self, :enum, (0...100).to_a + (200...250).to_a + (300...330).to_a, line: __LINE__
|
879
|
+
end
|
880
|
+
end
|
881
|
+
end
|
387
882
|
end
|
388
883
|
end
|
389
884
|
|
390
|
-
describe "
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
885
|
+
describe ".new" do
|
886
|
+
let(:enum) { Target.new ary1, ary2, ary3, first: first }
|
887
|
+
describe "0...100, Proc.new { 200...250 }, -> (c) { 300...330 }," do
|
888
|
+
describe "first:" do
|
889
|
+
describe "50" do
|
890
|
+
let(:ary1) { 0...100 }
|
891
|
+
let(:ary2) {
|
892
|
+
ary = Proc.new { |c| 200...250 }
|
893
|
+
allow(ary).to receive(:call).never
|
894
|
+
ary
|
895
|
+
}
|
896
|
+
let(:ary3) {
|
897
|
+
ary = -> (c) { 300...330 }
|
898
|
+
allow(ary).to receive(:call).never
|
899
|
+
ary
|
900
|
+
}
|
901
|
+
let (:first) { 50 }
|
902
|
+
test_all self, :enum, 0...50, line: __LINE__
|
903
|
+
end
|
904
|
+
|
905
|
+
describe "130" do
|
906
|
+
let(:ary1) { 0...100 }
|
907
|
+
let (:first) { 130 }
|
908
|
+
|
909
|
+
context "<all>" do
|
910
|
+
let(:ary2) {
|
911
|
+
ary = Proc.new { |c| 200...250 }
|
912
|
+
allow(ary).to receive(:call).once.with(30).and_return 200...250
|
913
|
+
ary
|
914
|
+
}
|
915
|
+
let(:ary3) {
|
916
|
+
ary = -> (c) { 300...330 }
|
917
|
+
allow(ary).to receive(:call).never
|
918
|
+
ary
|
919
|
+
}
|
920
|
+
test_equal self, :enum, (0...100).to_a + (200...230).to_a, line: __LINE__
|
921
|
+
end
|
922
|
+
|
923
|
+
context "<interrupt>" do
|
924
|
+
let(:ary2) {
|
925
|
+
ary = Proc.new { |c| 200...250 }
|
926
|
+
allow(ary).to receive(:call).never
|
927
|
+
ary
|
928
|
+
}
|
929
|
+
let(:ary3) {
|
930
|
+
ary = -> (c) { 300...330 }
|
931
|
+
allow(ary).to receive(:call).never
|
932
|
+
ary
|
933
|
+
}
|
934
|
+
test_interrupt self, :enum, (0...100).to_a + (200...230).to_a, line: __LINE__
|
935
|
+
end
|
936
|
+
end
|
937
|
+
|
938
|
+
describe "200" do
|
939
|
+
let(:ary1) { 0...100 }
|
940
|
+
let (:first) { 200 }
|
941
|
+
|
942
|
+
context "<all>" do
|
943
|
+
let(:ary2) {
|
944
|
+
ary = Proc.new { |c| 200...250 }
|
945
|
+
allow(ary).to receive(:call).once.with(100).and_return 200...250
|
946
|
+
ary
|
947
|
+
}
|
948
|
+
let(:ary3) {
|
949
|
+
ary = -> (c) { 300...330 }
|
950
|
+
allow(ary).to receive(:call).once.with(50).and_return 300...330
|
951
|
+
ary
|
952
|
+
}
|
953
|
+
test_equal self, :enum, (0...100).to_a + (200...250).to_a + (300...330).to_a, line: __LINE__
|
954
|
+
end
|
955
|
+
|
956
|
+
context "<interrupt>" do
|
957
|
+
let(:ary2) {
|
958
|
+
ary = Proc.new { |c| 200...250 }
|
959
|
+
allow(ary).to receive(:call).never
|
960
|
+
ary
|
961
|
+
}
|
962
|
+
let(:ary3) {
|
963
|
+
ary = -> (c) { 300...330 }
|
964
|
+
allow(ary).to receive(:call).never
|
965
|
+
ary
|
966
|
+
}
|
967
|
+
test_interrupt self, :enum, (0...100).to_a + (200...250).to_a + (300...330).to_a, line: __LINE__
|
968
|
+
end
|
969
|
+
end
|
970
|
+
end
|
403
971
|
end
|
404
972
|
end
|
405
973
|
|
406
|
-
describe "
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
ary = 0...100
|
424
|
-
allow(ary).to receive(:first).and_raise("unexpect")
|
425
|
-
enum = MergeEnum::MergeEnumerable.new ary, first: 10, compact: true
|
426
|
-
expect(enum.count).to be 10
|
974
|
+
describe ".new" do
|
975
|
+
describe "0...100, Proc.new { 200...250 }, -> (c) { 300...330 }, first: 200" do
|
976
|
+
let(:enum) { Target.new 0...100, Proc.new { 200...250 }, -> (c) { 300...330 }, first: 200 }
|
977
|
+
context "<is_a?>" do
|
978
|
+
it { expect(enum).to be_a Enumerable }
|
979
|
+
end
|
980
|
+
context "#each <is_a?>" do
|
981
|
+
subject { enum.each }
|
982
|
+
it { is_expected.to be_a Enumerable }
|
983
|
+
it { is_expected.not_to be_a Array }
|
984
|
+
it { is_expected.not_to be enum }
|
985
|
+
end
|
986
|
+
context "#each#to_a <is_a?>" do
|
987
|
+
subject { enum.each.to_a }
|
988
|
+
it { is_expected.to be_a Array }
|
989
|
+
it { is_expected.to eq enum.to_a }
|
990
|
+
end
|
427
991
|
end
|
428
992
|
end
|
429
993
|
|
430
|
-
describe "
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
)
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
994
|
+
describe ".new" do
|
995
|
+
let(:enum) { Target.new ary1, ary2, ary3, first: 200 }
|
996
|
+
describe "0...100, Proc.new { 200...250 }, -> { 300...330 }, first: 200" do
|
997
|
+
let(:ary1) {
|
998
|
+
ary = 0...100
|
999
|
+
allow(ary).to receive(:first).with(200) { |c| (0...100).first c }
|
1000
|
+
ary
|
1001
|
+
}
|
1002
|
+
let(:ary2) {
|
1003
|
+
ary = 200...250
|
1004
|
+
_proc = Proc.new { ary }
|
1005
|
+
allow(_proc).to receive(:call).with(no_args).and_return ary
|
1006
|
+
allow(ary).to receive(:first).with(100) { |c| (200...250).first c }
|
1007
|
+
_proc
|
1008
|
+
}
|
1009
|
+
let(:ary3) {
|
1010
|
+
ary = 300...330
|
1011
|
+
_proc = -> { ary }
|
1012
|
+
allow(_proc).to receive(:call).with(no_args).and_return ary
|
1013
|
+
allow(ary).to receive(:first).with(50) { |c| (300...330).first c }
|
1014
|
+
_proc
|
1015
|
+
}
|
1016
|
+
|
1017
|
+
context "<whitebox>" do
|
1018
|
+
test_equal self, :enum, (0...100).to_a + (200...250).to_a + (300...330).to_a, line: __LINE__
|
1019
|
+
end
|
1020
|
+
end
|
1021
|
+
|
1022
|
+
describe "0...100, Proc.new { |c| 200...250 }, -> (c) { 300...330 }, first: 200" do
|
1023
|
+
let(:ary1) {
|
1024
|
+
ary = 0...100
|
1025
|
+
allow(ary).to receive(:first).with(200).and_return 0...100
|
1026
|
+
ary
|
1027
|
+
}
|
1028
|
+
let(:ary2) {
|
1029
|
+
ary = 200...250
|
1030
|
+
_proc = Proc.new { |c| ary }
|
1031
|
+
allow(_proc).to receive(:call).with(100).and_return ary
|
1032
|
+
allow(ary).to receive(:first).never
|
1033
|
+
_proc
|
1034
|
+
}
|
1035
|
+
let(:ary3) {
|
1036
|
+
ary = 300...330
|
1037
|
+
_proc = -> (c) { ary }
|
1038
|
+
allow(_proc).to receive(:call).with(50).and_return ary
|
1039
|
+
allow(ary).to receive(:first).never
|
1040
|
+
_proc
|
1041
|
+
}
|
1042
|
+
|
1043
|
+
context "<whitebox>" do
|
1044
|
+
test_equal self, :enum, (0...100).to_a + (200...250).to_a + (300...330).to_a, line: __LINE__
|
1045
|
+
end
|
446
1046
|
end
|
447
1047
|
end
|
448
1048
|
|
449
|
-
describe "
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
1049
|
+
describe ".new" do
|
1050
|
+
describe "0...100, Proc.new { |c| 200...250 }, first: 160" do
|
1051
|
+
let(:enum) { Target.new 0...100, Proc.new { |c| 200...250 }, first: 160 }
|
1052
|
+
it { expect(enum).to be enum }
|
1053
|
+
|
1054
|
+
context "#concat -> (c) { 300...330 }" do
|
1055
|
+
it { expect(enum.concat []).not_to be enum }
|
1056
|
+
it { expect(enum.concat([]).to_a).to eq enum.to_a }
|
1057
|
+
|
1058
|
+
let(:ary) { -> (c) { 300...330 } }
|
1059
|
+
|
1060
|
+
subject { enum.concat(ary).to_a }
|
1061
|
+
it { is_expected.to eq (0...100).to_a + (200...250).to_a + (300...310).to_a }
|
1062
|
+
end
|
1063
|
+
|
1064
|
+
context "#concat! -> (c) { 300...330 }" do
|
1065
|
+
it { expect(enum.concat! [1, 2, 3]).to eq enum }
|
1066
|
+
|
1067
|
+
let(:ary) { -> (c) { 300...330 } }
|
1068
|
+
|
1069
|
+
subject { enum.concat!(ary).to_a }
|
1070
|
+
it { is_expected.to eq (0...100).to_a + (200...250).to_a + (300...310).to_a }
|
1071
|
+
end
|
470
1072
|
end
|
471
1073
|
end
|
472
1074
|
|