2012-08-01 07:27:35 -04:00
|
|
|
module Mutant
|
|
|
|
class Mutator
|
|
|
|
# Registry for mutators
|
|
|
|
module Registry
|
|
|
|
# Return registry state
|
|
|
|
#
|
|
|
|
# @return [Hash]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def self.registry
|
|
|
|
@registry ||= {}
|
|
|
|
end
|
|
|
|
private_class_method :registry
|
|
|
|
|
|
|
|
# Register mutator class for AST node class
|
|
|
|
#
|
|
|
|
# @param [Class] ast_class
|
|
|
|
# @param [Class] mutator_class
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
# @return [self]
|
|
|
|
#
|
|
|
|
def self.register(ast_class,mutator_class)
|
|
|
|
registry[ast_class]=mutator_class
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
2013-06-04 13:26:53 -04:00
|
|
|
# Lookup mutator class for node
|
2012-08-01 07:27:35 -04:00
|
|
|
#
|
2013-06-04 13:26:53 -04:00
|
|
|
# @param [Parser::AST::Node] node
|
2012-08-01 07:27:35 -04:00
|
|
|
#
|
|
|
|
# @return [Class]
|
|
|
|
#
|
|
|
|
# @raise [ArgumentError]
|
|
|
|
# raises argument error when mutator class cannot be found
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2013-06-04 13:26:53 -04:00
|
|
|
def self.lookup(node)
|
|
|
|
type = node.type
|
|
|
|
registry.fetch(type) do
|
|
|
|
raise ArgumentError,"No mutator to handle: #{type.inspect}"
|
2012-08-01 07:27:35 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|