From c379d02b3e41857e8bab9b7e13a255431f435af9 Mon Sep 17 00:00:00 2001 From: chenguoping Date: Thu, 16 Apr 2020 10:23:21 +0800 Subject: [PATCH] Add missing testcase about NaN in unit-constructor1.cpp --- test/src/unit-constructor1.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/src/unit-constructor1.cpp b/test/src/unit-constructor1.cpp index 4ce91676..dc3507bc 100644 --- a/test/src/unit-constructor1.cpp +++ b/test/src/unit-constructor1.cpp @@ -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::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); + + // check that NaN is serialized to null + CHECK(j.dump() == "null"); + } + SECTION("infinity") { // infinity is stored properly, but serialized to null