Class: Evilution::Mutator::Operator::SendMutation

Inherits:
Base
  • Object
show all
Defined in:
lib/evilution/mutator/operator/send_mutation.rb

Constant Summary collapse

REPLACEMENTS =
{
  flat_map: [:map],
  map: [:flat_map],
  collect: [:map],
  public_send: [:send],
  send: [:public_send],
  gsub: [:sub],
  sub: [:gsub],
  detect: [:find],
  find: [:detect],
  each_with_object: [:inject],
  inject: [:each_with_object],
  reverse_each: [:each],
  each: [:reverse_each],
  length: [:size],
  size: [:length],
  values_at: [:fetch_values],
  fetch_values: [:values_at]
}.freeze

Instance Attribute Summary

Attributes inherited from Base

#mutations

Instance Method Summary collapse

Methods inherited from Base

#call, #initialize, operator_name

Constructor Details

This class inherits a constructor from Evilution::Mutator::Base

Instance Method Details

#visit_call_node(node) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/evilution/mutator/operator/send_mutation.rb', line 27

def visit_call_node(node)
  replacements = REPLACEMENTS[node.name]
  return super unless replacements
  return super unless node.receiver

  loc = node.message_loc
  return super unless loc

  replacements.each do |replacement|
    add_mutation(
      offset: loc.start_offset,
      length: loc.length,
      replacement: replacement.to_s,
      node: node
    )
  end

  super
end