class Mutest::Mutator::Node::Send

Namespace for send mutators rubocop:disable ClassLength

Constants

RECEIVER_SELECTOR_REPLACEMENTS
SELECTOR_REPLACEMENTS

Private Instance Methods

dispatch() click to toggle source

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() click to toggle source

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_array_mutation() click to toggle source

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_const_get_mutation() click to toggle source

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_dig_mutation() click to toggle source

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_double_negation_mutation() click to toggle source

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() click to toggle source

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_integer_mutation() click to toggle source

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_lambda_mutation() click to toggle source

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_method_method_selector_replacements() click to toggle source

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() click to toggle source

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_receiver_selector_mutations() click to toggle source

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() click to toggle source

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_selector_specific_mutations() click to toggle source

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
meta() click to toggle source

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() click to toggle source

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
mutate_receiver() click to toggle source

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
normal_dispatch() click to toggle source

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
selector_replacements(selector) click to toggle source
# 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