Class: Mutineer::Mutation
- Inherits:
-
Data
- Object
- Data
- Mutineer::Mutation
- Defined in:
- lib/mutineer/mutation.rb
Overview
One atomic byte-range edit. Immutable. One mutation per mutant — never combine. Source is mutated textually, never regenerated from the AST.
Instance Attribute Summary collapse
-
#end_offset ⇒ Object
readonly
Returns the value of attribute end_offset.
-
#operator ⇒ Object
readonly
Returns the value of attribute operator.
-
#replacement ⇒ Object
readonly
Returns the value of attribute replacement.
-
#start_offset ⇒ Object
readonly
Returns the value of attribute start_offset.
Instance Method Summary collapse
-
#apply(source) ⇒ Object
Pure: returns a new string, does not mutate
source. -
#valid?(source) ⇒ Boolean
Validity rule: a mutation is valid iff the mutated source re-parses clean.
Instance Attribute Details
#end_offset ⇒ Object (readonly)
Returns the value of attribute end_offset
8 9 10 |
# File 'lib/mutineer/mutation.rb', line 8 def end_offset @end_offset end |
#operator ⇒ Object (readonly)
Returns the value of attribute operator
8 9 10 |
# File 'lib/mutineer/mutation.rb', line 8 def operator @operator end |
#replacement ⇒ Object (readonly)
Returns the value of attribute replacement
8 9 10 |
# File 'lib/mutineer/mutation.rb', line 8 def replacement @replacement end |
#start_offset ⇒ Object (readonly)
Returns the value of attribute start_offset
8 9 10 |
# File 'lib/mutineer/mutation.rb', line 8 def start_offset @start_offset end |
Instance Method Details
#apply(source) ⇒ Object
Pure: returns a new string, does not mutate source. Prism offsets are
BYTE offsets, so all slicing is byte-based (byteslice) — char slicing would
corrupt any source containing a multibyte char before the mutation point.
12 13 14 |
# File 'lib/mutineer/mutation.rb', line 12 def apply(source) source.byteslice(0, start_offset) + replacement + source.byteslice(end_offset..) end |
#valid?(source) ⇒ Boolean
Validity rule: a mutation is valid iff the mutated source re-parses clean.
17 18 19 |
# File 'lib/mutineer/mutation.rb', line 17 def valid?(source) Parser.parse_string(apply(source)).errors.empty? end |