Class: Henitai::Operators::HashKeyType

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

Overview

Mutates symbol hash keys into string keys, one pair at a time ({ a: 1 } -> { "a" => 1 }). Symbol/string key confusion is a real defect class, but frameworks that normalize keys (e.g. ActiveRecord's order/where) make these mutants frequently unkillable — hence the hard set, not full (ADR-12).

Constant Summary collapse

NODE_TYPES =
[:hash].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



13
14
15
# File 'lib/henitai/operators/hash_key_type.rb', line 13

def self.node_types
  NODE_TYPES
end

Instance Method Details

#mutate(node, subject:) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/henitai/operators/hash_key_type.rb', line 17

def mutate(node, subject:)
  node.children.each_with_index.filter_map do |pair, index|
    next unless symbol_key_pair?(pair)

    build_mutant(
      subject:,
      original_node: node,
      mutated_node: mutated_hash(node, index),
      description: "replaced symbol key with string key"
    )
  end
end