Sha256: 1a8c77978e2c3a8aafab1b8b08c21134bf0f6252fd6b1892671ea4941be72625

Contents?: true

Size: 1.24 KB

Versions: 26

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

module Mutant
  class Mutator
    class Node
      class Block < self

        handle(:block)

        children :send, :arguments, :body

      private

        def dispatch
          emit_singletons
          emit(send) unless n_lambda?(send)
          emit_send_mutations(&method(:valid_send_mutation?))
          emit_arguments_mutations

          mutate_body
        end

        def mutate_body
          emit_body(nil)
          emit_body(N_RAISE)

          return unless body
          emit(body) unless body_has_control?
          emit_body_mutations

          mutate_body_receiver
        end

        def body_has_control?
          AST.find_last_path(body) do |node|
            n_break?(node) || n_next?(node)
          end.any?
        end

        def mutate_body_receiver
          return if n_lambda?(send) || !n_send?(body)

          body_meta = AST::Meta::Send.new(body)

          emit(s(:send, send, body_meta.selector, *body_meta.arguments))
        end

        def valid_send_mutation?(node)
          return unless n_send?(node)

          last = AST::Meta::Send.new(node).arguments.last

          !last&.type.equal?(:block_pass)
        end

      end # Block
    end # Node
  end # Mutator
end # Mutant

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
mutant-0.10.21 lib/mutant/mutator/node/block.rb
mutant-0.10.20 lib/mutant/mutator/node/block.rb
mutant-0.10.19 lib/mutant/mutator/node/block.rb
mutant-0.10.18 lib/mutant/mutator/node/block.rb
mutant-0.10.17 lib/mutant/mutator/node/block.rb
mutant-0.10.16 lib/mutant/mutator/node/block.rb
mutant-0.10.15 lib/mutant/mutator/node/block.rb
mutant-0.10.14 lib/mutant/mutator/node/block.rb
mutant-0.10.13 lib/mutant/mutator/node/block.rb
mutant-0.10.12 lib/mutant/mutator/node/block.rb
mutant-0.10.11 lib/mutant/mutator/node/block.rb
mutant-0.10.10 lib/mutant/mutator/node/block.rb
mutant-0.10.9 lib/mutant/mutator/node/block.rb
mutant-0.10.8 lib/mutant/mutator/node/block.rb
mutant-0.10.7 lib/mutant/mutator/node/block.rb
mutant-0.10.6 lib/mutant/mutator/node/block.rb
mutant-0.10.5 lib/mutant/mutator/node/block.rb
mutant-0.10.4 lib/mutant/mutator/node/block.rb
mutant-0.10.1 lib/mutant/mutator/node/block.rb
mutant-0.10.0 lib/mutant/mutator/node/block.rb