diff --git a/TODO b/TODO index 758846a7..b15df81c 100644 --- a/TODO +++ b/TODO @@ -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: diff --git a/lib/mutant.rb b/lib/mutant.rb index 52a0c10c..c7251463 100644 --- a/lib/mutant.rb +++ b/lib/mutant.rb @@ -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' diff --git a/lib/mutant/mutator/node/send.rb b/lib/mutant/mutator/node/send.rb index 168f3ebf..df62d059 100644 --- a/lib/mutant/mutator/node/send.rb +++ b/lib/mutant/mutator/node/send.rb @@ -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] diff --git a/lib/mutant/mutator/node/send/binary.rb b/lib/mutant/mutator/node/send/binary.rb new file mode 100644 index 00000000..b263af95 --- /dev/null +++ b/lib/mutant/mutator/node/send/binary.rb @@ -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 diff --git a/lib/mutant/mutator/node/send/binary_operator_method.rb b/lib/mutant/mutator/node/send/binary_operator_method.rb deleted file mode 100644 index 66db6ecb..00000000 --- a/lib/mutant/mutator/node/send/binary_operator_method.rb +++ /dev/null @@ -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