Class: Mutineer::Mutators::SafeNavigation
- Defined in:
- lib/mutineer/mutators/safe_navigation.rb
Overview
Safe-navigation mutator (Tier-2).
Replaces &. with ., one mutation per occurrence. The mutant raises
NoMethodError on a nil receiver, so it survives when no test passes nil.
Instance Method Summary collapse
-
#emit(node) ⇒ void
private
Emits a mutation when the node's call operator is
&.. -
#visit_call_and_write_node(node) ⇒ void
Visits
a&.b &&= 1. -
#visit_call_node(node) ⇒ void
Visits call nodes and emits safe-navigation mutations.
-
#visit_call_operator_write_node(node) ⇒ void
Visits
a&.b += 1, which Prism parses as its own node, not a CallNode. -
#visit_call_or_write_node(node) ⇒ void
Visits
a&.b ||= 1. -
#visit_call_target_node(node) ⇒ void
Visits a call used as an assignment target, as in
for a&.b in list.
Methods inherited from Base
Instance Method Details
#emit(node) ⇒ void (private)
This method returns an undefined value.
Emits a mutation when the node's call operator is &..
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/mutineer/mutators/safe_navigation.rb', line 63 def emit(node) return unless node. loc = node.call_operator_loc @mutations << Mutation.new( start_offset: loc.start_offset, end_offset: loc.end_offset, replacement: ".", operator: :safe_navigation ) end |
#visit_call_and_write_node(node) ⇒ void
This method returns an undefined value.
Visits a&.b &&= 1.
43 44 45 46 |
# File 'lib/mutineer/mutators/safe_navigation.rb', line 43 def visit_call_and_write_node(node) emit(node) super end |
#visit_call_node(node) ⇒ void
This method returns an undefined value.
Visits call nodes and emits safe-navigation mutations.
16 17 18 19 |
# File 'lib/mutineer/mutators/safe_navigation.rb', line 16 def visit_call_node(node) emit(node) super # chained calls (a&.b&.c) each get their own mutation end |
#visit_call_operator_write_node(node) ⇒ void
This method returns an undefined value.
Visits a&.b += 1, which Prism parses as its own node, not a CallNode.
25 26 27 28 |
# File 'lib/mutineer/mutators/safe_navigation.rb', line 25 def visit_call_operator_write_node(node) emit(node) super end |
#visit_call_or_write_node(node) ⇒ void
This method returns an undefined value.
Visits a&.b ||= 1.
34 35 36 37 |
# File 'lib/mutineer/mutators/safe_navigation.rb', line 34 def visit_call_or_write_node(node) emit(node) super end |
#visit_call_target_node(node) ⇒ void
This method returns an undefined value.
Visits a call used as an assignment target, as in for a&.b in list.
52 53 54 55 |
# File 'lib/mutineer/mutators/safe_navigation.rb', line 52 def visit_call_target_node(node) emit(node) super end |