优化了平衡,尤其对于向后倾倒的几种极限情况进行优化

This commit is contained in:
myperworld committed 2025-08-16 22:32:06 +08:00
1 parent 10aba2664d
commit fcb8af8163
693 files changed
+2427 -70

No files matched your search

@@ -0,0 +1,57 @@
// ArduinoJson - https://arduinojson.org
// Copyright © 2014-2023, Benoit BLANCHON
// MIT License
#include <ArduinoJson.h>
#include <catch.hpp>
TEST_CASE("serialize JsonArray to std::string") {
DynamicJsonDocument doc(4096);
JsonArray array = doc.to<JsonArray>();
array.add(4);
array.add(2);
SECTION("serializeJson()") {
std::string json;
serializeJson(array, json);
REQUIRE("[4,2]" == json);
}
SECTION("serializeJsonPretty") {
std::string json;
serializeJsonPretty(array, json);
REQUIRE("[\r\n 4,\r\n 2\r\n]" == json);
}
}
TEST_CASE("serialize JsonObject to std::string") {
DynamicJsonDocument doc(4096);
JsonObject obj = doc.to<JsonObject>();
obj["key"] = "value";
SECTION("object") {
std::string json;
serializeJson(doc, json);
REQUIRE("{\"key\":\"value\"}" == json);
}
SECTION("serializeJsonPretty") {
std::string json;
serializeJsonPretty(doc, json);
REQUIRE("{\r\n \"key\": \"value\"\r\n}" == json);
}
}
TEST_CASE("serialize an std::string containing a NUL") {
StaticJsonDocument<256> doc;
doc.set(std::string("hello\0world", 11));
CHECK(doc.memoryUsage() == 12);
std::string json;
serializeJson(doc, json);
CHECK("\"hello\\u0000world\"" == json);
}