Fix visiblity of NamedChildren methods
This commit is contained in:
parent
237d032f63
commit
f0ae1d1990
10 changed files with 53 additions and 6 deletions
|
@ -1,3 +1,3 @@
|
|||
---
|
||||
threshold: 18
|
||||
total_score: 1160
|
||||
total_score: 1162
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
---
|
||||
threshold: 29.3
|
||||
threshold: 27.7
|
||||
|
|
|
@ -9,6 +9,8 @@ module Mutant
|
|||
|
||||
children :base, :name
|
||||
|
||||
public :base, :name
|
||||
|
||||
# Test if AST node is possibly a top level constant
|
||||
#
|
||||
# @return [Boolean]
|
||||
|
|
|
@ -11,6 +11,8 @@ module Mutant
|
|||
|
||||
children :name, :default_value
|
||||
|
||||
public :name, :default_value
|
||||
|
||||
# Test if optarg definition intends to be used
|
||||
#
|
||||
# @return [Boolean]
|
||||
|
|
|
@ -8,6 +8,8 @@ module Mutant
|
|||
include NamedChildren, Concord.new(:node)
|
||||
|
||||
children :captures, :assignment, :body
|
||||
|
||||
public :captures, :assignment, :body
|
||||
end # Resbody
|
||||
|
||||
end # Meta
|
||||
|
|
|
@ -8,6 +8,8 @@ module Mutant
|
|||
include NamedChildren, Concord.new(:node)
|
||||
|
||||
children :name
|
||||
|
||||
public :name
|
||||
end # Restarg
|
||||
|
||||
end # Meta
|
||||
|
|
|
@ -9,6 +9,8 @@ module Mutant
|
|||
|
||||
children :receiver, :selector
|
||||
|
||||
public :receiver, :selector
|
||||
|
||||
INDEX_ASSIGNMENT_SELECTOR = :[]=
|
||||
ATTRIBUTE_ASSIGNMENT_SELECTOR_SUFFIX = '='.freeze
|
||||
|
||||
|
@ -16,6 +18,7 @@ module Mutant
|
|||
#
|
||||
# @return [Enumerable<Parser::AST::Node>]
|
||||
alias_method :arguments, :remaining_children
|
||||
public :arguments
|
||||
|
||||
# Test if AST node is a valid assignment target
|
||||
#
|
||||
|
|
|
@ -9,6 +9,8 @@ module Mutant
|
|||
|
||||
children :name
|
||||
|
||||
public :name
|
||||
|
||||
end # Symbol
|
||||
end # Meta
|
||||
end # AST
|
||||
|
|
|
@ -42,7 +42,7 @@ module Mutant
|
|||
#
|
||||
# @return [undefined]
|
||||
def define_named_child(name, index)
|
||||
define_method(name) do
|
||||
define_private_method(name) do
|
||||
children.at(index)
|
||||
end
|
||||
end
|
||||
|
@ -53,15 +53,15 @@ module Mutant
|
|||
#
|
||||
# @return [undefined]
|
||||
def define_remaining_children(names)
|
||||
define_method(:remaining_children_with_index) do
|
||||
define_private_method(:remaining_children_with_index) do
|
||||
children.each_with_index.drop(names.length)
|
||||
end
|
||||
|
||||
define_method(:remaining_children_indices) do
|
||||
define_private_method(:remaining_children_indices) do
|
||||
children.each_index.drop(names.length)
|
||||
end
|
||||
|
||||
define_method(:remaining_children) do
|
||||
define_private_method(:remaining_children) do
|
||||
children.drop(names.length)
|
||||
end
|
||||
end
|
||||
|
@ -76,6 +76,14 @@ module Mutant
|
|||
define_remaining_children(names)
|
||||
end
|
||||
|
||||
# Define private method
|
||||
#
|
||||
# @param [Symbol] name
|
||||
def define_private_method(name, &block)
|
||||
define_method(name, &block)
|
||||
private(name)
|
||||
end
|
||||
|
||||
end # ClassMethods
|
||||
end # NamedChildren
|
||||
end # AST
|
||||
|
|
|
@ -8,6 +8,14 @@ RSpec.describe Mutant::AST::NamedChildren do
|
|||
end
|
||||
end
|
||||
|
||||
def publish
|
||||
klass.class_eval do
|
||||
public :foo, :bar
|
||||
|
||||
public :remaining_children, :remaining_children_indices, :remaining_children_with_index
|
||||
end
|
||||
end
|
||||
|
||||
let(:instance) { klass.new(node) }
|
||||
|
||||
let(:node_foo) { s(:foo) }
|
||||
|
@ -17,26 +25,42 @@ RSpec.describe Mutant::AST::NamedChildren do
|
|||
let(:node) { s(:node, node_foo, node_bar, node_baz) }
|
||||
|
||||
describe 'generated methods' do
|
||||
specify 'are private by default' do
|
||||
%i[
|
||||
foo
|
||||
bar
|
||||
remaining_children
|
||||
remaining_children_indices
|
||||
remaining_children_with_index
|
||||
].each do |name|
|
||||
expect(klass.private_instance_methods.include?(name)).to be(true)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#remaining_children' do
|
||||
it 'returns remaining unnamed children' do
|
||||
publish
|
||||
expect(instance.remaining_children).to eql([node_baz])
|
||||
end
|
||||
end
|
||||
|
||||
describe '#remaining_children_indices' do
|
||||
it 'returns remaining unnamed children indices' do
|
||||
publish
|
||||
expect(instance.remaining_children_indices).to eql([2])
|
||||
end
|
||||
end
|
||||
|
||||
describe '#remaining_children_with_index' do
|
||||
it 'returns remaining unnamed children indices' do
|
||||
publish
|
||||
expect(instance.remaining_children_with_index).to eql([[node_baz, 2]])
|
||||
end
|
||||
end
|
||||
|
||||
describe '#foo' do
|
||||
it 'returns named child foo' do
|
||||
publish
|
||||
expect(instance.foo).to be(node_foo)
|
||||
end
|
||||
end
|
||||
|
@ -44,6 +68,7 @@ RSpec.describe Mutant::AST::NamedChildren do
|
|||
describe '#bar' do
|
||||
context 'when node is present' do
|
||||
it 'returns named child bar' do
|
||||
publish
|
||||
expect(instance.bar).to be(node_bar)
|
||||
end
|
||||
end
|
||||
|
@ -52,6 +77,7 @@ RSpec.describe Mutant::AST::NamedChildren do
|
|||
let(:node) { s(:node, node_foo) }
|
||||
|
||||
it 'returns nil' do
|
||||
publish
|
||||
expect(instance.bar).to be(nil)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue