Class: Mutineer::Mutators::NegationRemoval

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

Overview

Negation-removal mutator (Tier-2).

Removes the ! or not of a negation, one mutation per occurrence: !x becomes x and not x becomes x. The mutant survives when no test depends on the negated value.

Instance Method Summary collapse

Methods inherited from Base

#heredoc?, #mutations_for

Instance Method Details

#emit(node) ⇒ void (private)

This method returns an undefined value.

Emits a mutation when the node is a prefix ! or not.

The explicit form x.! is skipped: without its message, x. does not parse.

Parameters:

  • node (Prism::CallNode) —

    call node to inspect.



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/mutineer/mutators/negation_removal.rb', line 31

def emit(node)
  return unless node.name == :! && node.call_operator_loc.nil?

  loc = node.message_loc
  @mutations << Mutation.new(
    start_offset: loc.start_offset,
    end_offset: loc.end_offset,
    replacement: "",
    operator: :negation_removal
  )
end

#visit_call_node(node) ⇒ void

This method returns an undefined value.

Visits call nodes and emits negation-removal mutations.

Parameters:

  • node (Prism::CallNode) —

    call node to inspect.



17
18
19
20
# File 'lib/mutineer/mutators/negation_removal.rb', line 17

def visit_call_node(node)
  emit(node)
  super # nested negations (!!x) each get their own mutation
end