lib/mutant/mutator/node/send.rb in mutant-0.8.5 vs lib/mutant/mutator/node/send.rb in mutant-0.8.6
- old
+ new
@@ -1,10 +1,11 @@
module Mutant
class Mutator
class Node
# Namespace for send mutators
+ # rubocop:disable ClassLength
class Send < self
include AST::Types
handle(:send)
@@ -32,10 +33,16 @@
:<= => %i[< == eql? equal?],
:> => %i[== >= eql? equal?],
:< => %i[== <= eql? equal?]
)
+ RECEIVER_SELECTOR_REPLACEMENTS = IceNine.deep_freeze(
+ Date: {
+ parse: %i[jd civil strptime iso8601 rfc3339 xmlschema rfc2822 rfc822 httpdate jisx0301]
+ }
+ )
+
private
# Perform dispatch
#
# @return [undefined]
@@ -88,13 +95,49 @@
#
# @api private
def normal_dispatch
emit_naked_receiver
emit_selector_replacement
- emit_const_get_mutation
+ emit_selector_specific_mutations
emit_argument_propagation
+ emit_receiver_selector_mutations
mutate_receiver
mutate_arguments
+ 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)
+ .fetch(selector, EMPTY_ARRAY)
+ .each(&method(:emit_selector))
+ 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]