Class: Mutineer::Mutators::ArrayLiteral
- Defined in:
- lib/mutineer/mutators/array_literal.rb
Overview
Array-literal mutator (Tier-2).
Replaces a non-empty array literal with an empty one, one mutation per
literal: [a, b] and %i[a b] become []. The mutant survives when no
test checks the contents of the array.
Instance Method Summary collapse
-
#emit(node) ⇒ void
private
Emits a mutation for a non-empty array with brackets.
-
#visit_array_node(node) ⇒ void
Visits array nodes and emits array-literal mutations.
Methods inherited from Base
#dangling_heredoc?, #decline, #declined, #drop_dangling_heredocs, #heredoc?, #mutations_for, #visit_def_node, #visit_singleton_class_node
Instance Method Details
#emit(node) ⇒ void (private)
This method returns an undefined value.
Emits a mutation for a non-empty array with brackets.
The operator skips an implicit array (x = 1, 2), because it has no
brackets. It also skips an array that holds a heredoc, because the
heredoc body stays behind as code. Only the heredoc skip counts as
declined.
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/mutineer/mutators/array_literal.rb', line 33 def emit(node) return if node.opening_loc.nil? || node.elements.empty? return decline if heredoc?(node) @mutations << Mutation.new( start_offset: node.location.start_offset, end_offset: node.location.end_offset, replacement: "[]", operator: :array_literal ) end |
#visit_array_node(node) ⇒ void
This method returns an undefined value.
Visits array nodes and emits array-literal mutations.
17 18 19 20 |
# File 'lib/mutineer/mutators/array_literal.rb', line 17 def visit_array_node(node) emit(node) super # nested arrays each get their own mutation end |