Class: Evilution::Mutator::Operator::IntegerLiteral

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

Instance Attribute Summary

Attributes inherited from Base

#mutations

Instance Method Summary collapse

Methods inherited from Base

#call, #initialize, operator_name

Constructor Details

This class inherits a constructor from Evilution::Mutator::Base

Instance Method Details

#visit_integer_node(node) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/evilution/mutator/operator/integer_literal.rb', line 7

def visit_integer_node(node)
  value = node.value

  if value.zero?
    add_mutation(
      offset: node.location.start_offset,
      length: node.location.length,
      replacement: "1",
      node: node
    )
  elsif value == 1
    add_mutation(
      offset: node.location.start_offset,
      length: node.location.length,
      replacement: "0",
      node: node
    )
  else
    add_mutation(
      offset: node.location.start_offset,
      length: node.location.length,
      replacement: "0",
      node: node
    )

    add_mutation(
      offset: node.location.start_offset,
      length: node.location.length,
      replacement: (node.value + 1).to_s,
      node: node
    )
  end

  add_mutation(
    offset: node.location.start_offset,
    length: node.location.length,
    replacement: "nil",
    node: node
  )

  super
end