Take care to not mutate self.class
into class
This commit is contained in:
parent
fce6d5c06e
commit
a06030ef06
2 changed files with 32 additions and 5 deletions
|
@ -29,7 +29,7 @@ module Mutant
|
||||||
# @api private
|
# @api private
|
||||||
#
|
#
|
||||||
def emit_receiver
|
def emit_receiver
|
||||||
unless self?
|
unless to_self?
|
||||||
emit(receiver)
|
emit(receiver)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -53,7 +53,7 @@ module Mutant
|
||||||
# @api private
|
# @api private
|
||||||
#
|
#
|
||||||
def emit_receiver_mutations
|
def emit_receiver_mutations
|
||||||
unless self?
|
unless to_self? or self_class?
|
||||||
emit_attribute_mutations(:receiver)
|
emit_attribute_mutations(:receiver)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -93,17 +93,33 @@ module Mutant
|
||||||
# Check if receiver is self
|
# Check if receiver is self
|
||||||
#
|
#
|
||||||
# @return [true]
|
# @return [true]
|
||||||
# returns true when receiver is a Rubinius::AST::Self node
|
# if receiver is a Rubinius::AST::Self node
|
||||||
#
|
#
|
||||||
# @return [false]
|
# @return [false]
|
||||||
# return false otherwise
|
# return false otherwise
|
||||||
#
|
#
|
||||||
# @api private
|
# @api private
|
||||||
#
|
#
|
||||||
def self?
|
def to_self?
|
||||||
receiver.kind_of?(Rubinius::AST::Self)
|
receiver.kind_of?(Rubinius::AST::Self)
|
||||||
end
|
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
|
# Emit mutation that replaces explicit send to self with implicit send to self
|
||||||
#
|
#
|
||||||
# @example:
|
# @example:
|
||||||
|
@ -130,7 +146,7 @@ module Mutant
|
||||||
# @api private
|
# @api private
|
||||||
#
|
#
|
||||||
def emit_implicit_self_receiver
|
def emit_implicit_self_receiver
|
||||||
return unless self?
|
return unless to_self?
|
||||||
mutant = dup_node
|
mutant = dup_node
|
||||||
mutant.privately = true
|
mutant.privately = true
|
||||||
# TODO: Fix rubinius to allow this as an attr_accessor
|
# TODO: Fix rubinius to allow this as an attr_accessor
|
||||||
|
|
|
@ -32,6 +32,17 @@ describe Mutant::Mutator, 'send' do
|
||||||
|
|
||||||
it_should_behave_like 'a mutator'
|
it_should_behave_like 'a mutator'
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
context 'send with arguments' do
|
context 'send with arguments' do
|
||||||
|
|
Loading…
Reference in a new issue