Class: Mutineer::Mutation

Inherits:
Data
  • Object
show all
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

Instance Method Summary collapse

Instance Attribute Details

#end_offsetObject (readonly)

Returns the value of attribute end_offset

Returns:

  • (Object)

    the current value of end_offset



10
11
12
# File 'lib/mutineer/mutation.rb', line 10

def end_offset
  @end_offset
end

#operatorObject (readonly)

Returns the value of attribute operator

Returns:

  • (Object)

    the current value of operator



10
11
12
# File 'lib/mutineer/mutation.rb', line 10

def operator
  @operator
end

#replacementObject (readonly)

Returns the value of attribute replacement

Returns:

  • (Object)

    the current value of replacement



10
11
12
# File 'lib/mutineer/mutation.rb', line 10

def replacement
  @replacement
end

#start_offsetObject (readonly)

Returns the value of attribute start_offset

Returns:

  • (Object)

    the current value of start_offset



10
11
12
# File 'lib/mutineer/mutation.rb', line 10

def start_offset
  @start_offset
end

Instance Method Details

#apply(source) ⇒ String

Applies the mutation to source text.

Parameters:

  • source (String)

    original source text.

Returns:

  • (String)

    mutated source text.



15
16
17
# File 'lib/mutineer/mutation.rb', line 15

def apply(source)
  source.byteslice(0, start_offset) + replacement + source.byteslice(end_offset..)
end

#valid?(source) ⇒ Boolean

Checks whether the mutated source still parses cleanly.

Parameters:

  • source (String)

    original source text.

Returns:

  • (Boolean)

    true when the mutated source re-parses without errors.



23
24
25
# File 'lib/mutineer/mutation.rb', line 23

def valid?(source)
  Parser.parse_string(apply(source)).errors.empty?
end