Class: Evilution::Mutator::Operator::BitwiseComplement

Inherits:
Base
  • Object
show all
Defined in:
lib/evilution/mutator/operator/bitwise_complement.rb

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



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/evilution/mutator/operator/bitwise_complement.rb', line 6

def visit_call_node(node)
  if node.name == :~ && node.receiver && node.arguments.nil?
    loc = node.message_loc
    receiver_loc = node.receiver.location

    # Remove ~: replace entire ~expr with just the receiver expression
    receiver_source = byteslice_source(receiver_loc.start_offset, receiver_loc.length)
    add_mutation(
      offset: node.location.start_offset,
      length: node.location.length,
      replacement: receiver_source,
      node: node
    )

    # Swap ~ with unary minus
    add_mutation(
      offset: loc.start_offset,
      length: loc.length,
      replacement: "-",
      node: node
    )
  end

  super
end