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-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
|
|
|
|
#
|
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
|
|
|
|
"#{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
|
|
|
|
@node.to_source
|
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
|
|
|
|
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
|
|
|
#
|
|
|
|
# @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
|