3ae85ea0f9
* Before Symbol#==, Symbol#eql?, and Symbol#equal? where used inconsistently * Lots of redundant foo.type.equal?(:symbol)
97 lines
2.2 KiB
Ruby
97 lines
2.2 KiB
Ruby
module Mutant
|
|
class Mutator
|
|
class Node
|
|
# Mutator for arguments node
|
|
class Arguments < self
|
|
|
|
handle(:args)
|
|
|
|
private
|
|
|
|
# Perform dispatch
|
|
#
|
|
# @return [undefined]
|
|
#
|
|
# @api private
|
|
#
|
|
def dispatch
|
|
emit_argument_presence
|
|
emit_argument_mutations
|
|
emit_mlhs_expansion
|
|
end
|
|
|
|
# Emit argument presence mutation
|
|
#
|
|
# @return [undefined]
|
|
#
|
|
# @api private
|
|
#
|
|
def emit_argument_presence
|
|
emit_type
|
|
Mutator::Util::Array::Presence.each(children, self) do |children|
|
|
emit_type(*children)
|
|
end
|
|
end
|
|
|
|
# Emit argument mutations
|
|
#
|
|
# @return [undefined]
|
|
#
|
|
# @api private
|
|
#
|
|
def emit_argument_mutations
|
|
children.each_with_index do |child, index|
|
|
Mutator.each(child) do |mutant|
|
|
next if invalid_argument_replacement?(mutant, index)
|
|
emit_child_update(index, mutant)
|
|
end
|
|
end
|
|
end
|
|
|
|
# Test if child mutation is allowed
|
|
#
|
|
# @param [Parser::AST::Node]
|
|
#
|
|
# @return [Boolean]
|
|
#
|
|
# @api private
|
|
#
|
|
def invalid_argument_replacement?(mutant, index)
|
|
original = children.fetch(index)
|
|
|
|
n_optarg?(original) &&
|
|
n_arg?(mutant) &&
|
|
children[0...index].any?(&method(:n_optarg?))
|
|
end
|
|
|
|
# Emit mlhs expansions
|
|
#
|
|
# @return [undefined]
|
|
#
|
|
# @api private
|
|
#
|
|
def emit_mlhs_expansion
|
|
mlhs_childs_with_index.each do |child, index|
|
|
dup_children = children.dup
|
|
dup_children.delete_at(index)
|
|
dup_children.insert(index, *child.children)
|
|
emit_type(*dup_children)
|
|
end
|
|
end
|
|
|
|
# Return mlhs childs
|
|
#
|
|
# @return [Enumerable<Parser::AST::Node, Fixnum>]
|
|
#
|
|
# @api private
|
|
#
|
|
def mlhs_childs_with_index
|
|
children.each_with_index.select do |child, _index|
|
|
n_mlhs?(child)
|
|
end
|
|
end
|
|
|
|
end # Arguments
|
|
end # Node
|
|
end # Mutator
|
|
end # Mutant
|