lib/mutant/mutator/node.rb in mutant-0.8.8 vs lib/mutant/mutator/node.rb in mutant-0.8.9
- old
+ new
@@ -15,12 +15,10 @@
# @param [Parser::AST::Node] node
#
# @param [Fixnum] index
#
# @return [undefined]
- #
- # @api private
def self.define_named_child(name, index)
super
define_method("emit_#{name}_mutations") do |&block|
mutate_child(index, &block)
@@ -35,37 +33,29 @@
private
# Node to mutate
#
# @return [Parser::AST::Node]
- #
- # @api private
alias_method :node, :input
# Duplicate of original
#
# @return [Parser::AST::Node]
- #
- # @api private
alias_method :dup_node, :dup_input
# Original nodes children
#
# @return [Array<Parser::AST::Node>]
- #
- # @api private
def children
node.children
end
# Dispatch on child index
#
# @param [Fixnum] index
#
# @return [undefined]
- #
- # @api private
def mutate_child(index, mutator = Mutator, &block)
block ||= TAUTOLOGY
child = children.at(index)
mutator.each(child, self) do |mutation|
next unless block.call(mutation)
@@ -76,12 +66,10 @@
# Emit delete child mutation
#
# @param [Fixnum] index
#
# @return [undefined]
- #
- # @api private
def delete_child(index)
dup_children = children.dup
dup_children.delete_at(index)
emit_type(*dup_children)
end
@@ -90,12 +78,10 @@
#
# @param [Fixnum] index
# @param [Parser::AST::Node] node
#
# @return [undefined]
- #
- # @api private
def emit_child_update(index, node)
new_children = children.dup
new_children[index] = node
emit_type(*new_children)
end
@@ -103,51 +89,41 @@
# Emit a new AST node with same class as wrapped node
#
# @param [Array<Parser::AST::Node>] children
#
# @return [undefined]
- #
- # @api private
def emit_type(*children)
- emit(Parser::AST::Node.new(node.type, children))
+ emit(::Parser::AST::Node.new(node.type, children))
end
# Emit singleton literals
#
# @return [undefined]
- #
- # @api private
def emit_singletons
emit_nil
emit_self
end
# Emit a literal self
#
# @return [undefined]
- #
- # @api private
def emit_self
emit(N_SELF)
end
# Emit a literal nil
#
# @return [undefined]
- #
- # @api private
def emit_nil
emit(N_NIL) unless asgn_left?
end
# Emit values
#
# @param [Array<Object>] values
#
# @return [undefined]
- #
- # @api private
def emit_values(values)
values.each do |value|
emit_type(value)
end
end
@@ -157,12 +133,10 @@
# @return [Parser::AST::Node] node
# if parent with node is present
#
# @return [nil]
# otherwise
- #
- # @api private
def parent_node
parent.node if parent
end
# Parent type
@@ -170,31 +144,25 @@
# @return [Symbol] type
# if parent with type is present
#
# @return [nil]
# otherwise
- #
- # @api private
def parent_type
parent_node.type if parent_node
end
# Test if the node is the left of an or_asgn or op_asgn
#
# @return [Boolean]
- #
- # @api private
def asgn_left?
AST::Types::OP_ASSIGN.include?(parent_type) && parent.node.children.first.equal?(node)
end
# Children indices
#
# @param [Range] range
#
# @return [Enumerable<Fixnum>]
- #
- # @api private
def children_indices(range)
range_end = range.end
last_index = range_end >= 0 ? range_end : children.length + range_end
range.begin.upto(last_index)
end