class Mutest::Mutator::Node::Send
Namespace for send mutators rubocop:disable ClassLength
Constants
- RECEIVER_SELECTOR_REPLACEMENTS
- SELECTOR_REPLACEMENTS
Private Instance Methods
Emit mutations
@return [undefined]
# File lib/mutest/mutator/node/send.rb, line 63 def dispatch emit_singletons if meta.binary_method_operator? run(Binary) elsif meta.attribute_assignment? run(AttributeAssignment) else normal_dispatch end end
Emit argument propagation
@return [undefined]
# File lib/mutest/mutator/node/send.rb, line 235 def emit_argument_propagation emit_propagation(Mutest::Util.one(arguments)) if arguments.one? end
Emit mutation from `Array(a)` to `[a]`
@return [undefined]
# File lib/mutest/mutator/node/send.rb, line 192 def emit_array_mutation return unless selector.equal?(:Array) && receiver.nil? emit(s(:array, *arguments)) end
Emit mutation from `const_get` to const literal
@return [undefined]
# File lib/mutest/mutator/node/send.rb, line 201 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 mutation for `#dig`
-
Mutates `foo.dig(a, b)` to `foo.fetch(a).dig(b)`
-
Mutates `foo.dig(a)` to `foo.fetch(a)`
@return [undefined]
# File lib/mutest/mutator/node/send.rb, line 168 def emit_dig_mutation return if !selector.equal?(:dig) || arguments.none? head, *tail = arguments fetch_mutation = s(:send, receiver, :fetch, head) return emit(fetch_mutation) if tail.empty? emit_type(fetch_mutation, :dig, *tail) end
Emit mutation from `!!foo` to `foo`
@return [undefined]
# File lib/mutest/mutator/node/send.rb, line 148 def emit_double_negation_mutation return unless selector.equal?(:!) && n_send?(receiver) negated = AST::Meta::Send.new(meta.receiver) emit(negated.receiver) if negated.selector.equal?(:!) end
Emit implicit self mutation
@return [undefined]
# File lib/mutest/mutator/node/send.rb, line 254 def emit_implicit_self emit_receiver(nil) if n_self?(receiver) && !( KEYWORDS.include?(selector) || METHOD_OPERATORS.include?(selector) || meta.attribute_assignment? ) end
Emit mutation from `to_i` to `Integer(…)`
@return [undefined]
# File lib/mutest/mutator/node/send.rb, line 183 def emit_integer_mutation return unless selector.equal?(:to_i) emit_type(nil, :Integer, receiver) end
Emit mutation from proc definition to lambda
@return [undefined]
# File lib/mutest/mutator/node/send.rb, line 158 def emit_lambda_mutation emit_type(nil, :lambda) if meta.proc? end
Emit selector mutations for [public_]method calls
-
Mutates `foo.method(:to_s)` to `foo.method(:to_str)`
-
Mutates `foo.public_method('to_s')` to `foo.public_method('to_str')`
@return [undefined]
# File lib/mutest/mutator/node/send.rb, line 133 def emit_method_method_selector_replacements return unless meta.method_object_selector? && meta.arguments.one? arg = Mutest::Util.one(meta.arguments) return unless n_sym?(arg) || n_str?(arg) selector_replacements(*arg).each do |replacement| emit_type(receiver, selector, s(arg.type, replacement)) end end
Emit naked receiver mutation
@return [undefined]
# File lib/mutest/mutator/node/send.rb, line 217 def emit_naked_receiver emit(receiver) if receiver end
Emit selector mutations specific to top level constants
@return [undefined]
# File lib/mutest/mutator/node/send.rb, line 118 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(&public_method(:emit_selector)) end
Emit selector replacement
@return [undefined]
# File lib/mutest/mutator/node/send.rb, line 210 def emit_selector_replacement selector_replacements(selector).each(&public_method(:emit_selector)) end
Emit mutations which only correspond to one selector
@return [undefined]
# File lib/mutest/mutator/node/send.rb, line 105 def emit_selector_specific_mutations emit_method_method_selector_replacements emit_const_get_mutation emit_integer_mutation emit_array_mutation emit_dig_mutation emit_double_negation_mutation emit_lambda_mutation end
AST
metadata for node
@return [AST::Meta::Send]
# File lib/mutest/mutator/node/send.rb, line 78 def meta AST::Meta::Send.new(node) end
Mutate arguments
@return [undefined]
# File lib/mutest/mutator/node/send.rb, line 224 def mutate_arguments emit_type(receiver, selector) remaining_children_with_index.each do |_node, index| mutate_child(index) delete_child(index) end end
Emit receiver mutations
@return [undefined]
# File lib/mutest/mutator/node/send.rb, line 242 def mutate_receiver return unless receiver emit_implicit_self emit_receiver_mutations do |node| !n_nil?(node) end end
Perform normal, non special case dispatch
@return [undefined]
# File lib/mutest/mutator/node/send.rb, line 92 def normal_dispatch emit_naked_receiver emit_selector_replacement emit_selector_specific_mutations emit_argument_propagation emit_receiver_selector_mutations mutate_receiver mutate_arguments end
# File lib/mutest/mutator/node/send.rb, line 262 def selector_replacements(selector) replacements = SELECTOR_REPLACEMENTS.fetch(selector.to_sym, EMPTY_ARRAY) if selector.instance_of?(String) replacements.map(&:to_s) else replacements end end