2012-07-26 13:25:23 -04:00
|
|
|
module Mutant
|
2012-08-15 22:10:54 -04:00
|
|
|
# Subject of mutation
|
2012-08-01 12:34:03 -04:00
|
|
|
class Subject
|
2012-10-15 08:36:15 -04:00
|
|
|
include Adamantium, Enumerable
|
2012-07-26 13:25:23 -04:00
|
|
|
|
|
|
|
# Return context
|
|
|
|
#
|
|
|
|
# @return [Context]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2012-08-20 11:53:41 -04:00
|
|
|
def context; @context; end
|
|
|
|
|
|
|
|
# Return matcher
|
|
|
|
#
|
|
|
|
# @return [Matcher]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def matcher; @matcher; end
|
2012-07-26 13:25:23 -04:00
|
|
|
|
|
|
|
# Return AST node
|
|
|
|
#
|
|
|
|
# @return [Rubinius::AST::Node]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2012-08-20 11:53:41 -04:00
|
|
|
def node; @node; end
|
2012-07-26 13:25:23 -04:00
|
|
|
|
|
|
|
# Enumerate possible mutations
|
|
|
|
#
|
|
|
|
# @return [self]
|
|
|
|
# returns self if block given
|
|
|
|
#
|
2012-08-15 22:10:54 -04:00
|
|
|
# @return [Enumerator<Mutation>]
|
2012-07-26 13:25:23 -04:00
|
|
|
# returns eumerator if no block given
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
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|
|
2012-08-15 22:10:54 -04:00
|
|
|
yield Mutation.new(self, mutant)
|
2012-08-01 12:19:12 -04:00
|
|
|
end
|
2012-07-26 13:25:23 -04:00
|
|
|
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
2012-08-15 22:10:54 -04:00
|
|
|
# Return subject identicication
|
2012-07-26 13:25:23 -04:00
|
|
|
#
|
2012-08-15 22:10:54 -04:00
|
|
|
# @return [String]
|
2012-07-26 13:25:23 -04:00
|
|
|
#
|
|
|
|
# @api private
|
2012-07-30 22:10:37 -04:00
|
|
|
#
|
2012-08-15 22:10:54 -04:00
|
|
|
def identification
|
|
|
|
source_path = context.source_path
|
|
|
|
source_line = node.line
|
2012-08-20 11:53:41 -04:00
|
|
|
"#{matcher.identification}:#{source_path}:#{source_line}"
|
2012-07-26 13:25:23 -04:00
|
|
|
end
|
2012-08-15 22:10:54 -04:00
|
|
|
memoize :identification
|
2012-07-26 13:25:23 -04:00
|
|
|
|
2012-08-15 22:10:54 -04:00
|
|
|
# Return source representation of ast
|
2012-08-14 06:27:56 -04:00
|
|
|
#
|
2012-08-15 22:10:54 -04:00
|
|
|
# @return [Source]
|
2012-08-14 06:27:56 -04:00
|
|
|
#
|
|
|
|
# @api private
|
2012-08-15 22:10:54 -04:00
|
|
|
#
|
|
|
|
def source
|
2012-08-19 17:43:31 -04:00
|
|
|
ToSource.to_source(@node)
|
2012-08-14 06:27:56 -04:00
|
|
|
end
|
2012-08-15 22:10:54 -04:00
|
|
|
memoize :source
|
2012-08-14 06:27:56 -04:00
|
|
|
|
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-08-15 22:10:54 -04:00
|
|
|
# Return root AST node for original AST ndoe
|
|
|
|
#
|
|
|
|
# @return [Rubinius::AST::Node]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def original_root
|
|
|
|
root(@node)
|
|
|
|
end
|
|
|
|
memoize :original_root
|
|
|
|
|
|
|
|
# Reset subject into original state
|
2012-08-16 13:26:15 -04:00
|
|
|
#
|
|
|
|
# @return [self]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2012-08-15 22:10:54 -04:00
|
|
|
def reset
|
|
|
|
Loader.run(original_root)
|
|
|
|
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
|
|
|
#
|
2012-08-20 11:53:41 -04:00
|
|
|
# @param [Matcher] matcher
|
2012-07-26 13:25:23 -04:00
|
|
|
# the context of mutations
|
|
|
|
#
|
|
|
|
# @param [Rubinius::AST::Node] node
|
|
|
|
# the node to be mutated
|
|
|
|
#
|
|
|
|
# @return [unkown]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2012-08-20 11:53:41 -04:00
|
|
|
def initialize(matcher, context, node)
|
|
|
|
@matcher, @context, @node = matcher, context, node
|
2012-07-26 13:25:23 -04:00
|
|
|
end
|
2012-08-29 07:38:14 -04:00
|
|
|
|
2012-07-26 13:25:23 -04:00
|
|
|
end
|
|
|
|
end
|