ruby-changes:14435
From: tenderlove <ko1@a...>
Date: Sun, 10 Jan 2010 07:11:45 +0900 (JST)
Subject: [ruby-changes:14435] Ruby:r26265 (trunk): * test/yaml/test_struct.rb Test for dealing with structs that have
tenderlove 2010-01-10 07:11:35 +0900 (Sun, 10 Jan 2010) New Revision: 26265 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=26265 Log: * test/yaml/test_struct.rb Test for dealing with structs that have instance variables Added files: trunk/test/yaml/test_struct.rb Index: test/yaml/test_struct.rb =================================================================== --- test/yaml/test_struct.rb (revision 0) +++ test/yaml/test_struct.rb (revision 26265) @@ -0,0 +1,33 @@ +require 'test/unit' +require 'yaml' + +class StructWithIvar < Struct.new(:foo) + attr_reader :bar + def initialize *args + super + @bar = 'hello' + end +end + +module YAML + class TestStruct < MiniTest::Unit::TestCase + def test_roundtrip + thing = StructWithIvar.new('bar') + struct = YAML.load(YAML.dump(thing)) + + assert_equal 'hello', struct.bar + assert_equal 'bar', struct.foo + end + + def test_load + obj = YAML.load(<<-eoyml) +--- !ruby/struct:StructWithIvar +:foo: bar +:@bar: hello + eoyml + + assert_equal 'hello', obj.bar + assert_equal 'bar', obj.foo + end + end +end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/