Skip to content

Commit

Permalink
test: set precision if non-toml float is given
Browse files Browse the repository at this point in the history
in toml-test encoder test, it passes a large integer with float type.
in that case, we used a std::stringstream, so no prec information is
stored.
  • Loading branch information
ToruNiina committed Jun 16, 2024
1 parent 717c2d8 commit 29f8517
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions tests/to_toml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ toml::value convert_to_toml(const nlohmann::json& j)
{
return f_r.unwrap();
}
else
else // not conform TOML floating-point syntax.
{
// toml-test converts "inf" into "Inf"
if(value == "Inf" || value == "+Inf")
Expand All @@ -52,9 +52,11 @@ toml::value convert_to_toml(const nlohmann::json& j)
{
return toml::value(-std::numeric_limits<double>::infinity());
}
else
else // sometimes toml-test uses large int with type:float
{
return toml::value(toml::detail::from_string<double>(value).unwrap());
toml::floating_format_info fmt;
fmt.prec = value.size();
return toml::value(toml::detail::from_string<double>(value).unwrap(), fmt);
}
}
}
Expand Down

0 comments on commit 29f8517

Please sign in to comment.