Sha256: dd92b1a559b530635a47a8d7add43eda69cdc97a514b8d5c26efa9df811dbaed

Contents?: true

Size: 1.25 KB

Versions: 17

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

module Mutant
  # Generator for mutations
  class Mutator

    REGISTRY = Registry.new(->(_) { Node::Generic })

    include(
      Adamantium,
      Concord.new(:input, :parent),
      AbstractType,
      Procto
    )

    # Lookup and invoke dedicated AST mutator
    #
    # @param node [Parser::AST::Node]
    # @param parent [nil,Mutant::Mutator::Node]
    #
    # @return [Set<Parser::AST::Node>]
    def self.mutate(node, parent = nil)
      self::REGISTRY.lookup(node.type).call(node, parent)
    end

    def self.handle(*types)
      types.each do |type|
        self::REGISTRY.register(type, self)
      end
    end
    private_class_method :handle

    # Return output
    #
    # @return [Set<Parser::AST::Node>]
    attr_reader :output

    alias_method :call, :output

  private

    def initialize(_input, _parent = nil)
      super

      @output = Set.new

      dispatch
    end

    def new?(object)
      !object.eql?(input)
    end

    abstract_method :dispatch
    private :dispatch

    def emit(object)
      return unless new?(object)

      output << object
    end

    def run(mutator)
      mutator.call(input).each(&method(:emit))
    end

    def dup_input
      input.dup
    end

  end # Mutator
end # Mutant

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
mutant-0.11.11 lib/mutant/mutator.rb
mutant-0.11.10 lib/mutant/mutator.rb
mutant-0.11.9 lib/mutant/mutator.rb
mutant-0.11.8 lib/mutant/mutator.rb
mutant-0.11.7 lib/mutant/mutator.rb
mutant-0.11.6 lib/mutant/mutator.rb
mutant-0.11.5 lib/mutant/mutator.rb
mutant-0.11.4 lib/mutant/mutator.rb
mutant-0.11.3 lib/mutant/mutator.rb
mutant-0.11.2 lib/mutant/mutator.rb
mutant-0.11.1 lib/mutant/mutator.rb
mutant-0.11.0 lib/mutant/mutator.rb
mutant-0.10.35 lib/mutant/mutator.rb
mutant-0.10.34 lib/mutant/mutator.rb
mutant-0.10.33 lib/mutant/mutator.rb
mutant-0.10.32 lib/mutant/mutator.rb
mutant-0.10.31 lib/mutant/mutator.rb