Class: Mutineer::Mutators::Comparison

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

Overview

Comparison and boundary mutator.

Rewrites comparison operators one occurrence at a time.

Constant Summary collapse

REPLACEMENTS =

Token replacements for comparison 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 comparison 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/comparison.rb', line 20

def visit_call_node(node)
  replacement = REPLACEMENTS[node.name]
  loc = node.message_loc
  if replacement && loc && node.receiver
    @mutations << Mutation.new(
      start_offset: loc.start_offset,
      end_offset: loc.end_offset,
      replacement: replacement,
      operator: :comparison
    )
  end
  super # nested comparisons (a >= b && c <= d) each get their own mutation
end