Sha256: 32667fc2e018015cb05ca9ae3eeb9fc6326265fce47ec8f777efc5a8235658be

Contents?: true

Size: 1.27 KB

Versions: 19

Compression:

Stored size: 1.27 KB

Contents

module Mutant
  class Mutator
    class Node
      module NamedValue

        # Mutation emitter to handle variable assignment nodes
        class VariableAssignment < Node

          children :name, :value

          map = {
            gvasgn: '$',
            cvasgn: '@@',
            ivasgn: '@',
            lvasgn: EMPTY_STRING
          }

          MAP = IceNine.deep_freeze(
            Hash[map.map { |type, prefix| [type, [prefix, /^#{Regexp.escape(prefix)}/]] }]
          )

          handle(*MAP.keys)

        private

          # Perform dispatch
          #
          # @return [undefined]
          #
          # @api private
          #
          def dispatch
            emit_singletons
            mutate_name
            emit_value_mutations if value # mlhs!
          end

          # Emit name mutations
          #
          # @return [undefined]
          #
          # @api private
          #
          def mutate_name
            prefix, regexp = MAP.fetch(node.type)
            stripped = name.to_s.sub(regexp, EMPTY_STRING)
            Mutator::Util::Symbol.each(stripped, self) do |name|
              emit_name(:"#{prefix}#{name}")
            end
          end

        end # VariableAssignment
      end # NamedValue
    end # Node
  end # Mutator
end # Mutant

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
mutant-0.8.0 lib/mutant/mutator/node/named_value/variable_assignment.rb
mutant-0.7.9 lib/mutant/mutator/node/named_value/variable_assignment.rb
mutant-0.7.8 lib/mutant/mutator/node/named_value/variable_assignment.rb
mutant-0.7.7 lib/mutant/mutator/node/named_value/variable_assignment.rb
mutant-0.7.6 lib/mutant/mutator/node/named_value/variable_assignment.rb
mutant-0.7.5 lib/mutant/mutator/node/named_value/variable_assignment.rb
mutant-0.7.4 lib/mutant/mutator/node/named_value/variable_assignment.rb
mutant-0.7.3 lib/mutant/mutator/node/named_value/variable_assignment.rb
mutant-0.7.2 lib/mutant/mutator/node/named_value/variable_assignment.rb
mutant-0.7.1 lib/mutant/mutator/node/named_value/variable_assignment.rb
mutant-0.6.7 lib/mutant/mutator/node/named_value/variable_assignment.rb
mutant-0.6.6 lib/mutant/mutator/node/named_value/variable_assignment.rb
mutant-0.6.5 lib/mutant/mutator/node/named_value/variable_assignment.rb
mutant-0.6.4 lib/mutant/mutator/node/named_value/variable_assignment.rb
mutant-0.6.3 lib/mutant/mutator/node/named_value/variable_assignment.rb
mutant-0.6.2 lib/mutant/mutator/node/named_value/variable_assignment.rb
mutant-0.6.0 lib/mutant/mutator/node/named_value/variable_assignment.rb
mutant-0.5.26 lib/mutant/mutator/node/named_value/variable_assignment.rb
mutant-0.5.25 lib/mutant/mutator/node/named_value/variable_assignment.rb