astrolabe 1.2.1 → 1.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 533fadbcceb5e0b4521256ffa902fa7cecd2b7b0
4
- data.tar.gz: 03fb83e3bcd917fb63ff123a476b86492c28b62b
3
+ metadata.gz: 655b042c4b17609531f72d896368f9a182d9f5c0
4
+ data.tar.gz: c0b136a7bcbbe8a03950a78cea786c1a35803253
5
5
  SHA512:
6
- metadata.gz: 5a1ed3ae0bc7f231d84c01913e012eb46a32ff5020d26f43a88b0c3875a923901f8ebb6992a2b13e7c83400beadeee636aa8450d1a216563d968206cff7fc5f0
7
- data.tar.gz: 09409b8f6460607cbb64140439f878e635926e51e10941860ce60217b66618b1622e0f137cf8a2890f44d012ac74ee2394666a46594bda5506451344a919b155
6
+ metadata.gz: 7f1137b68a0f7b1fbabe736f7f2ef48758d76f566c19e9001bba6cbf5d799a8b459abb7f2d773e19e2b7e63b3ae1659a3ab022a7b26acecc2d6add00a6671b7f
7
+ data.tar.gz: 640ebf0b1e01d4ec8dc1a92ba13e1e06d1e9a9ab867dbf5724bcb1e559671edbd75d23ff6266b8e78cdca625973752066926ec2b45d94c4de1ba0d45a3810690
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Development
4
4
 
5
+ ## v1.3.0
6
+
7
+ * Add `Node#sibling_index`.
8
+
5
9
  ## v1.2.1
6
10
 
7
11
  * Re-release 1.2.0 due to an error in `rubygems.org`.
@@ -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
  #
@@ -5,8 +5,8 @@ module Astrolabe
5
5
  # http://semver.org/
6
6
  module Version
7
7
  MAJOR = 1
8
- MINOR = 2
9
- PATCH = 1
8
+ MINOR = 3
9
+ PATCH = 0
10
10
 
11
11
  def self.to_s
12
12
  [MAJOR, MINOR, PATCH].join('.')
@@ -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.2.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-21 00:00:00.000000000 Z
11
+ date: 2014-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser