2018-09-12 14:21:24 +00:00
|
|
|
# frozen_string_literal: true
|
2018-09-12 13:15:43 +00:00
|
|
|
|
2013-06-04 21:44:17 +00:00
|
|
|
module Mutant
|
|
|
|
class Mutator
|
|
|
|
class Node
|
2013-06-15 15:13:01 +00:00
|
|
|
# Mutator for arguments node
|
2013-06-04 21:44:17 +00:00
|
|
|
class Arguments < self
|
|
|
|
|
|
|
|
handle(:args)
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2016-06-18 22:39:16 +00:00
|
|
|
# Emit mutations
|
2013-06-04 21:44:17 +00:00
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
def dispatch
|
2014-06-06 23:05:27 +00:00
|
|
|
emit_argument_presence
|
|
|
|
emit_argument_mutations
|
2013-06-14 18:19:53 +00:00
|
|
|
emit_mlhs_expansion
|
|
|
|
end
|
|
|
|
|
2014-06-06 23:05:27 +00:00
|
|
|
# Emit argument presence mutation
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
def emit_argument_presence
|
|
|
|
emit_type
|
2018-11-29 22:07:24 +00:00
|
|
|
|
2016-03-06 21:19:32 +00:00
|
|
|
Util::Array::Presence.call(children).each do |children|
|
2021-01-17 04:53:49 +00:00
|
|
|
unless children.one? && n_mlhs?(children.first)
|
2018-11-29 22:07:24 +00:00
|
|
|
emit_type(*children)
|
|
|
|
end
|
2014-06-06 23:05:27 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-29 22:07:24 +00:00
|
|
|
# Emit procarg form
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
def emit_procarg(arg)
|
|
|
|
emit_type(s(:procarg0, *arg))
|
|
|
|
end
|
|
|
|
|
2014-06-06 23:05:27 +00:00
|
|
|
# Emit argument mutations
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
def emit_argument_mutations
|
|
|
|
children.each_with_index do |child, index|
|
2016-05-06 06:36:46 +00:00
|
|
|
Mutator.mutate(child).each do |mutant|
|
2014-06-08 13:01:26 +00:00
|
|
|
next if invalid_argument_replacement?(mutant, index)
|
|
|
|
emit_child_update(index, mutant)
|
2014-06-06 23:05:27 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Test if child mutation is allowed
|
|
|
|
#
|
|
|
|
# @param [Parser::AST::Node]
|
|
|
|
#
|
|
|
|
# @return [Boolean]
|
|
|
|
def invalid_argument_replacement?(mutant, index)
|
2016-03-06 21:19:32 +00:00
|
|
|
n_arg?(mutant) && children[0...index].any?(&method(:n_optarg?))
|
2014-06-06 23:05:27 +00:00
|
|
|
end
|
|
|
|
|
2013-06-14 18:19:53 +00:00
|
|
|
# Emit mlhs expansions
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
def emit_mlhs_expansion
|
2013-06-15 15:16:34 +00:00
|
|
|
mlhs_childs_with_index.each do |child, index|
|
2013-06-14 18:19:53 +00:00
|
|
|
dup_children = children.dup
|
|
|
|
dup_children.delete_at(index)
|
2016-03-06 21:19:32 +00:00
|
|
|
dup_children.insert(index, *child)
|
2014-06-03 03:51:22 +00:00
|
|
|
emit_type(*dup_children)
|
2013-06-14 18:19:53 +00:00
|
|
|
end
|
2013-06-04 21:44:17 +00:00
|
|
|
end
|
|
|
|
|
2015-07-03 15:21:39 +00:00
|
|
|
# Multiple left hand side childs
|
2013-06-15 15:16:34 +00:00
|
|
|
#
|
2017-07-06 07:45:17 +00:00
|
|
|
# @return [Enumerable<Parser::AST::Node, Integer>]
|
2013-06-15 15:16:34 +00:00
|
|
|
def mlhs_childs_with_index
|
2014-05-27 15:12:36 +00:00
|
|
|
children.each_with_index.select do |child, _index|
|
2014-06-10 02:05:58 +00:00
|
|
|
n_mlhs?(child)
|
2013-06-15 15:16:34 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-06-04 21:44:17 +00:00
|
|
|
end # Arguments
|
|
|
|
end # Node
|
|
|
|
end # Mutator
|
|
|
|
end # Mutant
|