2012-07-26 13:25:23 -04:00
|
|
|
module Mutant
|
2012-08-01 12:34:03 -04:00
|
|
|
# Subject for mutation wraps AST to mutate with its Context
|
|
|
|
class Subject
|
2012-08-02 18:19:01 -04:00
|
|
|
include Immutable, Enumerable
|
2012-07-26 13:25:23 -04:00
|
|
|
|
|
|
|
# Return context
|
|
|
|
#
|
|
|
|
# @return [Context]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
attr_reader :context
|
|
|
|
|
|
|
|
# Return AST node
|
|
|
|
#
|
|
|
|
# @return [Rubinius::AST::Node]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
attr_reader :node
|
|
|
|
|
|
|
|
# Enumerate possible mutations
|
|
|
|
#
|
|
|
|
# @return [self]
|
|
|
|
# returns self if block given
|
|
|
|
#
|
|
|
|
# @return [Enumerator]
|
|
|
|
# returns eumerator if no block given
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2012-08-01 12:39:00 -04:00
|
|
|
# FIXME:
|
|
|
|
# Rubinus <=> Rspec bug
|
|
|
|
#
|
|
|
|
# Mutator.each(node,&block)
|
|
|
|
#
|
|
|
|
# results in rspec expectation mismatch
|
|
|
|
#
|
2012-08-01 12:19:12 -04:00
|
|
|
def each
|
2012-07-29 12:03:44 -04:00
|
|
|
return to_enum unless block_given?
|
2012-08-01 12:19:12 -04:00
|
|
|
Mutator.each(node) do |mutant|
|
|
|
|
yield mutant
|
|
|
|
end
|
2012-07-26 13:25:23 -04:00
|
|
|
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
2012-07-30 22:10:37 -04:00
|
|
|
# Reset implementation to original
|
2012-07-26 13:25:23 -04:00
|
|
|
#
|
2012-07-30 22:10:37 -04:00
|
|
|
# This method inserts the original node again.
|
2012-07-26 13:25:23 -04:00
|
|
|
#
|
|
|
|
# @return [self]
|
|
|
|
#
|
|
|
|
# @api private
|
2012-07-30 22:10:37 -04:00
|
|
|
#
|
2012-07-26 13:25:23 -04:00
|
|
|
def reset
|
|
|
|
insert(@node)
|
|
|
|
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
2012-08-14 06:27:56 -04:00
|
|
|
# Insert AST node under context
|
|
|
|
#
|
|
|
|
# @param [Rubinius::AST::Node] node
|
|
|
|
#
|
|
|
|
# @return [self]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def insert(node)
|
2012-08-14 16:45:34 -04:00
|
|
|
Loader.load(root(node))
|
2012-08-14 06:27:56 -04:00
|
|
|
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
2012-08-14 16:45:34 -04:00
|
|
|
# Return root AST for node
|
|
|
|
#
|
|
|
|
# @param [Rubinius::AST::Node] node
|
|
|
|
#
|
|
|
|
# @return [Rubinius::AST::Node]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def root(node)
|
|
|
|
context.root(node)
|
|
|
|
end
|
|
|
|
|
2012-07-30 22:10:37 -04:00
|
|
|
private
|
2012-07-26 13:25:23 -04:00
|
|
|
|
2012-08-01 12:34:03 -04:00
|
|
|
# Initialize subject
|
2012-07-26 13:25:23 -04:00
|
|
|
#
|
|
|
|
# @param [Context] context
|
|
|
|
# the context of mutations
|
|
|
|
#
|
|
|
|
# @param [Rubinius::AST::Node] node
|
|
|
|
# the node to be mutated
|
|
|
|
#
|
|
|
|
# @return [unkown]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2012-07-30 22:10:37 -04:00
|
|
|
def initialize(context, node)
|
|
|
|
@context, @node = context, node
|
2012-07-26 13:25:23 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|