Class: Rigor::Protection::Mutation

Inherits:
Struct
  • Object
show all
Defined in:
lib/rigor/protection/mutator.rb

Overview

One concrete edit: replace source bytes [start, stop) with replacement. anchor is the Prism node whose inferred type decides type-relevance — the call receiver whose contract the mutation could violate, or nil when there is no concrete receiver (implicit-self call, literal outside a call). anchor_type (the rendered receiver type) and method_name are filled in for reporting a surviving site; both may stay nil.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#anchorObject

Returns the value of attribute anchor

Returns:

  • (Object)

    the current value of anchor



18
19
20
# File 'lib/rigor/protection/mutator.rb', line 18

def anchor
  @anchor
end

#anchor_typeObject

Returns the value of attribute anchor_type

Returns:

  • (Object)

    the current value of anchor_type



18
19
20
# File 'lib/rigor/protection/mutator.rb', line 18

def anchor_type
  @anchor_type
end

#expected_ruleObject

Returns the value of attribute expected_rule

Returns:

  • (Object)

    the current value of expected_rule



18
19
20
# File 'lib/rigor/protection/mutator.rb', line 18

def expected_rule
  @expected_rule
end

#labelObject

Returns the value of attribute label

Returns:

  • (Object)

    the current value of label



18
19
20
# File 'lib/rigor/protection/mutator.rb', line 18

def label
  @label
end

#lineObject

Returns the value of attribute line

Returns:

  • (Object)

    the current value of line



18
19
20
# File 'lib/rigor/protection/mutator.rb', line 18

def line
  @line
end

#method_nameObject

Returns the value of attribute method_name

Returns:

  • (Object)

    the current value of method_name



18
19
20
# File 'lib/rigor/protection/mutator.rb', line 18

def method_name
  @method_name
end

#operatorObject

Returns the value of attribute operator

Returns:

  • (Object)

    the current value of operator



18
19
20
# File 'lib/rigor/protection/mutator.rb', line 18

def operator
  @operator
end

#replacementObject

Returns the value of attribute replacement

Returns:

  • (Object)

    the current value of replacement



18
19
20
# File 'lib/rigor/protection/mutator.rb', line 18

def replacement
  @replacement
end

#startObject

Returns the value of attribute start

Returns:

  • (Object)

    the current value of start



18
19
20
# File 'lib/rigor/protection/mutator.rb', line 18

def start
  @start
end

#stopObject

Returns the value of attribute stop

Returns:

  • (Object)

    the current value of stop



18
19
20
# File 'lib/rigor/protection/mutator.rb', line 18

def stop
  @stop
end

Instance Method Details

#apply(source) ⇒ Object



23
24
25
26
27
# File 'lib/rigor/protection/mutator.rb', line 23

def apply(source)
  prefix = source.byteslice(0, start)
  suffix = source.byteslice(stop, source.bytesize - stop) || ""
  "#{prefix}#{replacement}#{suffix}"
end