Sha256: 0957b66b2e609de6ea36834292ccd9cd5981e5155c311aa36d59687700f765c3

Contents?: true

Size: 973 Bytes

Versions: 27

Compression:

Stored size: 973 Bytes

Contents

require_relative 'helper'

class PsychStructWithIvar < Struct.new(:foo)
  attr_reader :bar
  def initialize *args
    super
    @bar = 'hello'
  end
end

module Psych
  class TestStruct < TestCase
    class StructSubclass < Struct.new(:foo)
      def initialize foo, bar
        super(foo)
        @bar = bar
      end
    end

    def test_self_referential_struct
      ss = StructSubclass.new(nil, 'foo')
      ss.foo = ss

      loaded = Psych.load(Psych.dump(ss))
      assert_instance_of(StructSubclass, loaded.foo)

      assert_equal(ss, loaded)
    end

    def test_roundtrip
      thing = PsychStructWithIvar.new('bar')
      struct = Psych.load(Psych.dump(thing))

      assert_equal 'hello', struct.bar
      assert_equal 'bar', struct.foo
    end

    def test_load
      obj = Psych.load(<<-eoyml)
--- !ruby/struct:PsychStructWithIvar
:foo: bar
:@bar: hello
      eoyml

      assert_equal 'hello', obj.bar
      assert_equal 'bar', obj.foo
    end
  end
end

Version data entries

27 entries across 27 versions & 2 rubygems

Version Path
psych-2.0.17-java test/psych/test_struct.rb
psych-2.0.17 test/psych/test_struct.rb
psych-2.0.16-java test/psych/test_struct.rb
psych-2.0.16 test/psych/test_struct.rb
psych-2.0.15-java test/psych/test_struct.rb
psych-2.0.15 test/psych/test_struct.rb
psych-2.0.14-java test/psych/test_struct.rb
psych-2.0.14 test/psych/test_struct.rb
psych-shopifork-2.0.13 test/psych/test_struct.rb
psych-2.0.14.pre1-java test/psych/test_struct.rb
psych-2.0.13 test/psych/test_struct.rb
psych-2.0.12 test/psych/test_struct.rb
psych-2.0.11 test/psych/test_struct.rb
psych-2.0.10 test/psych/test_struct.rb
psych-2.0.9 test/psych/test_struct.rb
psych-2.0.8 test/psych/test_struct.rb
psych-2.0.7 test/psych/test_struct.rb
psych-2.0.6 test/psych/test_struct.rb
psych-shopifork-2.0.5 test/psych/test_struct.rb
psych-2.0.5 test/psych/test_struct.rb