Class: Henitai::Operators::PatternMatch

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

Overview

Mutates case-match arms and removes pattern guards.

Constant Summary collapse

NODE_TYPES =
[:case_match].freeze

Constants inherited from Henitai::Operator

Henitai::Operator::FULL_SET, Henitai::Operator::LIGHT_SET

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Henitai::Operator

for_set, #name

Class Method Details

.node_typesObject



11
12
13
# File 'lib/henitai/operators/pattern_match.rb', line 11

def self.node_types
  NODE_TYPES
end

Instance Method Details

#mutate(node, subject:) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/henitai/operators/pattern_match.rb', line 15

def mutate(node, subject:)
  mutants = []
  arm_number = 0

  node.children.each_with_index do |child, index|
    next unless child&.type == :in_pattern

    arm_number += 1
    mutants << remove_in_arm(node, subject:, index:, arm_number:)

    guard = child.children[1]
    next unless guard

    mutants << remove_guard(node, subject:, index:, arm_number:, child:)
  end

  mutants
end