|
7 | 7 | # [ruby-core:01946] |
8 | 8 | module Psych_Tests |
9 | 9 | StructTest = Struct::new( :c ) |
| 10 | + DataTest = Data.define( :c ) |
10 | 11 | end |
11 | 12 |
|
12 | 13 | class Psych_Unit_Tests < Psych::TestCase |
@@ -1066,6 +1067,42 @@ def test_ruby_struct |
1066 | 1067 |
|
1067 | 1068 | end |
1068 | 1069 |
|
| 1070 | + def test_ruby_data |
| 1071 | + Object.remove_const :MyBookData if Object.const_defined?(:MyBookData) |
| 1072 | + # Ruby Data value objects |
| 1073 | + book_class = Data.define(:author, :title, :year, :isbn) |
| 1074 | + Object.const_set(:MyBookData, book_class) |
| 1075 | + assert_to_yaml( |
| 1076 | + [ book_class.new( "Yukihiro Matsumoto", "Ruby in a Nutshell", 2002, "0-596-00214-9" ), |
| 1077 | + book_class.new( [ 'Dave Thomas', 'Andy Hunt' ], "The Pickaxe", 2002, |
| 1078 | + book_class.new( "This should be the ISBN", "but I have more data here", 2002, "None" ) |
| 1079 | + ) ], <<EOY |
| 1080 | +- !ruby/data:MyBookData |
| 1081 | + author: Yukihiro Matsumoto |
| 1082 | + title: Ruby in a Nutshell |
| 1083 | + year: 2002 |
| 1084 | + isbn: 0-596-00214-9 |
| 1085 | +- !ruby/data:MyBookData |
| 1086 | + author: |
| 1087 | + - Dave Thomas |
| 1088 | + - Andy Hunt |
| 1089 | + title: The Pickaxe |
| 1090 | + year: 2002 |
| 1091 | + isbn: !ruby/data:MyBookData |
| 1092 | + author: This should be the ISBN |
| 1093 | + title: but I have more data here |
| 1094 | + year: 2002 |
| 1095 | + isbn: None |
| 1096 | +EOY |
| 1097 | + ) |
| 1098 | + |
| 1099 | + assert_to_yaml( Psych_Tests::DataTest.new( 123 ), <<EOY ) |
| 1100 | +--- !ruby/data:Psych_Tests::DataTest |
| 1101 | +c: 123 |
| 1102 | +EOY |
| 1103 | + |
| 1104 | + end |
| 1105 | + |
1069 | 1106 | def test_ruby_rational |
1070 | 1107 | assert_to_yaml( Rational(1, 2), <<EOY ) |
1071 | 1108 | --- !ruby/object:Rational |
|
0 commit comments