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: %i[each_with_object sum],
  reverse_each: [:each],
  each: [:reverse_each],
  length: [:size],
  size: [:length],
  values_at: [:fetch_values],
  fetch_values: [:values_at],
  sum: [:inject],
  count: [:size],
  select: [:filter],
  filter: [:select],
  to_s: [:to_i],
  to_i: [:to_s],
  to_f: [:to_i],
  to_a: [:to_h],
  to_h: [:to_a],
  downcase: [:upcase],
  upcase: [:downcase],
  strip: %i[lstrip rstrip],
  lstrip: [:strip],
  rstrip: [:strip],
  chomp: [:chop],
  chop: [:chomp]
}.freeze

Instance Attribute Summary

Attributes inherited from Base

#mutations

Instance Method Summary collapse

Methods inherited from Base

#call, clear_parse_cache!, #initialize, operator_name, parsed_tree_for

Constructor Details

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

Instance Method Details

#visit_call_node(node) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/evilution/mutator/operator/send_mutation.rb', line 42

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