2012-08-15 22:09:14 -04:00
|
|
|
module Mutant
|
|
|
|
# Represent a mutated node with its subject
|
|
|
|
class Mutation
|
2012-11-02 21:12:33 -04:00
|
|
|
include Adamantium::Flat, Equalizer.new(:sha1)
|
2012-08-15 22:09:14 -04:00
|
|
|
|
2012-08-20 11:53:41 -04:00
|
|
|
# Return mutation subject
|
|
|
|
#
|
|
|
|
# @return [Subject]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2012-10-26 05:24:29 -04:00
|
|
|
attr_reader :subject
|
2012-08-20 11:53:41 -04:00
|
|
|
|
2012-08-29 07:33:47 -04:00
|
|
|
# Return mutated node
|
|
|
|
#
|
2012-10-26 05:24:29 -04:00
|
|
|
# @return [Rubinius::AST::Node]
|
2012-08-29 07:33:47 -04:00
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2012-10-26 05:24:29 -04:00
|
|
|
attr_reader :node
|
2012-08-29 07:33:47 -04:00
|
|
|
|
2012-08-15 22:09:14 -04:00
|
|
|
# Return mutated root node
|
|
|
|
#
|
2012-11-21 14:31:01 -05:00
|
|
|
# @return [Rubinius::AST::Node]
|
2012-08-15 22:09:14 -04:00
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def root
|
2012-10-26 05:24:29 -04:00
|
|
|
subject.root(node)
|
2012-08-15 22:09:14 -04:00
|
|
|
end
|
|
|
|
memoize :root
|
|
|
|
|
|
|
|
# Insert mutated node
|
|
|
|
#
|
|
|
|
# @return [self]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def insert
|
2012-12-14 13:53:37 -05:00
|
|
|
Loader::Eval.run(root, subject.source_path, subject.source_line)
|
2012-08-15 22:09:14 -04:00
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
# Return identification
|
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def identification
|
2012-08-29 07:33:47 -04:00
|
|
|
"#{subject.identification}:#{code}"
|
|
|
|
end
|
|
|
|
memoize :identification
|
|
|
|
|
|
|
|
# Return mutation code
|
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def code
|
|
|
|
sha1[0..4]
|
2012-08-15 22:09:14 -04:00
|
|
|
end
|
2012-08-29 07:33:47 -04:00
|
|
|
memoize :code
|
2012-08-15 22:09:14 -04:00
|
|
|
|
2012-08-29 07:33:47 -04:00
|
|
|
# Return sha1 sum of source and subject identification
|
2012-08-15 22:09:14 -04:00
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def sha1
|
2012-11-21 16:28:08 -05:00
|
|
|
Digest::SHA1.hexdigest(subject.identification + source)
|
2012-08-15 22:09:14 -04:00
|
|
|
end
|
|
|
|
memoize :sha1
|
|
|
|
|
|
|
|
# Return source
|
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def source
|
2012-10-26 05:24:29 -04:00
|
|
|
ToSource.to_source(node)
|
2012-08-15 22:09:14 -04:00
|
|
|
end
|
|
|
|
memoize :source
|
|
|
|
|
|
|
|
# Return original source
|
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def original_source
|
2012-08-20 11:53:41 -04:00
|
|
|
subject.source
|
2012-08-15 22:09:14 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# Initialize mutation object
|
|
|
|
#
|
|
|
|
# @param [Subject] subject
|
|
|
|
# @param [Rubinius::Node::AST] node
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def initialize(subject, node)
|
|
|
|
@subject, @node = subject, node
|
|
|
|
end
|
2012-12-10 18:17:19 -05:00
|
|
|
|
|
|
|
class Noop < self
|
|
|
|
|
|
|
|
# Initialihe object
|
|
|
|
#
|
|
|
|
# @param [Subject] subject
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def initialize(subject)
|
|
|
|
super(subject, subject.node)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Return identification
|
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def identification
|
|
|
|
"noop:#{super}"
|
|
|
|
end
|
|
|
|
memoize :identification
|
|
|
|
end
|
2012-08-15 22:09:14 -04:00
|
|
|
end
|
|
|
|
end
|