Class: Mutineer::Mutators::Arithmetic

Inherits:
Base
  • Object
show all
Defined in:
lib/mutineer/mutators/arithmetic.rb

Overview

Arithmetic operator: +<->-, <->/, %->, **->*. One mutation per occurrence, rewriting the operator token (CallNode#message_loc).

Constant Summary collapse

REPLACEMENTS =
{
  :+ => "-", :- => "+", :* => "/", :/ => "*", :% => "*", :** => "*"
}.freeze

Instance Method Summary collapse

Methods inherited from Base

#mutations_for

Instance Method Details

#visit_call_node(node) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/mutineer/mutators/arithmetic.rb', line 14

def visit_call_node(node)
  replacement = REPLACEMENTS[node.name]
  loc = node.message_loc
  if replacement && loc
    @mutations << Mutation.new(
      start_offset: loc.start_offset,
      end_offset: loc.end_offset,
      replacement: replacement,
      operator: :arithmetic
    )
  end
  super # nested calls (e.g. a + (b * c)) each get their own mutation
end