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



22
23
24
# File 'lib/rigor/protection/mutator.rb', line 22

def anchor
  @anchor
end

#anchor_typeObject

Returns the value of attribute anchor_type

Returns:

  • (Object)

    the current value of anchor_type



22
23
24
# File 'lib/rigor/protection/mutator.rb', line 22

def anchor_type
  @anchor_type
end

#expected_ruleObject

Returns the value of attribute expected_rule

Returns:

  • (Object)

    the current value of expected_rule



22
23
24
# File 'lib/rigor/protection/mutator.rb', line 22

def expected_rule
  @expected_rule
end

#labelObject

Returns the value of attribute label

Returns:

  • (Object)

    the current value of label



22
23
24
# File 'lib/rigor/protection/mutator.rb', line 22

def label
  @label
end

#lineObject

Returns the value of attribute line

Returns:

  • (Object)

    the current value of line



22
23
24
# File 'lib/rigor/protection/mutator.rb', line 22

def line
  @line
end

#method_nameObject

Returns the value of attribute method_name

Returns:

  • (Object)

    the current value of method_name



22
23
24
# File 'lib/rigor/protection/mutator.rb', line 22

def method_name
  @method_name
end

#operatorObject

Returns the value of attribute operator

Returns:

  • (Object)

    the current value of operator



22
23
24
# File 'lib/rigor/protection/mutator.rb', line 22

def operator
  @operator
end

#replacementObject

Returns the value of attribute replacement

Returns:

  • (Object)

    the current value of replacement



22
23
24
# File 'lib/rigor/protection/mutator.rb', line 22

def replacement
  @replacement
end

#startObject

Returns the value of attribute start

Returns:

  • (Object)

    the current value of start



22
23
24
# File 'lib/rigor/protection/mutator.rb', line 22

def start
  @start
end

#stopObject

Returns the value of attribute stop

Returns:

  • (Object)

    the current value of stop



22
23
24
# File 'lib/rigor/protection/mutator.rb', line 22

def stop
  @stop
end

Instance Method Details

#apply(source) ⇒ Object



27
28
29
30
31
# File 'lib/rigor/protection/mutator.rb', line 27

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