free_mutant/lib/mutant/subject/method/instance.rb
Markus Schirp a19f3b1691 Nuke UTF-8 encoding headers
* I do not use 1.9.3
* Also keeping them in each file increases mental overhead (true it *can* be autoamted)
* None of the files encodes NON ASCII chars.
* I do not expect it makes any difference, since nobody programmatically
  will consume strings generated by mutant under the assumption they are UTF-8 encoded.
* 1.9.3 Users have to deal with the encoding fuckup under ruby anyways.
2014-06-09 15:37:48 +00:00

114 lines
2.7 KiB
Ruby

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?
# Prepare subject for mutation insertion
#
# @return [self]
#
# @api private
#
def prepare
expected_warnings =
if RUBY_ENGINE.eql?('ruby') && name.equal?(:initialize)
["#{__FILE__}:#{__LINE__ + 5}: warning: undefining `initialize' may cause serious problems\n"]
else
[]
end
WarningExpectation.new(expected_warnings).execute do
scope.send(:undef_method, name)
end
self
end
# Mutator for memoized instance methods
class Memoized < self
include NodeHelpers
# Return source
#
# @return [String]
#
# @api private
#
def source
Unparser.unparse(memoizer_node(node))
end
memoize :source
# Prepare subject for mutation insertion
#
# @return [self]
#
# @api private
#
def prepare
scope.send(:memoized_methods).instance_variable_get(:@memory).delete(name)
super
self
end
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