lib/mutant/mutator/node/send.rb in mutant-0.8.8 vs lib/mutant/mutator/node/send.rb in mutant-0.8.9
- old
+ new
@@ -24,12 +24,14 @@
eql?: %i[equal?],
to_s: %i[to_str],
to_i: %i[to_int],
to_a: %i[to_ary],
to_h: %i[to_hash],
- at: %i[fetch],
- :[] => %i[at fetch],
+ at: %i[fetch key?],
+ fetch: %i[key?],
+ values_at: %i[fetch_values],
+ :[] => %i[at fetch key?],
:== => %i[eql? equal?],
:>= => %i[> == eql? equal?],
:<= => %i[< == eql? equal?],
:> => %i[== >= eql? equal?],
:< => %i[== <= eql? equal?]
@@ -44,12 +46,10 @@
private
# Perform dispatch
#
# @return [undefined]
- #
- # @api private
def dispatch
emit_singletons
if meta.index_assignment?
run(Index::Assign)
else
@@ -58,12 +58,10 @@
end
# Perform non index dispatch
#
# @return [undefined]
- #
- # @api private
def non_index_dispatch
if meta.binary_method_operator?
run(Binary)
elsif meta.attribute_assignment?
run(AttributeAssignment)
@@ -73,29 +71,23 @@
end
# AST metadata for node
#
# @return [AST::Meta::Send]
- #
- # @api private
def meta
AST::Meta::Send.new(node)
end
memoize :meta
# Arguments being send
#
# @return [Enumerable<Parser::AST::Node>]
- #
- # @api private
alias_method :arguments, :remaining_children
# Perform normal, non special case dispatch
#
# @return [undefined]
- #
- # @api private
def normal_dispatch
emit_naked_receiver
emit_selector_replacement
emit_selector_specific_mutations
emit_argument_propagation
@@ -105,22 +97,18 @@
end
# Emit mutations which only correspond to one selector
#
# @return [undefined]
- #
- # @api private
def emit_selector_specific_mutations
emit_const_get_mutation
emit_integer_mutation
end
# Emit selector mutations specific to top level constants
#
# @return [undefined]
- #
- # @api private
def emit_receiver_selector_mutations
return unless meta.receiver_possible_top_level_const?
RECEIVER_SELECTOR_REPLACEMENTS
.fetch(receiver.children.last, EMPTY_HASH)
@@ -129,52 +117,42 @@
end
# Emit mutation from `to_i` to `Integer(...)`
#
# @return [undefined]
- #
- # @api private
def emit_integer_mutation
return unless selector.equal?(:to_i)
emit(s(:send, nil, :Integer, receiver))
end
# Emit mutation from `const_get` to const literal
#
# @return [undefined]
- #
- # @api private
def emit_const_get_mutation
return unless selector.equal?(:const_get) && n_sym?(arguments.first)
emit(s(:const, receiver, AST::Meta::Symbol.new(arguments.first).name))
end
# Emit selector replacement
#
# @return [undefined]
- #
- # @api private
def emit_selector_replacement
SELECTOR_REPLACEMENTS.fetch(selector, EMPTY_ARRAY).each(&method(:emit_selector))
end
# Emit naked receiver mutation
#
# @return [undefined]
- #
- # @api private
def emit_naked_receiver
emit(receiver) if receiver && !NOT_ASSIGNABLE.include?(receiver.type)
end
# Mutate arguments
#
# @return [undefined]
- #
- # @api private
def mutate_arguments
emit_type(receiver, selector)
remaining_children_with_index.each do |_node, index|
mutate_child(index)
delete_child(index)
@@ -182,22 +160,18 @@
end
# Emit argument propagation
#
# @return [undefined]
- #
- # @api private
def emit_argument_propagation
node = arguments.first
emit(node) if arguments.one? && !NOT_STANDALONE.include?(node.type)
end
# Emit receiver mutations
#
# @return [undefined]
- #
- # @api private
def mutate_receiver
return unless receiver
emit_implicit_self
emit_receiver_mutations do |node|
!n_nil?(node)
@@ -205,11 +179,9 @@
end
# Emit implicit self mutation
#
# @return [undefined]
- #
- # @api private
def emit_implicit_self
emit_receiver(nil) if n_self?(receiver) && !(
KEYWORDS.include?(selector) ||
METHOD_OPERATORS.include?(selector) ||
meta.attribute_assignment?