Sha256: af7c7785f8a869d170eb4c9b99874358e3f5a9932613020ec198fa1a85d3bd49

Contents?: true

Size: 1.91 KB

Versions: 7

Compression:

Stored size: 1.91 KB

Contents

module Mutant
  # Subject of a mutation
  class Subject
    include AbstractType, Adamantium::Flat, Enumerable, Concord::Public.new(:context, :node)

    # Enumerate possible mutations
    #
    # @return [self]
    #   returns self if block given
    #
    # @return [Enumerator<Mutation>]
    #   returns eumerator if no block given
    #
    # @api private
    #
    def each
      return to_enum unless block_given?
      Mutator.each(node) do |mutant|
        yield Mutation::Evil.new(self, mutant)
      end

      self
    end

    # Return noop mutation
    #
    # @return [Mutation::Noop]
    #
    # @api private
    #
    def noop
      Mutation::Neutral.new(self, node)
    end
    memoize :noop

    # Return source path
    #
    # @return [String]
    #
    # @api private
    #
    def source_path
      context.source_path
    end

    # Return source line
    #
    # @return [Fixnum]
    #
    # @api private
    #
    def source_line
      node.location.expression.line
    end

    # Return subject identification
    #
    # @return [String]
    #
    # @api private
    #
    def identification
      "#{subtype}:#{source_path}:#{source_line}"
    end
    memoize :identification

    # Return source representation of ast
    #
    # @return [String]
    #
    # @api private
    #
    def source
      Unparser.unparse(node)
    end
    memoize :source

    # Return root AST for node
    #
    # @param [Parser::AST::Node] node
    #
    # @return [Parser::AST::Node]
    #
    # @api private
    #
    def root(node)
      context.root(node)
    end

    # Return root AST node for original AST ndoe
    #
    # @return [Parser::AST::Node]
    #
    # @api private
    #
    def original_root
      root(node)
    end
    memoize :original_root

  private

    # Return subtype identifier
    #
    # @return [String]
    #
    # @api private
    #
    abstract_method :subtype
    private :subtype

  end # Subject
end # Mutant

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
mutant-0.3.0.beta8 lib/mutant/subject.rb
mutant-0.3.0.beta7 lib/mutant/subject.rb
mutant-0.3.0.beta6 lib/mutant/subject.rb
mutant-0.3.0.beta5 lib/mutant/subject.rb
mutant-0.3.0.beta4 lib/mutant/subject.rb
mutant-0.3.0.beta3 lib/mutant/subject.rb
mutant-0.3.0.beta2 lib/mutant/subject.rb