Skip to content

Commit

Permalink
Implement BigDecimal.from_yaml (#7398)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sija authored and straight-shoota committed Feb 10, 2019
1 parent 4e0f731 commit 80b41fe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions spec/std/yaml/serialization_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ describe "YAML serialization" do
big.should eq(BigFloat.new("1234.567891011121314"))
end

it "does for BigDecimal" do
big = BigDecimal.from_yaml("1234.567891011121314")
big.should be_a(BigDecimal)
big.should eq(BigDecimal.new("1234.567891011121314"))
end

it "does for Enum with number" do
YAMLSpecEnum.from_yaml(%("1")).should eq(YAMLSpecEnum::One)

Expand Down
8 changes: 8 additions & 0 deletions src/big/yaml.cr
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,11 @@ def BigFloat.new(ctx : YAML::ParseContext, node : YAML::Nodes::Node)

BigFloat.new(node.value)
end

def BigDecimal.new(ctx : YAML::ParseContext, node : YAML::Nodes::Node)
unless node.is_a?(YAML::Nodes::Scalar)
node.raise "Expected scalar, not #{node.class}"
end

BigDecimal.new(node.value)
end

0 comments on commit 80b41fe

Please sign in to comment.