Class: ActiveMutator::Operators::CallSwap

Inherits:
Base
  • Object
show all
Defined in:
lib/active_mutator/operators/call_swap.rb

Constant Summary collapse

MAP =

One-directional where the reverse is usually an equivalent mutant (e.g. each→map when return value is unused).

{
  map: "each",
  select: "reject", reject: "select",
  min: "max", max: "min",
  first: "last", last: "first",
  any?: "none?", none?: "any?",
  # Rails-aware pack:
  present?: "blank?", blank?: "present?",
  save: "save!", save!: "save"
}.freeze

Constants inherited from Base

Base::REGISTRY

Instance Method Summary collapse

Methods inherited from Base

all, inherited

Instance Method Details

#edits(node) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/active_mutator/operators/call_swap.rb', line 17

def edits(node)
  return [] unless node.is_a?(Prism::CallNode) && node.receiver && node.message_loc

  replacement = MAP[node.name]
  return [] unless replacement

  [edit(loc_range(node.message_loc), replacement,
        "replace `.#{node.name}` with `.#{replacement}`")]
end