Class: Mutineer::Mutators::StringLiteral

Inherits:
Base
  • Object
show all
Defined in:
lib/mutineer/mutators/string_literal.rb

Overview

String literal mutator (Tier-2).

Empties a non-empty string literal and fills an empty one. Only plain quoted strings are touched; interpolated strings, heredocs and %-literals are skipped for safety (they re-parse unpredictably).

Instance Method Summary collapse

Methods inherited from Base

#mutations_for

Instance Method Details

#visit_string_node(node) ⇒ void

This method returns an undefined value.

Visits string literals.

Parameters:

  • node (Prism::StringNode)

    node to inspect.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/mutineer/mutators/string_literal.rb', line 17

def visit_string_node(node)
  # ponytail: only plain "..." / '...' quotes. opening is nil for
  # interpolation parts and %w[] elements; heredocs/%-literals use a
  # different opening token. Skipping them keeps mutants re-parseable.
  if %w[" '].include?(node.opening)
    loc = node.content_loc
    @mutations << Mutation.new(
      start_offset: loc.start_offset,
      end_offset: loc.end_offset,
      replacement: node.unescaped.empty? ? "mutineer" : "",
      operator: :string_literal
    )
  end
  super
end