2012-07-26 13:25:23 -04:00
|
|
|
module Mutant
|
2012-11-21 16:28:08 -05:00
|
|
|
# Subject of a mutation
|
2012-08-01 12:34:03 -04:00
|
|
|
class Subject
|
2013-01-13 16:25:49 -05:00
|
|
|
include AbstractType, Adamantium::Flat, Enumerable, Equalizer.new(:context, :node)
|
2012-07-26 13:25:23 -04:00
|
|
|
|
|
|
|
# Return context
|
|
|
|
#
|
|
|
|
# @return [Context]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2012-10-26 05:24:29 -04:00
|
|
|
attr_reader :context
|
2012-08-20 11:53:41 -04:00
|
|
|
|
2012-07-26 13:25:23 -04:00
|
|
|
# Return AST node
|
|
|
|
#
|
|
|
|
# @return [Rubinius::AST::Node]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2012-10-26 05:24:29 -04:00
|
|
|
attr_reader :node
|
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|
|
2013-01-15 17:46:05 -05:00
|
|
|
yield Mutation::Evil.new(self, mutant)
|
2012-08-01 12:19:12 -04:00
|
|
|
end
|
2012-07-26 13:25:23 -04:00
|
|
|
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
2012-12-10 18:17:19 -05:00
|
|
|
# Return noop mutation
|
|
|
|
#
|
|
|
|
# @return [Mutation::Noop]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def noop
|
2013-01-15 17:46:05 -05:00
|
|
|
Mutation::Neutral.new(self, node)
|
2012-12-10 18:17:19 -05:00
|
|
|
end
|
|
|
|
memoize :noop
|
|
|
|
|
2012-12-14 13:53:37 -05:00
|
|
|
# Return source path
|
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def source_path
|
|
|
|
context.source_path
|
|
|
|
end
|
|
|
|
|
|
|
|
# Return source line
|
|
|
|
#
|
|
|
|
# @return [Fixnum]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def source_line
|
|
|
|
node.line
|
|
|
|
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
|
2013-01-14 07:36:26 -05:00
|
|
|
"#{subtype}:#{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-10-26 05:24:29 -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
|
2012-10-26 05:24:29 -04:00
|
|
|
root(node)
|
2012-08-15 22:10:54 -04:00
|
|
|
end
|
|
|
|
memoize :original_root
|
|
|
|
|
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
|
|
|
#
|
2013-01-13 16:25:49 -05:00
|
|
|
# @param [Mutant::Context] context
|
2012-07-26 13:25:23 -04:00
|
|
|
#
|
|
|
|
# @param [Rubinius::AST::Node] node
|
2013-01-13 16:25:49 -05:00
|
|
|
# the original node to be mutated
|
2012-07-26 13:25:23 -04:00
|
|
|
#
|
|
|
|
# @return [unkown]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2013-01-13 16:25:49 -05:00
|
|
|
def initialize(context, node)
|
|
|
|
@context, @node = context, node
|
2012-07-26 13:25:23 -04:00
|
|
|
end
|
2012-08-29 07:38:14 -04:00
|
|
|
|
2013-01-13 16:25:49 -05:00
|
|
|
# Return subtype identifier
|
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
abstract_method :subtype
|
|
|
|
private :subtype
|
|
|
|
|
2012-07-26 13:25:23 -04:00
|
|
|
end
|
|
|
|
end
|