astrolabe 0.5.0 → 0.5.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c17d30b9bee8cee926de9b4b2527950eb5c50763
4
- data.tar.gz: 218e6135e0a8019b136651f4b92c0ca8648326a2
3
+ metadata.gz: 1306bd1680b44a33bad44374f71f0254be88dd30
4
+ data.tar.gz: f49d728a8cde1724e8c312475bcd8dad607c4eb6
5
5
  SHA512:
6
- metadata.gz: 0e705c920bc838e45e1e0abc555e21582647c37f857e43ad36bea9057db9e9e50431c0e6eb6a9a57a7f271d8f0ec66bf45735907e1a03c159ec7016ddaf9d72b
7
- data.tar.gz: 255f1615ab127be042ead82d9c363c06667c1e50caf9983920330313e2c9ac95fdcf09ff3b255449469a8b557e616fce7de0f02a6858b31463110ac7f4a0ceda
6
+ metadata.gz: 47f5e3637d1d87069147a9d1f574ae36d853ce942fa1f3a44330430184519639490aa28c0e6c5c81e8a126ec3dbef1152eb754209c1bc2bbf35c0a2cff69f234
7
+ data.tar.gz: 10468278e65896eb7d8a641fbe57789823a7a11bb91e89b8b34f976037b0ae3f7e6c9066e1bf583223123c23430f9143c6eb874ba95e01621b1f5e8ab4bc9d18
@@ -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)
@@ -6,7 +6,7 @@ module Astrolabe
6
6
  module Version
7
7
  MAJOR = 0
8
8
  MINOR = 5
9
- PATCH = 0
9
+ PATCH = 1
10
10
 
11
11
  def self.to_s
12
12
  [MAJOR, MINOR, PATCH].join('.')
@@ -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
- include_examples 'node enumerator', :each_ancestor
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
- context 'when a node type symbol is passed' do
120
- it 'scans all the ancestor nodes but yields only nodes matching the type' do
121
- yielded_types = []
137
+ target_node.each_ancestor(:begin) do |node|
138
+ yielded_types << node.type
139
+ end
122
140
 
123
- target_node.each_ancestor(:begin) do |node|
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
- context 'when multiple node type symbols are passed' do
132
- it 'scans all the ancestor nodes but yields only nodes matching any of the types' do
133
- yielded_types = []
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
- target_node.each_ancestor(:begin, :def) do |node|
136
- yielded_types << node.type
137
- end
149
+ target_node.each_ancestor(:begin, :def) do |node|
150
+ yielded_types << node.type
151
+ end
138
152
 
139
- expect(yielded_types).to eq([:def, :begin])
153
+ expect(yielded_types).to eq([:def, :begin])
154
+ end
140
155
  end
141
- end
142
156
 
143
- context 'when an array including type symbols are passed' do
144
- it 'scans all the ancestor nodes but yields only nodes matching any of the types' do
145
- yielded_types = []
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
- target_node.each_ancestor([:begin, :def]) do |node|
148
- yielded_types << node.type
149
- end
161
+ target_node.each_ancestor([:begin, :def]) do |node|
162
+ yielded_types << node.type
163
+ end
150
164
 
151
- expect(yielded_types).to eq([:def, :begin])
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
- include_examples 'node enumerator', :each_child_node
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
- context 'when a node type symbol is passed' do
192
- it 'scans all the child nodes but yields only nodes matching the type' do
193
- yielded_types = []
209
+ target_node.each_child_node(:send) do |node|
210
+ yielded_types << node.type
211
+ end
194
212
 
195
- target_node.each_child_node(:send) do |node|
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
- context 'when multiple node type symbols are passed' do
204
- it 'scans all the child nodes but yields only nodes matching any of the types' do
205
- yielded_types = []
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
- target_node.each_child_node(:send, :args) do |node|
208
- yielded_types << node.type
209
- end
221
+ target_node.each_child_node(:send, :args) do |node|
222
+ yielded_types << node.type
223
+ end
210
224
 
211
- expect(yielded_types).to eq([:args, :send])
225
+ expect(yielded_types).to eq([:args, :send])
226
+ end
212
227
  end
213
- end
214
228
 
215
- context 'when an array including type symbols are passed' do
216
- it 'scans all the child nodes but yields only nodes matching any of the types' do
217
- yielded_types = []
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
- target_node.each_child_node([:send, :args]) do |node|
220
- yielded_types << node.type
221
- end
233
+ target_node.each_child_node([:send, :args]) do |node|
234
+ yielded_types << node.type
235
+ end
222
236
 
223
- expect(yielded_types).to eq([:args, :send])
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
- include_examples 'node enumerator', :each_descendant
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
- context 'when a node type symbol is passed' do
273
- it 'scans all the descendant nodes but yields only nodes matching the type' do
274
- yielded_types = []
290
+ target_node.each_descendant(:send) do |node|
291
+ yielded_types << node.type
292
+ end
275
293
 
276
- target_node.each_descendant(:send) do |node|
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
- context 'when multiple node type symbols are passed' do
285
- it 'scans all the descendant nodes but yields only nodes matching any of the types' do
286
- yielded_types = []
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
- target_node.each_descendant(:send, :def) do |node|
289
- yielded_types << node.type
290
- end
302
+ target_node.each_descendant(:send, :def) do |node|
303
+ yielded_types << node.type
304
+ end
291
305
 
292
- expect(yielded_types).to eq([:send, :def, :send])
306
+ expect(yielded_types).to eq([:send, :def, :send])
307
+ end
293
308
  end
294
- end
295
309
 
296
- context 'when an array including type symbols are passed' do
297
- it 'scans all the descendant nodes but yields only nodes matching any of the types' do
298
- yielded_types = []
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
- target_node.each_descendant([:send, :def]) do |node|
301
- yielded_types << node.type
302
- end
314
+ target_node.each_descendant([:send, :def]) do |node|
315
+ yielded_types << node.type
316
+ end
303
317
 
304
- expect(yielded_types).to eq([:send, :def, :send])
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
- include_examples 'node enumerator', :each_node
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
- context 'when a node type symbol is passed' do
354
- it 'scans all the nodes but yields only nodes matching the type' do
355
- yielded_types = []
371
+ target_node.each_node(:send) do |node|
372
+ yielded_types << node.type
373
+ end
356
374
 
357
- target_node.each_node(:send) do |node|
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
- context 'when multiple node type symbols are passed' do
366
- it 'scans all the nodes but yields only nodes matching any of the types' do
367
- yielded_types = []
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
- target_node.each_node(:send, :def) do |node|
370
- yielded_types << node.type
371
- end
383
+ target_node.each_node(:send, :def) do |node|
384
+ yielded_types << node.type
385
+ end
372
386
 
373
- expect(yielded_types).to eq([:send, :def, :send])
387
+ expect(yielded_types).to eq([:send, :def, :send])
388
+ end
374
389
  end
375
- end
376
390
 
377
- context 'when an array including type symbols are passed' do
378
- it 'scans all the nodes but yields only nodes matching any of the types' do
379
- yielded_types = []
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
- target_node.each_node([:send, :def]) do |node|
382
- yielded_types << node.type
383
- end
395
+ target_node.each_node([:send, :def]) do |node|
396
+ yielded_types << node.type
397
+ end
384
398
 
385
- expect(yielded_types).to eq([:send, :def, :send])
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: astrolabe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuji Nakayama