2012-12-06 15:30:28 -05:00
|
|
|
module Mutant
|
|
|
|
class Mutator
|
|
|
|
class Node
|
2013-01-04 16:16:03 -05:00
|
|
|
|
|
|
|
# Namespace for send mutators
|
2012-12-06 15:30:28 -05:00
|
|
|
class Send < self
|
|
|
|
|
2013-06-04 04:25:13 -04:00
|
|
|
handle(:send)
|
2012-12-06 15:30:28 -05:00
|
|
|
|
2013-06-14 13:48:11 -04:00
|
|
|
RECEIVER_INDEX, SELECTOR_INDEX = 0, 1
|
|
|
|
ARGUMENTS_INDEX = 2..-1.freeze
|
2013-06-14 13:47:23 -04:00
|
|
|
|
2012-12-06 15:30:28 -05:00
|
|
|
private
|
|
|
|
|
2012-12-10 11:11:08 -05:00
|
|
|
# Emit mutations
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def dispatch
|
2013-06-14 13:53:55 -04:00
|
|
|
if binary_operator?
|
|
|
|
run(Binary)
|
|
|
|
return
|
|
|
|
end
|
2013-06-14 13:47:23 -04:00
|
|
|
emit(receiver) if receiver
|
|
|
|
mutate_receiver
|
|
|
|
mutate_arguments
|
|
|
|
end
|
|
|
|
|
2013-06-14 13:53:55 -04:00
|
|
|
# Test for binary operator
|
|
|
|
#
|
|
|
|
# @return [true]
|
|
|
|
# if send is a binary operator
|
|
|
|
#
|
|
|
|
# @return [false]
|
|
|
|
# otherwise
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def binary_operator?
|
|
|
|
arguments.one? && BINARY_METHOD_OPERATORS.include?(selector)
|
|
|
|
end
|
|
|
|
|
2013-06-14 13:47:23 -04:00
|
|
|
# Mutate arguments
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def mutate_arguments
|
|
|
|
return if arguments.empty?
|
|
|
|
if arguments.one?
|
|
|
|
emit(arguments.first)
|
|
|
|
end
|
|
|
|
emit_self(receiver, selector)
|
|
|
|
children.each_index do |index|
|
|
|
|
next if index <= SELECTOR_INDEX
|
|
|
|
mutate_child(index)
|
|
|
|
delete_child(index)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Emit receiver mutations
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def mutate_receiver
|
|
|
|
return unless receiver
|
|
|
|
emit_implicit_self
|
|
|
|
mutate_child(RECEIVER_INDEX)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Emit implicit self mutation
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api rpivate
|
|
|
|
#
|
|
|
|
def emit_implicit_self
|
|
|
|
if receiver.type == :self and !KEYWORDS.include?(selector)
|
|
|
|
emit_child_update(RECEIVER_INDEX, nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Return receiver
|
|
|
|
#
|
|
|
|
# @return [Parser::Node::AST]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def receiver
|
|
|
|
children[RECEIVER_INDEX]
|
|
|
|
end
|
|
|
|
|
|
|
|
# Return selector
|
|
|
|
#
|
|
|
|
# @return [Symbol]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def selector
|
|
|
|
children[SELECTOR_INDEX]
|
|
|
|
end
|
|
|
|
|
|
|
|
# Return arguments
|
|
|
|
#
|
|
|
|
# @return [Array<Parser::AST::Node>]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def arguments
|
|
|
|
children[ARGUMENTS_INDEX]
|
2012-12-06 15:30:28 -05:00
|
|
|
end
|
2013-06-14 13:47:23 -04:00
|
|
|
memoize :arguments
|
2013-06-04 04:25:13 -04:00
|
|
|
|
|
|
|
end # Send
|
|
|
|
end # Node
|
|
|
|
end # Mutator
|
|
|
|
end # Mutant
|