free_mutant/lib/mutant/mutator/node/arguments.rb

98 lines
2.2 KiB
Ruby
Raw Normal View History

2013-06-04 17:44:17 -04:00
module Mutant
class Mutator
class Node
2013-06-15 11:13:01 -04:00
# Mutator for arguments node
2013-06-04 17:44:17 -04:00
class Arguments < self
handle(:args)
private
# Perform dispatch
#
# @return [undefined]
#
# @api private
#
def dispatch
emit_argument_presence
emit_argument_mutations
2013-06-14 14:19:53 -04:00
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|
2014-06-08 09:01:26 -04:00
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
2013-06-14 14:19:53 -04:00
# Emit mlhs expansions
#
# @return [undefined]
#
# @api private
#
def emit_mlhs_expansion
2013-06-15 11:16:34 -04:00
mlhs_childs_with_index.each do |child, index|
2013-06-14 14:19:53 -04:00
dup_children = children.dup
dup_children.delete_at(index)
dup_children.insert(index, *child.children)
2014-06-02 23:51:22 -04:00
emit_type(*dup_children)
2013-06-14 14:19:53 -04:00
end
2013-06-04 17:44:17 -04:00
end
2013-06-15 11:16:34 -04:00
# Return mlhs childs
#
# @return [Enumerable<Parser::AST::Node, Fixnum>]
#
# @api private
#
def mlhs_childs_with_index
2014-05-27 11:12:36 -04:00
children.each_with_index.select do |child, _index|
n_mlhs?(child)
2013-06-15 11:16:34 -04:00
end
end
2013-06-04 17:44:17 -04:00
end # Arguments
end # Node
end # Mutator
end # Mutant