astrolabe 1.2.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/astrolabe/node.rb +7 -0
- data/lib/astrolabe/version.rb +2 -2
- data/spec/astrolabe/node_spec.rb +44 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 655b042c4b17609531f72d896368f9a182d9f5c0
|
4
|
+
data.tar.gz: c0b136a7bcbbe8a03950a78cea786c1a35803253
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f1137b68a0f7b1fbabe736f7f2ef48758d76f566c19e9001bba6cbf5d799a8b459abb7f2d773e19e2b7e63b3ae1659a3ab022a7b26acecc2d6add00a6671b7f
|
7
|
+
data.tar.gz: 640ebf0b1e01d4ec8dc1a92ba13e1e06d1e9a9ab867dbf5724bcb1e559671edbd75d23ff6266b8e78cdca625973752066926ec2b45d94c4de1ba0d45a3810690
|
data/CHANGELOG.md
CHANGED
data/lib/astrolabe/node.rb
CHANGED
@@ -63,6 +63,13 @@ module Astrolabe
|
|
63
63
|
parent.nil?
|
64
64
|
end
|
65
65
|
|
66
|
+
# Returns the index of the receiver node in its siblings.
|
67
|
+
#
|
68
|
+
# @return [Integer] the index of the receiver node in its siblings
|
69
|
+
def sibling_index
|
70
|
+
parent.children.index { |sibling| sibling.equal?(self) }
|
71
|
+
end
|
72
|
+
|
66
73
|
# Calls the given block for each ancestor node in the order from parent to root.
|
67
74
|
# If no block is given, an `Enumerator` is returned.
|
68
75
|
#
|
data/lib/astrolabe/version.rb
CHANGED
data/spec/astrolabe/node_spec.rb
CHANGED
@@ -52,6 +52,50 @@ module Astrolabe
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
+
describe '#sibling_index' do
|
56
|
+
let(:source) { <<-END }
|
57
|
+
2.times do |index|
|
58
|
+
puts index
|
59
|
+
end
|
60
|
+
END
|
61
|
+
|
62
|
+
# (block
|
63
|
+
# (send
|
64
|
+
# (int 2) :times)
|
65
|
+
# (args
|
66
|
+
# (arg :index))
|
67
|
+
# (send nil :puts
|
68
|
+
# (lvar :index)))
|
69
|
+
|
70
|
+
let(:target_node) { root_node.each_node.find(&:args_type?) }
|
71
|
+
|
72
|
+
it 'returns the index of the receiver node in its siblings' do
|
73
|
+
expect(target_node.sibling_index).to eq(1)
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'when there are same structure nodes in the siblings' do
|
77
|
+
let(:source) { <<-END }
|
78
|
+
foo = 1
|
79
|
+
puts foo
|
80
|
+
puts foo
|
81
|
+
END
|
82
|
+
|
83
|
+
# (begin
|
84
|
+
# (lvasgn :foo
|
85
|
+
# (int 1))
|
86
|
+
# (send nil :puts
|
87
|
+
# (lvar :foo))
|
88
|
+
# (send nil :puts
|
89
|
+
# (lvar :foo)))
|
90
|
+
|
91
|
+
let(:target_node) { root_node.each_node(:send).to_a.last }
|
92
|
+
|
93
|
+
it 'does not confuse them' do
|
94
|
+
expect(target_node.sibling_index).to eq(2)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
55
99
|
shared_examples 'node enumerator' do |method_name|
|
56
100
|
context 'when no block is given' do
|
57
101
|
it 'returns an enumerator' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: astrolabe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuji Nakayama
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|