Sha256: 99fa712cfc8df09eb79b73e712909e9385d5af6020b4992950d967854d6b4e40

Contents?: true

Size: 1.77 KB

Versions: 5

Compression:

Stored size: 1.77 KB

Contents

module Mutant
  # Represent a mutated node with its subject
  class Mutation
    include Adamantium::Flat, Equalizer.new(:sha1)

    # Return mutation subject
    #
    # @return [Subject]
    #
    # @api private
    #
    attr_reader :subject

    # Return mutated node
    #
    # @return [Rubinius::AST::Node]
    #
    # @api private
    #
    attr_reader :node

    # Return mutated root node
    #
    # @return [Rubinius::AST::Node]
    #
    # @api private
    #
    def root
      subject.root(node)
    end
    memoize :root

    # Insert mutated node
    #
    # @return [self]
    #
    # @api private
    #
    def insert
      Loader::Eval.run(root)
      self
    end

    # Return identification
    #
    # @return [String]
    #
    # @api private
    #
    def identification
      "#{subject.identification}:#{code}"
    end
    memoize :identification

    # Return mutation code
    #
    # @return [String]
    #
    # @api private
    #
    def code
      sha1[0..4]
    end
    memoize :code

    # Return sha1 sum of source and subject identification
    #
    # @return [String]
    #
    # @api private
    #
    def sha1
      Digest::SHA1.hexdigest(subject.identification + source)
    end
    memoize :sha1

    # Return source
    #
    # @return [String]
    #
    # @api private
    #
    def source
      ToSource.to_source(node)
    end
    memoize :source

    # Return original source
    #
    # @return [String]
    #
    # @api private
    #
    def original_source
      subject.source
    end

  private

    # Initialize mutation object
    #
    # @param [Subject] subject
    # @param [Rubinius::Node::AST] node
    #
    # @return [undefined]
    #
    # @api private
    #
    def initialize(subject, node)
      @subject, @node = subject, node
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
mutant-0.2.4 lib/mutant/mutation.rb
mutant-0.2.3 lib/mutant/mutation.rb
mutant-0.2.2 lib/mutant/mutation.rb
mutant-0.2.1 lib/mutant/mutation.rb
mutant-0.2.0 lib/mutant/mutation.rb