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.
-
#visit_def_node(node) ⇒ void
Skips a nested method definition.
Methods inherited from Base
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.
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/mutineer/mutators/array_literal.rb', line 39 def emit(node) return if node.opening_loc.nil? || node.elements.empty? || 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 |
#visit_def_node(node) ⇒ void
This method returns an undefined value.
Skips a nested method definition. The project finds it as a subject of its own, so a visit here counts its arrays twice.
27 |
# File 'lib/mutineer/mutators/array_literal.rb', line 27 def visit_def_node(node); end |