Sha256: d17a43517dcc42544d06e4ebc94b713b2ed13e5a0defee01be9fb3dc9d41b306

Contents?: true

Size: 1.78 KB

Versions: 16

Compression:

Stored size: 1.78 KB

Contents

module Mutant
  class Mutator
    class Node
      # Mutator for rescue nodes
      class Rescue < self

        handle :rescue

        children :body

        define_named_child(:else_body, -1)

        RESCUE_INDICES = (1..-2).freeze

        # Emit mutations
        #
        # @return [undefined]
        #
        # @api private
        #
        def dispatch
          mutate_body
          mutate_rescue_bodies
          mutate_else_body
        end

      private

        # Mutate child by name
        #
        # @return [undefined]
        #
        # @api private
        #
        def mutate_rescue_bodies
          children_indices(RESCUE_INDICES).each do |index|
            rescue_body = children.at(index)
            next unless rescue_body
            mutate_child(index)
            resbody_body = AST::Meta.for(rescue_body).body
            emit_concat(resbody_body) if resbody_body
          end
        end

        # Emit concatenation with body
        #
        # @param [Parser::AST::Node] child
        #
        # @return [undefined]
        #
        # @api private
        #
        def emit_concat(child)
          if body
            emit(s(:begin, body, child))
          else
            emit(child)
          end
        end

        # Emit body mutations
        #
        # @return [undefined]
        #
        # @api private
        #
        def mutate_body
          return unless body
          emit_body_mutations
          emit(body)
        end

        # Emit else body mutations
        #
        # @return [undefined]
        #
        # @api private
        #
        def mutate_else_body
          return unless else_body
          emit_else_body_mutations
          emit_concat(else_body)
        end

      end # Rescue
    end # Node
  end # Mutator
end # Mutant

Version data entries

16 entries across 16 versions & 1 rubygems

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