File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -148,6 +148,23 @@ class YAMLAttrWithTimeArray3
148148 property value : Array (Time )
149149end
150150
151+ module YAMLAttrPointConverter
152+ def self.from_yaml (ctx : YAML ::ParseContext , node : YAML ::Nodes ::Node )
153+ YAMLAttrPoint .new(ctx, node)
154+ end
155+
156+ def self.to_yaml (value, yaml : YAML ::Nodes ::Builder )
157+ value.to_yaml(yaml)
158+ end
159+ end
160+
161+ class YAMLAttrWithSerializableArray
162+ include YAML ::Serializable
163+
164+ @[YAML ::Field (converter: YAML ::ArrayConverter (YAMLAttrPointConverter ))]
165+ property value : Array (YAMLAttrPoint )
166+ end
167+
151168class YAMLAttrWithSimpleMapping
152169 include YAML ::Serializable
153170
@@ -986,6 +1003,14 @@ describe "YAML::Serializable" do
9861003 yaml.value.map(& .to_s).should eq([" 2014-10-31 23:37:16 UTC" ])
9871004 yaml.to_yaml.should eq(string)
9881005 end
1006+
1007+ it " uses correct array element type" do
1008+ string = %( ---\n value:\n - x: 1\n y: 2\n )
1009+ yaml = YAMLAttrWithSerializableArray .from_yaml(string)
1010+ yaml.value.should be_a(Array (YAMLAttrPoint ))
1011+ yaml.value.should eq([YAMLAttrPoint .new(1 , 2 )])
1012+ yaml.to_yaml.should eq(string)
1013+ end
9891014 end
9901015
9911016 it " parses nilable union" do
Original file line number Diff line number Diff line change @@ -376,7 +376,10 @@ module YAML::ArrayConverter(Converter)
376376 node.raise " Expected sequence, not #{ node.kind } "
377377 end
378378
379- ary = Array (typeof (@converter .from_yaml(ctx, node))).new
379+ ary = Array (typeof (begin
380+ value = uninitialized YAML ::Nodes ::Node
381+ @converter .from_yaml(ctx, value)
382+ end )).new
380383
381384 node.each do |value |
382385 ary << @converter .from_yaml(ctx, value)
You can’t perform that action at this time.
0 commit comments