Sha256: b48108d7a91b3a2d78da2ed98282e31766ccf41a69330b045be6f33e7ed0c37e

Contents?: true

Size: 1.62 KB

Versions: 8

Compression:

Stored size: 1.62 KB

Contents

module Mutest
  class Mutator
    class Node
      # Mutation emitter to handle binary connectives
      class Binary < self
        INVERSE = {
          and: :or,
          or:  :and
        }.freeze

        handle(*INVERSE.keys)

        children :left, :right

        private

        # Emit mutations
        #
        # @return [undefined]
        def dispatch
          emit_singletons
          emit_promotions
          emit_operator_mutations
          emit_left_negation
          emit_left_mutations
          emit_right_mutations
        end

        # Emit operator mutations
        #
        # @return [undefined]
        def emit_operator_mutations
          emit(s(INVERSE.fetch(node.type), left, right))
        end

        # Emit promotions
        #
        # @return [undefined]
        def emit_promotions
          emit(left)
          emit(right)
        end

        # Emit left negation
        #
        # We do not emit right negation as the `and` and `or` nodes
        # in ruby are also used for control flow.
        #
        # Irrespective of their syntax, aka `||` parses internally to `or`.
        #
        # `do_a or do_b`. Negating left makes sense, negating right
        # only when the result is actually used.
        #
        # It *would* be possible to emit the right negation in case the use of the result is proved.
        # Like parent is an assignment to an {l,i}var. Dunno if we ever get the time to do that.
        #
        # @return [undefined]
        def emit_left_negation
          emit(s(node.type, n_not(left), right))
        end
      end # Binary
    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/binary.rb
mutest-0.0.8 lib/mutest/mutator/node/binary.rb
mutest-0.0.7 lib/mutest/mutator/node/binary.rb
mutest-0.0.6 lib/mutest/mutator/node/binary.rb
mutest-0.0.5 lib/mutest/mutator/node/binary.rb
mutest-0.0.4 lib/mutest/mutator/node/binary.rb
mutest-0.0.3 lib/mutest/mutator/node/binary.rb
mutest-0.0.2 lib/mutest/mutator/node/binary.rb