class Mutest::Context

An abstract context where mutations can be applied to.

Constants

NAMESPACE_DELIMITER

Attributes

scope[R]

Scope wrapped by context

@return [Module,Class]

Public Class Methods

wrap(scope, node) click to toggle source

Wrap node into ast node

@param [Class, Module] scope @param [Parser::AST::Node] node

@return [Parser::AST::Class]

if scope is of kind Class

@return [Parser::AST::Module]

if scope is of kind module
# File lib/mutest/context.rb, line 36
def self.wrap(scope, node)
  name = s(:const, nil, scope.name.split(NAMESPACE_DELIMITER).last.to_sym)
  case scope
  when Class
    s(:class, name, nil, node)
  when Module
    s(:module, name, node)
  end
end

Public Instance Methods

identification() click to toggle source

Identification string

@return [String]

# File lib/mutest/context.rb, line 22
def identification
  scope.name
end
ignore?(node) click to toggle source
# File lib/mutest/context.rb, line 81
def ignore?(node)
  source_file.ignore?(node)
end
match_expressions() click to toggle source

Match expressions for scope

@return [Enumerable<Expression>]

# File lib/mutest/context.rb, line 67
def match_expressions
  name_nesting.each_index.reverse_each.map do |index|
    Expression::Namespace::Recursive.new(
      scope_name: name_nesting.take(index.succ).join(NAMESPACE_DELIMITER)
    )
  end
end
nesting() click to toggle source

Nesting of scope

@return [Enumerable<Class,Module>]

# File lib/mutest/context.rb, line 49
def nesting
  const = Object
  name_nesting.map do |name|
    const = const.const_get(name)
  end
end
root(node) click to toggle source

Return root node for mutation

@return [Parser::AST::Node]

# File lib/mutest/context.rb, line 13
def root(node)
  nesting.reverse.reduce(node) do |current, scope|
    self.class.wrap(scope, current)
  end
end
source_path() click to toggle source
# File lib/mutest/context.rb, line 85
def source_path
  source_file.path
end
unqualified_name() click to toggle source

Unqualified name of scope

@return [String]

# File lib/mutest/context.rb, line 60
def unqualified_name
  name_nesting.last
end

Private Instance Methods

name_nesting() click to toggle source

Nesting of names in scope

@return [Array<String>]

# File lib/mutest/context.rb, line 94
def name_nesting
  scope.name.split(NAMESPACE_DELIMITER)
end