Take care to not mutate self.class into class

This commit is contained in:
Markus Schirp 2012-12-29 22:51:42 +01:00
parent fce6d5c06e
commit a06030ef06
2 changed files with 32 additions and 5 deletions

View file

@ -29,7 +29,7 @@ module Mutant
# @api private
#
def emit_receiver
unless self?
unless to_self?
emit(receiver)
end
end
@ -53,7 +53,7 @@ module Mutant
# @api private
#
def emit_receiver_mutations
unless self?
unless to_self? or self_class?
emit_attribute_mutations(:receiver)
end
end
@ -93,17 +93,33 @@ module Mutant
# Check if receiver is self
#
# @return [true]
# returns true when receiver is a Rubinius::AST::Self node
# if receiver is a Rubinius::AST::Self node
#
# @return [false]
# return false otherwise
#
# @api private
#
def self?
def to_self?
receiver.kind_of?(Rubinius::AST::Self)
end
# Check if receiver is self.class
#
# @return [true]
# if receiver is a "self.class" construct
#
# @return [false]
# otherwise
#
# @api private
#
def self_class?
receiver.kind_of?(Rubinius::AST::Send) &&
receiver.name == :class &&
receiver.receiver.kind_of?(Rubinius::AST::Self)
end
# Emit mutation that replaces explicit send to self with implicit send to self
#
# @example:
@ -130,7 +146,7 @@ module Mutant
# @api private
#
def emit_implicit_self_receiver
return unless self?
return unless to_self?
mutant = dup_node
mutant.privately = true
# TODO: Fix rubinius to allow this as an attr_accessor

View file

@ -32,6 +32,17 @@ describe Mutant::Mutator, 'send' do
it_should_behave_like 'a mutator'
end
context 'to self.class.foo' do
let(:source) { 'self.class.foo' }
let(:mutations) do
mutations = []
mutations << 'self.class'
end
it_should_behave_like 'a mutator'
end
end
context 'send with arguments' do