Port binary method operator mutator to parser

This commit is contained in:
Markus Schirp 2013-06-14 19:53:55 +02:00
parent 8e9043ea57
commit 8993fbf02a
5 changed files with 51 additions and 63 deletions

1
TODO
View file

@ -18,6 +18,7 @@ Mutations:
* Emit negative and positive mutations
* Mutate Block catch "def foo(&block)" and block pass "foo(&block)"
* Mutate super arguments just like send arguments
* Binary operator mutations
* Add timeout to terminate infinite loops
Example of a negative mutation:

View file

@ -58,7 +58,7 @@ require 'mutant/mutator/node/begin'
require 'mutant/mutator/node/while'
require 'mutant/mutator/node/super'
require 'mutant/mutator/node/send'
require 'mutant/mutator/node/send/binary_operator_method'
require 'mutant/mutator/node/send/binary'
require 'mutant/mutator/node/when'
require 'mutant/mutator/node/assignment'
require 'mutant/mutator/node/define'

View file

@ -19,11 +19,29 @@ module Mutant
# @api private
#
def dispatch
if binary_operator?
run(Binary)
return
end
emit(receiver) if receiver
mutate_receiver
mutate_arguments
end
# 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
# Mutate arguments
#
# @return [undefined]

View file

@ -0,0 +1,31 @@
module Mutant
class Mutator
class Node
class Send
# Mutator for sends that correspond to a binary operator
class Binary < self
RIGHT_INDEX = SELECTOR_INDEX+1
private
# Emit mutations
#
# @return [undefined]
#
# @api private
#
def dispatch
emit(receiver)
mutate_child(RECEIVER_INDEX) # left
mutate_child(RIGHT_INDEX)
emit(arguments.first)
end
end # Binary
end # Send
end # Node
end # Mutator
end # Mutant

View file

@ -1,62 +0,0 @@
module Mutant
class Mutator
class Node
class Send
# Mutator for sends that correspond to a binary operator
class BinaryOperatorMethod < Node
private
# Emit mutations
#
# @return [undefined]
#
# @api private
#
def dispatch
emit_left_mutations
emit_right_mutations
emit(right)
end
# Emit left mutations
#
# @return [undefined]
#
# @api private
#
def emit_left_mutations
emit_attribute_mutations(:receiver)
end
# Return right
#
# @return [Parser::AST::Node]
#
# @api private
#
def right
node.arguments.array.first
end
# Emit right mutations
#
# @return [undefined]
#
# @api private
#
def emit_right_mutations
Mutator.each(right).each do |mutated|
dup = dup_node
dup.arguments.array[0] = mutated
emit(dup)
end
end
end # BinaryOperatorMethod
end # Send
end # Node
end # Mutator
end # Mutant