mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 16:14:11 +01:00 
			
		
		
		
	Increased test coverage
This commit is contained in:
		| @@ -10,21 +10,37 @@ TEST_CASE("JsonVariant::add()") { | ||||
|   DynamicJsonDocument doc(4096); | ||||
|   JsonVariant var = doc.to<JsonVariant>(); | ||||
|  | ||||
|   SECTION("integer") { | ||||
|   SECTION("add integer to new variant") { | ||||
|     var.add(42); | ||||
|  | ||||
|     REQUIRE(var.as<std::string>() == "[42]"); | ||||
|   } | ||||
|  | ||||
|   SECTION("const char*") { | ||||
|   SECTION("add const char* to new variant") { | ||||
|     var.add("hello"); | ||||
|  | ||||
|     REQUIRE(var.as<std::string>() == "[\"hello\"]"); | ||||
|   } | ||||
|  | ||||
|   SECTION("std::string") { | ||||
|   SECTION("add std::string to new variant") { | ||||
|     var.add(std::string("hello")); | ||||
|  | ||||
|     REQUIRE(var.as<std::string>() == "[\"hello\"]"); | ||||
|   } | ||||
|  | ||||
|   SECTION("add integer to integer") { | ||||
|     var.set(123); | ||||
|  | ||||
|     var.add(456);  // no-op | ||||
|  | ||||
|     REQUIRE(var.as<std::string>() == "123"); | ||||
|   } | ||||
|  | ||||
|   SECTION("add integer to object") { | ||||
|     var["val"] = 123; | ||||
|  | ||||
|     var.add(456);  // no-op | ||||
|  | ||||
|     REQUIRE(var.as<std::string>() == "{\"val\":123}"); | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -158,6 +158,18 @@ TEST_CASE("Compare JsonVariant with JsonVariant") { | ||||
|     CHECK_FALSE(a > b); | ||||
|   } | ||||
|  | ||||
|   SECTION("42 vs 42U") { | ||||
|     a.set(42); | ||||
|     b.set(42U); | ||||
|  | ||||
|     CHECK(a == b); | ||||
|     CHECK(a <= b); | ||||
|     CHECK(a >= b); | ||||
|     CHECK_FALSE(a != b); | ||||
|     CHECK_FALSE(a < b); | ||||
|     CHECK_FALSE(a > b); | ||||
|   } | ||||
|  | ||||
|   SECTION("42 vs 42.0") { | ||||
|     a.set(42); | ||||
|     b.set(42.0); | ||||
| @@ -230,6 +242,30 @@ TEST_CASE("Compare JsonVariant with JsonVariant") { | ||||
|     CHECK_FALSE(a == b); | ||||
|   } | ||||
|  | ||||
|   SECTION("42U vs 42U") { | ||||
|     a.set(42U); | ||||
|     b.set(42U); | ||||
|  | ||||
|     CHECK(a == b); | ||||
|     CHECK(a <= b); | ||||
|     CHECK(a >= b); | ||||
|     CHECK_FALSE(a != b); | ||||
|     CHECK_FALSE(a < b); | ||||
|     CHECK_FALSE(a > b); | ||||
|   } | ||||
|  | ||||
|   SECTION("42U vs 42") { | ||||
|     a.set(42U); | ||||
|     b.set(42); | ||||
|  | ||||
|     CHECK(a == b); | ||||
|     CHECK(a <= b); | ||||
|     CHECK(a >= b); | ||||
|     CHECK_FALSE(a != b); | ||||
|     CHECK_FALSE(a < b); | ||||
|     CHECK_FALSE(a > b); | ||||
|   } | ||||
|  | ||||
|   SECTION("[1] vs [1]") { | ||||
|     a.add(1); | ||||
|     b.add(1); | ||||
|   | ||||
| @@ -83,4 +83,13 @@ TEST_CASE("JsonVariant::set(JsonVariant)") { | ||||
|     REQUIRE(doc1.memoryUsage() == JSON_STRING_SIZE(7)); | ||||
|     REQUIRE(doc2.memoryUsage() == JSON_STRING_SIZE(7)); | ||||
|   } | ||||
|  | ||||
|   SECTION("destination is unbound") { | ||||
|     JsonVariant unboundVariant; | ||||
|  | ||||
|     unboundVariant.set(var1); | ||||
|  | ||||
|     REQUIRE(unboundVariant.isUndefined()); | ||||
|     REQUIRE(unboundVariant.isNull()); | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -58,6 +58,15 @@ TEST_CASE("JsonVariant::operator[]") { | ||||
|       REQUIRE(1 == var[0].size()); | ||||
|       REQUIRE(std::string("world") == var[0]["hello"]); | ||||
|     } | ||||
|  | ||||
|     SECTION("variant[0] when variant contains an integer") { | ||||
|       var.set(123); | ||||
|  | ||||
|       var[0] = 345;  // no-op | ||||
|  | ||||
|       REQUIRE(var.is<int>()); | ||||
|       REQUIRE(var.as<int>() == 123); | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   SECTION("The JsonVariant is a JsonObject") { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user