Class: Mutineer::Mutators::Arithmetic

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

Overview

Arithmetic operator mutator.

One mutation per occurrence, rewriting the operator token.

Constant Summary collapse

REPLACEMENTS =

Token replacements for arithmetic operators.

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

Instance Method Summary collapse

Methods inherited from Base

#mutations_for

Instance Method Details

#visit_call_node(node) ⇒ void

This method returns an undefined value.

Visits call nodes and emits arithmetic mutations.

Parameters:

  • node (Prism::CallNode)

    call node to inspect.



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/mutineer/mutators/arithmetic.rb', line 20

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