Class: Henitai::Operators::MethodExpression

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

Overview

Replaces generic method call results with nil.

Constant Summary collapse

NODE_TYPES =
[:send].freeze
EXCLUDED_METHODS =
%i[
  +
  -
  *
  /
  **
  %
  ==
  !=
  <
  >
  <=
  >=
  <=>
  eql?
  equal?
  !
].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



29
30
31
# File 'lib/henitai/operators/method_expression.rb', line 29

def self.node_types
  NODE_TYPES
end

Instance Method Details

#mutate(node, subject:) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/henitai/operators/method_expression.rb', line 33

def mutate(node, subject:)
  return [] unless node.type == :send

  _receiver, method_name, *_arguments = node.children
  return [] if excluded_method?(method_name)

  [
    build_mutant(
      subject:,
      original_node: node,
      mutated_node: Parser::AST::Node.new(:nil, []),
      description: "replaced method call with nil"
    )
  ]
end