Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing testcase about NaN in unit-constructor1.cpp #2043

Merged
merged 1 commit into from
Apr 21, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions test/src/unit-constructor1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,21 @@ TEST_CASE("constructors")
CHECK(j.type() == json::value_t::number_float);
}

SECTION("NaN")
{
// NaN is stored properly, but serialized to null
json::number_float_t n(std::numeric_limits<json::number_float_t>::quiet_NaN());
json j(n);
CHECK(j.type() == json::value_t::number_float);

// check round trip of NaN
json::number_float_t d = j;
CHECK((std::isnan(d) and std::isnan(n)) == true);
nlohmann marked this conversation as resolved.
Show resolved Hide resolved

// check that NaN is serialized to null
CHECK(j.dump() == "null");
}

SECTION("infinity")
{
// infinity is stored properly, but serialized to null
Expand Down