Sha256: b3894e778f009c433586de8546cc109260a260b2df43cc704e174218ce576c02

Contents?: true

Size: 1.27 KB

Versions: 8

Compression:

Stored size: 1.27 KB

Contents

module Mutest
  class Mutator
    class Node
      # OpAsgn mutator
      class OpAsgn < self
        handle(:op_asgn)

        children :left, :operation, :right

        private

        # Emit mutations
        #
        # @return [undefined]
        def dispatch
          emit_singletons
          emit_left_mutations do |node|
            !n_self?(node)
          end
          emit_right_mutations
          emit_compound_assignment_mutations
        end

        # Mutate compound assignments like `+=` to `+` and `=`
        def emit_compound_assignment_mutations
          case left.type
          when :lvasgn then emit_lvar_mutation
          when :ivasgn then emit_ivar_mutation
          when :send   then emit_send_mutation
          end
        end

        def emit_lvar_mutation
          emit(s(:send, s(:send, nil, *left), operation, right))
          emit(s(:lvasgn, *left, right))
        end

        def emit_ivar_mutation
          emit(s(:send, s(:ivar, *left), operation, right))
          emit(s(:ivasgn, *left, right))
        end

        def emit_send_mutation
          emit(s(:send, left, operation, right))
          emit(s(:send, left.children.first, :"#{left.children.last}=", right))
        end
      end # OpAsgn
    end # Node
  end # Mutator
end # Mutest

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
mutest-0.0.9 lib/mutest/mutator/node/op_asgn.rb
mutest-0.0.8 lib/mutest/mutator/node/op_asgn.rb
mutest-0.0.7 lib/mutest/mutator/node/op_asgn.rb
mutest-0.0.6 lib/mutest/mutator/node/op_asgn.rb
mutest-0.0.5 lib/mutest/mutator/node/op_asgn.rb
mutest-0.0.4 lib/mutest/mutator/node/op_asgn.rb
mutest-0.0.3 lib/mutest/mutator/node/op_asgn.rb
mutest-0.0.2 lib/mutest/mutator/node/op_asgn.rb