Sha256: 2a63c1195d1b9da34d2c2b818ff264344a83ccaa2a0d9a59407fa39c1d977a6e

Contents?: true

Size: 1.78 KB

Versions: 6

Compression:

Stored size: 1.78 KB

Contents

module Mutant
  class Mutator
    class Node
      class Send

        # Mutator for send with arguments
        class WithArguments < self
          
          handle(Rubinius::AST::SendWithArguments)

        private

          # Emit mutations
          #
          # @return [undefined]
          #
          # @api private
          #
          def dispatch
            super

            if binary_operator?
              run(BinaryOperatorMethod)
              return
            end

            emit_send_remove_mutation
            emit_argument_mutations
          end

          # Test if message is a binary operator
          #
          # @return [true]
          #   if message is a binary operator
          #
          # @return [false]
          #   otherwise
          #
          # @api private
          #
          def binary_operator?
            Mutant::BINARY_METHOD_OPERATORS.include?(node.name)
          end

          # Emit argument mutations
          #
          # @api private
          #
          # @return [undefined]
          #
          # @api private
          #
          def emit_argument_mutations
            emit_attribute_mutations(:arguments) do |mutation|
              if mutation.arguments.array.empty?
                mutation = new_send(receiver, node.name)
                mutation.privately = node.privately
                mutation
              else
                mutation
              end
            end
          end

          # Emit send remove mutation
          #
          # @return [undefined]
          #
          # @api private
          #
          def emit_send_remove_mutation
            array = node.arguments.array
            return unless array.length == 1
            emit(array.first)
          end
        end

      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
mutant-0.2.20 lib/mutant/mutator/node/send/with_arguments.rb
mutant-0.2.17 lib/mutant/mutator/node/send/with_arguments.rb
mutant-0.2.16 lib/mutant/mutator/node/send/with_arguments.rb
mutant-0.2.15 lib/mutant/mutator/node/send/with_arguments.rb
mutant-0.2.14 lib/mutant/mutator/node/send/with_arguments.rb
mutant-0.2.13 lib/mutant/mutator/node/send/with_arguments.rb