Sha256: 296d3fac88ff2ec7d321d2828d819be4475935076331e90ac2b8b928923303e2

Contents?: true

Size: 1.18 KB

Versions: 18

Compression:

Stored size: 1.18 KB

Contents

StructUsingHashlike = Struct.new(:a, :b, :c, :nil_val, :false_val, :new_key) do
  include Gorillib::Hashlike
  include Gorillib::Struct::ActsAsHash

  def to_s ; to_hash.to_s ; end
  def inspect ; to_s ; end

  # compares so nil key is same as missing key
  def ==(othr)
    self.each_pair{|k,v| return false unless (v == othr[k]) }
    othr.each_pair{|k,v| return false unless (v == self[k]) }
    true
  end
end

module HashlikeFuzzingHelper
  SPECIAL_CASES_FOR_HASHLIKE_STRUCT = Hash.new({}).merge({
      :[]    => [
        [0], [1], [2], [100], [-1], # numeric keys are interpreted as positional args
        [:z], ['z'],                # Struct doesn't allow access to undefined keys
        [:z,  STRING_2X_PROC],
        ['z', STRING_2X_PROC],
        [:z, 100, STRING_2X_PROC],
      ],
      :[]=   => [
        [:z, :a], ['z', :a],        # Struct doesn't allow access to undefined keys
        [:z, 100, STRING_2X_PROC],
      ],
      :store     => [
        [:z, :a], ['z', :a],        # Struct doesn't allow access to undefined keys
        [:z, 100, STRING_2X_PROC],
      ],
      :each_pair => [
        [TOTAL_V_PROC],             # Struct behaves differently on arity 1
      ],
    })
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
gorillib-0.6.0 spec/support/hashlike_struct_helper.rb
gorillib-0.5.2 spec/support/hashlike_struct_helper.rb
gorillib-0.5.0 spec/support/hashlike_struct_helper.rb
gorillib-0.4.2 spec/support/hashlike_struct_helper.rb
gorillib-0.4.2pre spec/support/hashlike_struct_helper.rb
gorillib-0.4.0pre spec/support/hashlike_struct_helper.rb
gorillib-0.4.1pre spec/support/hashlike_struct_helper.rb
gorillib-0.1.11 spec/support/hashlike_struct_helper.rb
gorillib-0.1.9 spec/support/hashlike_struct_helper.rb
gorillib-0.1.8 spec/support/hashlike_struct_helper.rb
gorillib-0.1.7 spec/support/hashlike_struct_helper.rb
gorillib-0.1.6 spec/support/hashlike_struct_helper.rb
gorillib-0.1.5 spec/support/hashlike_struct_helper.rb
gorillib-0.1.4 spec/support/hashlike_struct_helper.rb
gorillib-0.1.3 spec/support/hashlike_struct_helper.rb
gorillib-0.1.2 spec/support/hashlike_struct_helper.rb
gorillib-0.1.1 spec/support/hashlike_struct_helper.rb
gorillib-0.1.0 spec/support/hashlike_struct_helper.rb