2012-07-26 19:25:23 +02:00
|
|
|
module Mutant
|
|
|
|
# Mutate rubinius AST nodes
|
|
|
|
class Mutator
|
2012-07-27 22:39:31 +02:00
|
|
|
include Enumerable, Veritas::Immutable
|
|
|
|
|
|
|
|
# Build mutation node
|
|
|
|
#
|
|
|
|
# @param [Rubinius::AST::Node] node
|
|
|
|
#
|
|
|
|
# @return [Mutator]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def self.build(node)
|
|
|
|
mutator(node).new(node)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Return mutator for node or raise
|
|
|
|
#
|
|
|
|
# @param [Rubinius::AST::Node] node
|
|
|
|
#
|
|
|
|
# @return [Mutator]
|
|
|
|
#
|
2012-07-30 22:39:03 +02:00
|
|
|
# @raise [NameError]
|
|
|
|
# raises NameError if mutator for node cannot be found
|
2012-07-27 22:39:31 +02:00
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def self.mutator(node)
|
|
|
|
unqualified_name = node.class.name.split('::').last
|
2012-07-29 22:29:24 +02:00
|
|
|
const_get(unqualified_name)
|
2012-07-27 22:39:31 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
# Enumerate mutated asts
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2012-07-30 22:39:03 +02:00
|
|
|
# @return [self]
|
|
|
|
# returns self if block given
|
|
|
|
#
|
|
|
|
# @return [Enumerator<Rubnius::AST::Node>]
|
|
|
|
# returns enumerator on AST nodes otherwise
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2012-07-27 22:39:31 +02:00
|
|
|
def each(&block)
|
2012-07-29 18:03:44 +02:00
|
|
|
return to_enum unless block_given?
|
2012-07-30 21:40:49 +02:00
|
|
|
mutants(Generator.new(@node,block))
|
2012-07-27 22:39:31 +02:00
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# Return wrapped node
|
|
|
|
#
|
|
|
|
# @return [Rubinius::AST::Node]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
attr_reader :node
|
|
|
|
|
|
|
|
# Initialize mutator with
|
2012-07-26 19:25:23 +02:00
|
|
|
#
|
|
|
|
# @param [Rubinius::AST::Node] node
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def initialize(node)
|
|
|
|
@node = node
|
|
|
|
end
|
|
|
|
|
2012-07-27 22:39:31 +02:00
|
|
|
# Create a new AST node
|
|
|
|
#
|
|
|
|
# @param [Rubinis::AST::Node:Class] node_class
|
|
|
|
#
|
|
|
|
# @return [Rubinius::AST::Node]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def new(node_class,*arguments)
|
|
|
|
node_class.new(node.line,*arguments)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Create a new AST node with same class as wrapped node
|
|
|
|
#
|
|
|
|
# @return [Rubinius::AST::Node]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def new_self(*arguments)
|
|
|
|
new(node.class,*arguments)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Create a new AST node with NilLiteral class
|
|
|
|
#
|
|
|
|
# @return [Rubinius::AST::NilLiteral]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def new_nil
|
|
|
|
new(Rubinius::AST::NilLiteral)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Append mutations
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
# @param [#<<] generator
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
def mutants(generator)
|
|
|
|
Mutant.not_implemented(self)
|
|
|
|
end
|
2012-07-26 19:25:23 +02:00
|
|
|
end
|
|
|
|
end
|