Add Mutation class

This commit is contained in:
Markus Schirp 2012-08-16 04:09:14 +02:00
parent 6ed134ad38
commit 3a2c1ab7b5
2 changed files with 86 additions and 0 deletions

View file

@ -39,6 +39,7 @@ require 'mutant/support/method_object'
require 'mutant/random'
require 'mutant/mutator'
require 'mutant/mutation'
require 'mutant/mutator/registry'
require 'mutant/mutator/literal'
require 'mutant/mutator/literal/boolean'

85
lib/mutant/mutation.rb Normal file
View file

@ -0,0 +1,85 @@
module Mutant
# Represent a mutated node with its subject
class Mutation
include Immutable
# Return mutated root node
#
# @return [Rubinius::AST::Script]
#
# @api private
#
def root
@subject.root(@node)
end
memoize :root
# Insert mutated node
#
# @return [self]
#
# @api private
#
def insert
Loader.run(root)
self
end
# Return identification
#
# @return [String]
#
# @api private
#
def identification
"#{@subject.identification}:#{sha1[0..4]}"
end
# Return sha1 sum of source
#
# @return [String]
#
# @api private
#
def sha1
SHA1.hexdigest(source)
end
memoize :sha1
# Return source
#
# @return [String]
#
# @api private
#
def source
@node.to_source
end
memoize :source
# Return original source
#
# @return [String]
#
# @api private
#
def original_source
@subject.source
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
end
end