astrolabe 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/astrolabe/node.rb +4 -4
- data/lib/astrolabe/version.rb +1 -1
- data/spec/astrolabe/node_spec.rb +117 -100
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1306bd1680b44a33bad44374f71f0254be88dd30
|
4
|
+
data.tar.gz: f49d728a8cde1724e8c312475bcd8dad607c4eb6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47f5e3637d1d87069147a9d1f574ae36d853ce942fa1f3a44330430184519639490aa28c0e6c5c81e8a126ec3dbef1152eb754209c1bc2bbf35c0a2cff69f234
|
7
|
+
data.tar.gz: 10468278e65896eb7d8a641fbe57789823a7a11bb91e89b8b34f976037b0ae3f7e6c9066e1bf583223123c23430f9143c6eb874ba95e01621b1f5e8ab4bc9d18
|
data/lib/astrolabe/node.rb
CHANGED
@@ -82,7 +82,7 @@ module Astrolabe
|
|
82
82
|
# @return [self] if a block is given
|
83
83
|
# @return [Enumerator] if no block is given
|
84
84
|
def each_ancestor(*types)
|
85
|
-
return to_enum(__method__) unless block_given?
|
85
|
+
return to_enum(__method__, *types) unless block_given?
|
86
86
|
|
87
87
|
types.flatten!
|
88
88
|
last_node = self
|
@@ -117,7 +117,7 @@ module Astrolabe
|
|
117
117
|
# @return [self] if a block is given
|
118
118
|
# @return [Enumerator] if no block is given
|
119
119
|
def each_child_node(*types)
|
120
|
-
return to_enum(__method__) unless block_given?
|
120
|
+
return to_enum(__method__, *types) unless block_given?
|
121
121
|
|
122
122
|
types.flatten!
|
123
123
|
|
@@ -148,7 +148,7 @@ module Astrolabe
|
|
148
148
|
# @return [self] if a block is given
|
149
149
|
# @return [Enumerator] if no block is given
|
150
150
|
def each_descendant(*types, &block)
|
151
|
-
return to_enum(__method__) unless block_given?
|
151
|
+
return to_enum(__method__, *types) unless block_given?
|
152
152
|
types.flatten!
|
153
153
|
visit_descendants(types, &block)
|
154
154
|
self
|
@@ -176,7 +176,7 @@ module Astrolabe
|
|
176
176
|
# @return [self] if a block is given
|
177
177
|
# @return [Enumerator] if no block is given
|
178
178
|
def each_node(*types, &block)
|
179
|
-
return to_enum(__method__) unless block_given?
|
179
|
+
return to_enum(__method__, *types) unless block_given?
|
180
180
|
types.flatten!
|
181
181
|
yield self if types.empty? || types.include?(type)
|
182
182
|
visit_descendants(types, &block)
|
data/lib/astrolabe/version.rb
CHANGED
data/spec/astrolabe/node_spec.rb
CHANGED
@@ -68,6 +68,23 @@ module Astrolabe
|
|
68
68
|
|
69
69
|
expect { enumerator.next }.to raise_error(StopIteration)
|
70
70
|
end
|
71
|
+
|
72
|
+
context 'when a node type symbol is passed' do
|
73
|
+
subject(:enumerator) { target_node.send(method_name, :send) }
|
74
|
+
|
75
|
+
it 'enumerates only nodes matching the type' do
|
76
|
+
count = 0
|
77
|
+
|
78
|
+
begin
|
79
|
+
loop do
|
80
|
+
expect(enumerator.next.type).to eq(:send)
|
81
|
+
count += 1
|
82
|
+
end
|
83
|
+
rescue StopIteration
|
84
|
+
expect(count).to be > 0
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
71
88
|
end
|
72
89
|
end
|
73
90
|
end
|
@@ -112,45 +129,45 @@ module Astrolabe
|
|
112
129
|
returned_value = target_node.each_ancestor {}
|
113
130
|
expect(returned_value).to equal(target_node)
|
114
131
|
end
|
115
|
-
end
|
116
132
|
|
117
|
-
|
133
|
+
context 'and a node type symbol is passed' do
|
134
|
+
it 'scans all the ancestor nodes but yields only nodes matching the type' do
|
135
|
+
yielded_types = []
|
118
136
|
|
119
|
-
|
120
|
-
|
121
|
-
|
137
|
+
target_node.each_ancestor(:begin) do |node|
|
138
|
+
yielded_types << node.type
|
139
|
+
end
|
122
140
|
|
123
|
-
|
124
|
-
yielded_types << node.type
|
141
|
+
expect(yielded_types).to eq([:begin])
|
125
142
|
end
|
126
|
-
|
127
|
-
expect(yielded_types).to eq([:begin])
|
128
143
|
end
|
129
|
-
end
|
130
144
|
|
131
|
-
|
132
|
-
|
133
|
-
|
145
|
+
context 'and multiple node type symbols are passed' do
|
146
|
+
it 'scans all the ancestor nodes but yields only nodes matching any of the types' do
|
147
|
+
yielded_types = []
|
134
148
|
|
135
|
-
|
136
|
-
|
137
|
-
|
149
|
+
target_node.each_ancestor(:begin, :def) do |node|
|
150
|
+
yielded_types << node.type
|
151
|
+
end
|
138
152
|
|
139
|
-
|
153
|
+
expect(yielded_types).to eq([:def, :begin])
|
154
|
+
end
|
140
155
|
end
|
141
|
-
end
|
142
156
|
|
143
|
-
|
144
|
-
|
145
|
-
|
157
|
+
context 'and an array including type symbols are passed' do
|
158
|
+
it 'scans all the ancestor nodes but yields only nodes matching any of the types' do
|
159
|
+
yielded_types = []
|
146
160
|
|
147
|
-
|
148
|
-
|
149
|
-
|
161
|
+
target_node.each_ancestor([:begin, :def]) do |node|
|
162
|
+
yielded_types << node.type
|
163
|
+
end
|
150
164
|
|
151
|
-
|
165
|
+
expect(yielded_types).to eq([:def, :begin])
|
166
|
+
end
|
152
167
|
end
|
153
168
|
end
|
169
|
+
|
170
|
+
include_examples 'node enumerator', :each_ancestor
|
154
171
|
end
|
155
172
|
|
156
173
|
describe '#each_child_node' do
|
@@ -184,45 +201,45 @@ module Astrolabe
|
|
184
201
|
returned_value = target_node.each_child_node {}
|
185
202
|
expect(returned_value).to equal(target_node)
|
186
203
|
end
|
187
|
-
end
|
188
204
|
|
189
|
-
|
205
|
+
context 'and a node type symbol is passed' do
|
206
|
+
it 'scans all the child nodes but yields only nodes matching the type' do
|
207
|
+
yielded_types = []
|
190
208
|
|
191
|
-
|
192
|
-
|
193
|
-
|
209
|
+
target_node.each_child_node(:send) do |node|
|
210
|
+
yielded_types << node.type
|
211
|
+
end
|
194
212
|
|
195
|
-
|
196
|
-
yielded_types << node.type
|
213
|
+
expect(yielded_types).to eq([:send])
|
197
214
|
end
|
198
|
-
|
199
|
-
expect(yielded_types).to eq([:send])
|
200
215
|
end
|
201
|
-
end
|
202
216
|
|
203
|
-
|
204
|
-
|
205
|
-
|
217
|
+
context 'and multiple node type symbols are passed' do
|
218
|
+
it 'scans all the child nodes but yields only nodes matching any of the types' do
|
219
|
+
yielded_types = []
|
206
220
|
|
207
|
-
|
208
|
-
|
209
|
-
|
221
|
+
target_node.each_child_node(:send, :args) do |node|
|
222
|
+
yielded_types << node.type
|
223
|
+
end
|
210
224
|
|
211
|
-
|
225
|
+
expect(yielded_types).to eq([:args, :send])
|
226
|
+
end
|
212
227
|
end
|
213
|
-
end
|
214
228
|
|
215
|
-
|
216
|
-
|
217
|
-
|
229
|
+
context 'and an array including type symbols are passed' do
|
230
|
+
it 'scans all the child nodes but yields only nodes matching any of the types' do
|
231
|
+
yielded_types = []
|
218
232
|
|
219
|
-
|
220
|
-
|
221
|
-
|
233
|
+
target_node.each_child_node([:send, :args]) do |node|
|
234
|
+
yielded_types << node.type
|
235
|
+
end
|
222
236
|
|
223
|
-
|
237
|
+
expect(yielded_types).to eq([:args, :send])
|
238
|
+
end
|
224
239
|
end
|
225
240
|
end
|
241
|
+
|
242
|
+
include_examples 'node enumerator', :each_child_node
|
226
243
|
end
|
227
244
|
|
228
245
|
describe '#each_descendant' do
|
@@ -265,45 +282,45 @@ module Astrolabe
|
|
265
282
|
returned_value = target_node.each_descendant {}
|
266
283
|
expect(returned_value).to equal(target_node)
|
267
284
|
end
|
268
|
-
end
|
269
285
|
|
270
|
-
|
286
|
+
context 'and a node type symbol is passed' do
|
287
|
+
it 'scans all the descendant nodes but yields only nodes matching the type' do
|
288
|
+
yielded_types = []
|
271
289
|
|
272
|
-
|
273
|
-
|
274
|
-
|
290
|
+
target_node.each_descendant(:send) do |node|
|
291
|
+
yielded_types << node.type
|
292
|
+
end
|
275
293
|
|
276
|
-
|
277
|
-
yielded_types << node.type
|
294
|
+
expect(yielded_types).to eq([:send, :send])
|
278
295
|
end
|
279
|
-
|
280
|
-
expect(yielded_types).to eq([:send, :send])
|
281
296
|
end
|
282
|
-
end
|
283
297
|
|
284
|
-
|
285
|
-
|
286
|
-
|
298
|
+
context 'and multiple node type symbols are passed' do
|
299
|
+
it 'scans all the descendant nodes but yields only nodes matching any of the types' do
|
300
|
+
yielded_types = []
|
287
301
|
|
288
|
-
|
289
|
-
|
290
|
-
|
302
|
+
target_node.each_descendant(:send, :def) do |node|
|
303
|
+
yielded_types << node.type
|
304
|
+
end
|
291
305
|
|
292
|
-
|
306
|
+
expect(yielded_types).to eq([:send, :def, :send])
|
307
|
+
end
|
293
308
|
end
|
294
|
-
end
|
295
309
|
|
296
|
-
|
297
|
-
|
298
|
-
|
310
|
+
context 'and an array including type symbols are passed' do
|
311
|
+
it 'scans all the descendant nodes but yields only nodes matching any of the types' do
|
312
|
+
yielded_types = []
|
299
313
|
|
300
|
-
|
301
|
-
|
302
|
-
|
314
|
+
target_node.each_descendant([:send, :def]) do |node|
|
315
|
+
yielded_types << node.type
|
316
|
+
end
|
303
317
|
|
304
|
-
|
318
|
+
expect(yielded_types).to eq([:send, :def, :send])
|
319
|
+
end
|
305
320
|
end
|
306
321
|
end
|
322
|
+
|
323
|
+
include_examples 'node enumerator', :each_descendant
|
307
324
|
end
|
308
325
|
|
309
326
|
describe '#each_node' do
|
@@ -346,45 +363,45 @@ module Astrolabe
|
|
346
363
|
returned_value = target_node.each_node {}
|
347
364
|
expect(returned_value).to equal(target_node)
|
348
365
|
end
|
349
|
-
end
|
350
366
|
|
351
|
-
|
367
|
+
context 'and a node type symbol is passed' do
|
368
|
+
it 'scans all the nodes but yields only nodes matching the type' do
|
369
|
+
yielded_types = []
|
352
370
|
|
353
|
-
|
354
|
-
|
355
|
-
|
371
|
+
target_node.each_node(:send) do |node|
|
372
|
+
yielded_types << node.type
|
373
|
+
end
|
356
374
|
|
357
|
-
|
358
|
-
yielded_types << node.type
|
375
|
+
expect(yielded_types).to eq([:send, :send])
|
359
376
|
end
|
360
|
-
|
361
|
-
expect(yielded_types).to eq([:send, :send])
|
362
377
|
end
|
363
|
-
end
|
364
378
|
|
365
|
-
|
366
|
-
|
367
|
-
|
379
|
+
context 'and multiple node type symbols are passed' do
|
380
|
+
it 'scans all the nodes but yields only nodes matching any of the types' do
|
381
|
+
yielded_types = []
|
368
382
|
|
369
|
-
|
370
|
-
|
371
|
-
|
383
|
+
target_node.each_node(:send, :def) do |node|
|
384
|
+
yielded_types << node.type
|
385
|
+
end
|
372
386
|
|
373
|
-
|
387
|
+
expect(yielded_types).to eq([:send, :def, :send])
|
388
|
+
end
|
374
389
|
end
|
375
|
-
end
|
376
390
|
|
377
|
-
|
378
|
-
|
379
|
-
|
391
|
+
context 'and an array including type symbols are passed' do
|
392
|
+
it 'scans all the nodes but yields only nodes matching any of the types' do
|
393
|
+
yielded_types = []
|
380
394
|
|
381
|
-
|
382
|
-
|
383
|
-
|
395
|
+
target_node.each_node([:send, :def]) do |node|
|
396
|
+
yielded_types << node.type
|
397
|
+
end
|
384
398
|
|
385
|
-
|
399
|
+
expect(yielded_types).to eq([:send, :def, :send])
|
400
|
+
end
|
386
401
|
end
|
387
402
|
end
|
403
|
+
|
404
|
+
include_examples 'node enumerator', :each_node
|
388
405
|
end
|
389
406
|
|
390
407
|
describe '#send_type?' do
|