Class: BareTypes::Array

Inherits:
BaseType show all
Defined in:
lib/generative_testing/monkey_patch.rb,
lib/types.rb

Overview

region Array

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ Array

Returns a new instance of Array.



695
696
697
698
# File 'lib/types.rb', line 695

def initialize(type)
  raise VoidUsedOutsideTaggedSet.new("Void types may only be used as members of the set of types in a tagged union.") if type.class == BareTypes::Void
  @type = type
end

Class Method Details

.make(depth, names) ⇒ Object



180
181
182
# File 'lib/generative_testing/monkey_patch.rb', line 180

def self.make(depth, names)
  BareTypes::Array.new(get_type(depth + 1, names))
end

Instance Method Details

#==(otherType) ⇒ Object



666
667
668
# File 'lib/types.rb', line 666

def ==(otherType)
  otherType.class == BareTypes::Array && otherType.type == self.type
end

#create_inputObject



184
185
186
187
188
189
190
191
# File 'lib/generative_testing/monkey_patch.rb', line 184

def create_input
  count = rand(ARRAY_MAX_SIZE) + 1
  arr = []
  0.upto(count) do
    arr << @type.create_input
  end
  arr
end

#cycle_search(seen) ⇒ Object



670
671
672
673
674
# File 'lib/types.rb', line 670

def cycle_search(seen)
  seen.add(self)
  @type.cycle_search(seen)
  seen.pop
end

#decode(msg) ⇒ Object



707
708
709
710
711
712
713
714
715
716
717
718
# File 'lib/types.rb', line 707

def decode(msg)
  arr = []
  arrayLen, rest = Uint.new.decode(msg)
  lastSize = msg.size + 1 # Make sure msg size monotonically decreasing
  (arrayLen - 1).downto(0) do
    arrVal, rest = @type.decode(rest)
    arr << arrVal
    break if rest.nil? || rest.size == 0 || lastSize <= rest.size
    lastSize = rest.size
  end
  return arr, rest
end

#encode(msg, buffer) ⇒ Object



700
701
702
703
704
705
# File 'lib/types.rb', line 700

def encode(msg, buffer)
  Uint.new.encode(msg.size, buffer)
  msg.each do |item|
    @type.encode(item, buffer)
  end
end

#finalize_references(schema) ⇒ Object



685
686
687
688
689
690
691
692
693
# File 'lib/types.rb', line 685

def finalize_references(schema)
  return if @finalized
  @finalized = true
  if @type.is_a?(Symbol)
    @type = Reference.new(@type, schema[@type])
  else
    @type.finalize_references(schema)
  end
end

#to_schema(buffer) ⇒ Object



680
681
682
683
# File 'lib/types.rb', line 680

def to_schema(buffer)
  buffer << "[]"
  @type.to_schema(buffer)
end

#typeObject



676
677
678
# File 'lib/types.rb', line 676

def type
  @type
end