2017-07-14 02:15:58 -04:00
|
|
|
# frozen_string_literal: true
|
2013-03-26 10:55:04 -04:00
|
|
|
require_relative 'helper'
|
2010-03-28 17:49:37 -04:00
|
|
|
|
|
|
|
module Psych
|
|
|
|
class Tagged
|
|
|
|
yaml_tag '!foo'
|
|
|
|
|
|
|
|
attr_accessor :baz
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
@baz = 'bar'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-06-21 14:22:54 -04:00
|
|
|
class Foo
|
|
|
|
attr_accessor :parent
|
|
|
|
|
|
|
|
def initialize parent
|
|
|
|
@parent = parent
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-03-28 17:49:37 -04:00
|
|
|
class TestObject < TestCase
|
|
|
|
def test_dump_with_tag
|
|
|
|
tag = Tagged.new
|
|
|
|
assert_match('foo', Psych.dump(tag))
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_tag_round_trip
|
|
|
|
tag = Tagged.new
|
|
|
|
tag2 = Psych.load(Psych.dump(tag))
|
|
|
|
assert_equal tag.baz, tag2.baz
|
|
|
|
assert_instance_of(Tagged, tag2)
|
|
|
|
end
|
2011-06-21 14:22:54 -04:00
|
|
|
|
|
|
|
def test_cyclic_references
|
|
|
|
foo = Foo.new(nil)
|
|
|
|
foo.parent = foo
|
|
|
|
loaded = Psych.load Psych.dump foo
|
|
|
|
|
|
|
|
assert_instance_of(Foo, loaded)
|
|
|
|
assert_equal loaded, loaded.parent
|
|
|
|
end
|
2010-03-28 17:49:37 -04:00
|
|
|
end
|
|
|
|
end
|