![Dan Kubb](/assets/img/avatar_default.png)
* rubocop still warns about this on ruby 1.9.3, so it was fixed so it produces less output on travis.
76 lines
1.7 KiB
Ruby
76 lines
1.7 KiB
Ruby
# encoding: utf-8
|
|
|
|
module Mutant
|
|
class Subject
|
|
class Method
|
|
# Instance method subjects
|
|
class Instance < self
|
|
|
|
NAME_INDEX = 0
|
|
SYMBOL = '#'.freeze
|
|
|
|
# Test if method is public
|
|
#
|
|
# @return [true]
|
|
# if method is public
|
|
#
|
|
# @return [false]
|
|
# otherwise
|
|
#
|
|
# @api private
|
|
#
|
|
def public?
|
|
scope.public_method_defined?(name)
|
|
end
|
|
memoize :public?
|
|
|
|
private
|
|
|
|
# Mutator for memoized instance methods
|
|
class Memoized < self
|
|
include NodeHelpers
|
|
|
|
private
|
|
|
|
# Return mutations
|
|
#
|
|
# @param [#<<] emitter
|
|
#
|
|
# @return [undefined]
|
|
#
|
|
# @api private
|
|
#
|
|
def generate_mutations(emitter)
|
|
emitter << noop_mutation
|
|
Mutator.each(node) do |mutant|
|
|
emitter << Mutation::Evil.new(self, memoizer_node(mutant))
|
|
end
|
|
end
|
|
|
|
# Return neutral mutation
|
|
#
|
|
# @return [Mutation::Neutral]
|
|
#
|
|
# @api private
|
|
#
|
|
def noop_mutation
|
|
Mutation::Neutral::Noop.new(self, memoizer_node(node))
|
|
end
|
|
|
|
# Return memoizer node for mutant
|
|
#
|
|
# @param [Parser::AST::Node] mutant
|
|
#
|
|
# @return [Parser::AST::Node]
|
|
#
|
|
# @api private
|
|
#
|
|
def memoizer_node(mutant)
|
|
s(:begin, mutant, s(:send, nil, :memoize, s(:args, s(:sym, name))))
|
|
end
|
|
|
|
end # Memoized
|
|
end # Instance
|
|
end # Method
|
|
end # Subject
|
|
end # Mutant
|