Port binary method operator mutator to parser
This commit is contained in:
parent
8e9043ea57
commit
8993fbf02a
5 changed files with 51 additions and 63 deletions
1
TODO
1
TODO
|
@ -18,6 +18,7 @@ Mutations:
|
||||||
* Emit negative and positive mutations
|
* Emit negative and positive mutations
|
||||||
* Mutate Block catch "def foo(&block)" and block pass "foo(&block)"
|
* Mutate Block catch "def foo(&block)" and block pass "foo(&block)"
|
||||||
* Mutate super arguments just like send arguments
|
* Mutate super arguments just like send arguments
|
||||||
|
* Binary operator mutations
|
||||||
* Add timeout to terminate infinite loops
|
* Add timeout to terminate infinite loops
|
||||||
|
|
||||||
Example of a negative mutation:
|
Example of a negative mutation:
|
||||||
|
|
|
@ -58,7 +58,7 @@ require 'mutant/mutator/node/begin'
|
||||||
require 'mutant/mutator/node/while'
|
require 'mutant/mutator/node/while'
|
||||||
require 'mutant/mutator/node/super'
|
require 'mutant/mutator/node/super'
|
||||||
require 'mutant/mutator/node/send'
|
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/when'
|
||||||
require 'mutant/mutator/node/assignment'
|
require 'mutant/mutator/node/assignment'
|
||||||
require 'mutant/mutator/node/define'
|
require 'mutant/mutator/node/define'
|
||||||
|
|
|
@ -19,11 +19,29 @@ module Mutant
|
||||||
# @api private
|
# @api private
|
||||||
#
|
#
|
||||||
def dispatch
|
def dispatch
|
||||||
|
if binary_operator?
|
||||||
|
run(Binary)
|
||||||
|
return
|
||||||
|
end
|
||||||
emit(receiver) if receiver
|
emit(receiver) if receiver
|
||||||
mutate_receiver
|
mutate_receiver
|
||||||
mutate_arguments
|
mutate_arguments
|
||||||
end
|
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
|
# Mutate arguments
|
||||||
#
|
#
|
||||||
# @return [undefined]
|
# @return [undefined]
|
||||||
|
|
31
lib/mutant/mutator/node/send/binary.rb
Normal file
31
lib/mutant/mutator/node/send/binary.rb
Normal 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
|
|
@ -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
|
|
Loading…
Add table
Reference in a new issue