From a9601a550729b2784d029edc624d01e61ea9b9cd Mon Sep 17 00:00:00 2001 From: Blacksmoke16 Date: Mon, 5 Aug 2019 11:15:08 -0400 Subject: [PATCH] Revert Yaml.deserialize to allow for anchors/alises (#22) --- spec/converters/yaml_spec.cr | 2 +- src/converters/yaml.cr | 47 ++---------------------------------- 2 files changed, 3 insertions(+), 46 deletions(-) diff --git a/spec/converters/yaml_spec.cr b/spec/converters/yaml_spec.cr index 48a9d09..f32eb90 100644 --- a/spec/converters/yaml_spec.cr +++ b/spec/converters/yaml_spec.cr @@ -238,7 +238,7 @@ describe OQ::Converters::Yaml do end end - pending "with anchors" do + describe "with anchors" do it "should output correctly" do run_binary(ANCHORS, args: ["-i", "yaml", "-c", "."]) do |output| output.should eq %({"base":{"name":"Everyone has same name"},"foo":{"name":"Everyone has same name","age":10},"bar":{"name":"Everyone has same name","age":20}}\n) diff --git a/src/converters/yaml.cr b/src/converters/yaml.cr index 8cc4d64..70b290e 100644 --- a/src/converters/yaml.cr +++ b/src/converters/yaml.cr @@ -6,52 +6,9 @@ class JSON::Builder end module OQ::Converters::Yaml - # ameba:disable Metrics/CyclomaticComplexity + # OPTIMIZE: Figure out a way to handle aliases/anchors while streaming. def self.deserialize(input : IO, output : IO, **args) : Nil - yaml = YAML::PullParser.new(input) - json = JSON::Builder.new(output) - - yaml.read_stream do - loop do - case yaml.kind - when .document_start? - json.start_document - when .document_end? - json.end_document - yaml.read_next - break - when .scalar? - string = yaml.value - - if json.next_is_object_key? - json.scalar(string) - else - scalar = YAML::Schema::Core.parse_scalar(yaml) - case scalar - when Nil - json.scalar(scalar) - when Bool - json.scalar(scalar) - when Int64 - json.scalar(scalar) - when Float64 - json.scalar(scalar) - else - json.scalar(string) - end - end - when .sequence_start? - json.start_array - when .sequence_end? - json.end_array - when .mapping_start? - json.start_object - when .mapping_end? - json.end_object - end - yaml.read_next - end - end + YAML.parse(input).to_json output end # ameba:disable Metrics/CyclomaticComplexity