Class: Mutineer::Mutators::Base

Inherits:
Prism::Visitor
  • Object
show all
Defined in:
lib/mutineer/mutators/base.rb

Overview

Base Prism visitor for operators.

Subclasses override visit_* methods to push Mutation objects onto @mutations. Visiting only def_node.body is the body-only enforcement: the def signature line is never touched.

ponytail: one implementor in M1; Base earns its keep at M4 when comparison/boolean operators land and share this contract.

Instance Method Summary collapse

Instance Method Details

#heredoc?(node) ⇒ Boolean (private)

Returns whether a node is, or contains, a heredoc.

A heredoc's body lies outside its node's byte range. A mutation that deletes the node leaves the body behind as code, so the mutant always raises.

Parameters:

  • node (Prism::Node) —

    node to inspect.

Returns:

  • (Boolean) —

    true when a heredoc is inside the node.



40
41
42
43
# File 'lib/mutineer/mutators/base.rb', line 40

def heredoc?(node)
  (node.respond_to?(:heredoc?) && node.heredoc?) ||
    node.compact_child_nodes.any? { |child| heredoc?(child) }
end

#mutations_for(subject, source) ⇒ Array<Mutineer::Mutation>

Walks the subject body and collects mutations.

Parameters:

  • subject (Mutineer::Subject) —

    subject whose body is visited.

  • source (String) —

    full source text for byte-based slicing.

Returns:



23
24
25
26
27
28
# File 'lib/mutineer/mutators/base.rb', line 23

def mutations_for(subject, source)
  @source = source
  @mutations = []
  subject.def_node.body&.accept(self)
  @mutations
end