Files
Benoit Blanchon 18671a5f3b Replace catch with doctest
This reduces the build times by about 38%
2026-07-06 17:59:49 +02:00

32 lines
667 B
C++

#define ARDUINOJSON_ENABLE_NAN 1
#include <ArduinoJson.h>
#include <doctest.h>
#include <limits>
namespace my {
using ArduinoJson::detail::isnan;
} // namespace my
TEST_CASE("ARDUINOJSON_ENABLE_NAN == 1") {
JsonDocument doc;
JsonObject root = doc.to<JsonObject>();
SUBCASE("serializeJson()") {
root["X"] = std::numeric_limits<double>::signaling_NaN();
std::string json;
serializeJson(doc, json);
REQUIRE(json == "{\"X\":NaN}");
}
SUBCASE("deserializeJson()") {
DeserializationError err = deserializeJson(doc, "{\"X\":NaN}");
float x = doc["X"];
REQUIRE(err == DeserializationError::Ok);
REQUIRE(my::isnan(x));
}
}