Class: Mutineer::Mutators::BooleanConnector

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

Overview

Boolean connector mutator.

Replaces symbolic and keyword connectors with their opposite form.

Constant Summary collapse

REPLACEMENTS =

Token replacements for boolean connectors.

{ "&&" => "||", "||" => "&&", "and" => "or", "or" => "and" }.freeze

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 connector mutation when the token is replaceable.

Parameters:

  • node (Prism::Node) —

    connector node.



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/mutineer/mutators/boolean_connector.rb', line 38

def emit(node)
  loc = node.operator_loc
  replacement = REPLACEMENTS[loc.slice]
  return unless replacement

  @mutations << Mutation.new(
    start_offset: loc.start_offset,
    end_offset: loc.end_offset,
    replacement: replacement,
    operator: :boolean_connector
  )
end

#visit_and_node(node) ⇒ void

This method returns an undefined value.

Visits and nodes.

Parameters:

  • node (Prism::AndNode) —

    node to inspect.



18
19
20
21
# File 'lib/mutineer/mutators/boolean_connector.rb', line 18

def visit_and_node(node)
  emit(node)
  super
end

#visit_or_node(node) ⇒ void

This method returns an undefined value.

Visits or nodes.

Parameters:

  • node (Prism::OrNode) —

    node to inspect.



27
28
29
30
# File 'lib/mutineer/mutators/boolean_connector.rb', line 27

def visit_or_node(node)
  emit(node)
  super
end