diff --git a/spec/std/yaml/any_spec.cr b/spec/std/yaml/any_spec.cr index 33c8dc458db4..ffab8f14babc 100644 --- a/spec/std/yaml/any_spec.cr +++ b/spec/std/yaml/any_spec.cr @@ -236,6 +236,26 @@ describe YAML::Any do YAML.parse("*foo") end end + + it "gets yes/no unquoted booleans" do + YAML.parse("yes").as_bool.should be_true + YAML.parse("no").as_bool.should be_false + YAML.parse("'yes'").as_bool?.should be_nil + YAML.parse("'no'").as_bool?.should be_nil + YAML::Any.from_yaml("yes").as_bool.should be_true + YAML::Any.from_yaml("no").as_bool.should be_false + YAML::Any.from_yaml("'yes'").as_bool?.should be_nil + YAML::Any.from_yaml("'no'").as_bool?.should be_nil + end + + it "doesn't get quoted numbers" do + YAML.parse("1").as_i64.should eq(1) + YAML.parse("'1'").as_i64?.should be_nil + YAML.parse("'1'").as_s?.should eq("1") + YAML::Any.from_yaml("1").as_i64.should eq(1) + YAML::Any.from_yaml("'1'").as_i64?.should be_nil + YAML::Any.from_yaml("'1'").as_s?.should eq("1") + end end describe "#size" do diff --git a/src/yaml/any.cr b/src/yaml/any.cr index 8acd9fa057df..1518623efd5f 100644 --- a/src/yaml/any.cr +++ b/src/yaml/any.cr @@ -31,7 +31,7 @@ struct YAML::Any def self.new(ctx : YAML::ParseContext, node : YAML::Nodes::Node) case node when YAML::Nodes::Scalar - new YAML::Schema::Core.parse_scalar(node.value) + new YAML::Schema::Core.parse_scalar(node) when YAML::Nodes::Sequence ary = [] of YAML::Any