Class: Henitai::Operators::EqualityIdentityOperator

Inherits:
Henitai::Operator show all
Defined in:
lib/henitai/operators/equality_identity_operator.rb

Overview

Replaces relational operators with identity methods (eql?, equal?) and vice versa.

This is the noisy half of the equality/identity pairing split out of EqualityOperator: most Ruby objects don't observably distinguish == from eql?/equal?, so these mutations are frequently unkillable by ordinary tests. They stay available in the full operator set rather than the default light set.

Constant Summary collapse

NODE_TYPES =
[:send].freeze
RELATIONAL =
%i[== != < > <= >= <=>].freeze
IDENTITY =
%i[eql? equal?].freeze
OPERATORS =
(RELATIONAL + IDENTITY).freeze

Constants inherited from Henitai::Operator

Henitai::Operator::FULL_SET, Henitai::Operator::HARD_SET, Henitai::Operator::LIGHT_SET, Henitai::Operator::SETS

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Henitai::Operator

#build_mutant, for_set, #name, #node_location

Class Method Details

.node_typesObject



21
22
23
# File 'lib/henitai/operators/equality_identity_operator.rb', line 21

def self.node_types
  NODE_TYPES
end

Instance Method Details

#mutate(node, subject:) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/henitai/operators/equality_identity_operator.rb', line 25

def mutate(node, subject:)
  method_name = node.children[1]
  return [] unless OPERATORS.include?(method_name)

  OPERATORS.each_with_object([]) do |replacement, mutants|
    next if replacement == method_name
    next if RELATIONAL.include?(method_name) && RELATIONAL.include?(replacement)

    mutants << build_mutant(
      subject:,
      original_node: node,
      mutated_node: mutated_node(node, replacement),
      description: "replaced #{method_name} with #{replacement}"
    )
  end
end