Class: Mutineer::Mutators::Base
- Inherits:
-
Prism::Visitor
- Object
- Prism::Visitor
- Mutineer::Mutators::Base
- 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.
Direct Known Subclasses
Arithmetic, ArrayLiteral, BooleanConnector, BooleanLiteral, ChainLink, CollectionMethod, Comparison, ConditionForcing, ConditionNegation, LiteralMutation, NegationRemoval, OperandRemoval, OperatorAssignment, RangeLiteral, RegexLiteral, ReturnNil, SafeNavigation, StatementRemoval, StringLiteral
Instance Method Summary collapse
-
#heredoc?(node) ⇒ Boolean
private
Returns whether a node is, or contains, a heredoc.
-
#mutations_for(subject, source) ⇒ Array<Mutineer::Mutation>
Walks the subject body and collects mutations.
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.
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.
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 |