mirror of
https://github.com/nlohmann/json.git
synced 2025-07-25 13:41:56 +03:00
✅ improved test coverage
This commit is contained in:
@ -54,6 +54,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
// roundtrip
|
||||
CHECK(json::from_msgpack(result) == j);
|
||||
CHECK(json::from_msgpack(result, true, false) == j);
|
||||
}
|
||||
|
||||
SECTION("boolean")
|
||||
@ -67,6 +68,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
// roundtrip
|
||||
CHECK(json::from_msgpack(result) == j);
|
||||
CHECK(json::from_msgpack(result, true, false) == j);
|
||||
}
|
||||
|
||||
SECTION("false")
|
||||
@ -78,6 +80,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
// roundtrip
|
||||
CHECK(json::from_msgpack(result) == j);
|
||||
CHECK(json::from_msgpack(result, true, false) == j);
|
||||
}
|
||||
}
|
||||
|
||||
@ -111,6 +114,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
// roundtrip
|
||||
CHECK(json::from_msgpack(result) == j);
|
||||
CHECK(json::from_msgpack(result, true, false) == j);
|
||||
}
|
||||
}
|
||||
|
||||
@ -141,6 +145,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
// roundtrip
|
||||
CHECK(json::from_msgpack(result) == j);
|
||||
CHECK(json::from_msgpack(result, true, false) == j);
|
||||
}
|
||||
}
|
||||
|
||||
@ -174,6 +179,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
// roundtrip
|
||||
CHECK(json::from_msgpack(result) == j);
|
||||
CHECK(json::from_msgpack(result, true, false) == j);
|
||||
}
|
||||
}
|
||||
|
||||
@ -208,6 +214,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
// roundtrip
|
||||
CHECK(json::from_msgpack(result) == j);
|
||||
CHECK(json::from_msgpack(result, true, false) == j);
|
||||
}
|
||||
}
|
||||
|
||||
@ -250,6 +257,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
// roundtrip
|
||||
CHECK(json::from_msgpack(result) == j);
|
||||
CHECK(json::from_msgpack(result, true, false) == j);
|
||||
}
|
||||
}
|
||||
|
||||
@ -300,6 +308,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
// roundtrip
|
||||
CHECK(json::from_msgpack(result) == j);
|
||||
CHECK(json::from_msgpack(result, true, false) == j);
|
||||
}
|
||||
}
|
||||
|
||||
@ -331,6 +340,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
// roundtrip
|
||||
CHECK(json::from_msgpack(result) == j);
|
||||
CHECK(json::from_msgpack(result, true, false) == j);
|
||||
}
|
||||
}
|
||||
|
||||
@ -347,6 +357,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
// roundtrip
|
||||
CHECK(json::from_msgpack(result) == j);
|
||||
CHECK(json::from_msgpack(result, true, false) == j);
|
||||
}
|
||||
|
||||
SECTION("-32768..-129 (int 16)")
|
||||
@ -379,6 +390,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
// roundtrip
|
||||
CHECK(json::from_msgpack(result) == j);
|
||||
CHECK(json::from_msgpack(result, true, false) == j);
|
||||
}
|
||||
}
|
||||
|
||||
@ -423,6 +435,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
// roundtrip
|
||||
CHECK(json::from_msgpack(result) == j);
|
||||
CHECK(json::from_msgpack(result, true, false) == j);
|
||||
}
|
||||
}
|
||||
|
||||
@ -472,6 +485,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
// roundtrip
|
||||
CHECK(json::from_msgpack(result) == j);
|
||||
CHECK(json::from_msgpack(result, true, false) == j);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -504,6 +518,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
// roundtrip
|
||||
CHECK(json::from_msgpack(result) == j);
|
||||
CHECK(json::from_msgpack(result, true, false) == j);
|
||||
}
|
||||
}
|
||||
|
||||
@ -536,6 +551,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
// roundtrip
|
||||
CHECK(json::from_msgpack(result) == j);
|
||||
CHECK(json::from_msgpack(result, true, false) == j);
|
||||
}
|
||||
}
|
||||
|
||||
@ -569,6 +585,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
// roundtrip
|
||||
CHECK(json::from_msgpack(result) == j);
|
||||
CHECK(json::from_msgpack(result, true, false) == j);
|
||||
}
|
||||
}
|
||||
|
||||
@ -610,6 +627,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
// roundtrip
|
||||
CHECK(json::from_msgpack(result) == j);
|
||||
CHECK(json::from_msgpack(result, true, false) == j);
|
||||
}
|
||||
}
|
||||
|
||||
@ -659,6 +677,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
// roundtrip
|
||||
CHECK(json::from_msgpack(result) == j);
|
||||
CHECK(json::from_msgpack(result, true, false) == j);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -679,6 +698,7 @@ TEST_CASE("MessagePack")
|
||||
// roundtrip
|
||||
CHECK(json::from_msgpack(result) == j);
|
||||
CHECK(json::from_msgpack(result) == v);
|
||||
CHECK(json::from_msgpack(result, true, false) == j);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -727,6 +747,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
// roundtrip
|
||||
CHECK(json::from_msgpack(result) == j);
|
||||
CHECK(json::from_msgpack(result, true, false) == j);
|
||||
}
|
||||
}
|
||||
|
||||
@ -758,6 +779,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
// roundtrip
|
||||
CHECK(json::from_msgpack(result) == j);
|
||||
CHECK(json::from_msgpack(result, true, false) == j);
|
||||
}
|
||||
}
|
||||
|
||||
@ -790,6 +812,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
// roundtrip
|
||||
CHECK(json::from_msgpack(result) == j);
|
||||
CHECK(json::from_msgpack(result, true, false) == j);
|
||||
}
|
||||
}
|
||||
|
||||
@ -824,6 +847,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
// roundtrip
|
||||
CHECK(json::from_msgpack(result) == j);
|
||||
CHECK(json::from_msgpack(result, true, false) == j);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -839,6 +863,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
// roundtrip
|
||||
CHECK(json::from_msgpack(result) == j);
|
||||
CHECK(json::from_msgpack(result, true, false) == j);
|
||||
}
|
||||
|
||||
SECTION("[null]")
|
||||
@ -850,6 +875,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
// roundtrip
|
||||
CHECK(json::from_msgpack(result) == j);
|
||||
CHECK(json::from_msgpack(result, true, false) == j);
|
||||
}
|
||||
|
||||
SECTION("[1,2,3,4,5]")
|
||||
@ -861,6 +887,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
// roundtrip
|
||||
CHECK(json::from_msgpack(result) == j);
|
||||
CHECK(json::from_msgpack(result, true, false) == j);
|
||||
}
|
||||
|
||||
SECTION("[[[[]]]]")
|
||||
@ -872,6 +899,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
// roundtrip
|
||||
CHECK(json::from_msgpack(result) == j);
|
||||
CHECK(json::from_msgpack(result, true, false) == j);
|
||||
}
|
||||
|
||||
SECTION("array 16")
|
||||
@ -886,6 +914,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
// roundtrip
|
||||
CHECK(json::from_msgpack(result) == j);
|
||||
CHECK(json::from_msgpack(result, true, false) == j);
|
||||
}
|
||||
|
||||
SECTION("array 32")
|
||||
@ -909,6 +938,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
// roundtrip
|
||||
CHECK(json::from_msgpack(result) == j);
|
||||
CHECK(json::from_msgpack(result, true, false) == j);
|
||||
}
|
||||
}
|
||||
|
||||
@ -923,6 +953,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
// roundtrip
|
||||
CHECK(json::from_msgpack(result) == j);
|
||||
CHECK(json::from_msgpack(result, true, false) == j);
|
||||
}
|
||||
|
||||
SECTION("{\"\":null}")
|
||||
@ -934,6 +965,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
// roundtrip
|
||||
CHECK(json::from_msgpack(result) == j);
|
||||
CHECK(json::from_msgpack(result, true, false) == j);
|
||||
}
|
||||
|
||||
SECTION("{\"a\": {\"b\": {\"c\": {}}}}")
|
||||
@ -948,6 +980,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
// roundtrip
|
||||
CHECK(json::from_msgpack(result) == j);
|
||||
CHECK(json::from_msgpack(result, true, false) == j);
|
||||
}
|
||||
|
||||
SECTION("map 16")
|
||||
@ -971,6 +1004,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
// roundtrip
|
||||
CHECK(json::from_msgpack(result) == j);
|
||||
CHECK(json::from_msgpack(result, true, false) == j);
|
||||
}
|
||||
|
||||
SECTION("map 32")
|
||||
@ -1001,6 +1035,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
// roundtrip
|
||||
CHECK(json::from_msgpack(result) == j);
|
||||
CHECK(json::from_msgpack(result, true, false) == j);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1019,10 +1054,12 @@ TEST_CASE("MessagePack")
|
||||
CHECK_THROWS_AS(json::from_msgpack(std::vector<uint8_t>()), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>()),
|
||||
"[json.exception.parse_error.110] parse error at 1: unexpected end of input");
|
||||
CHECK(json::from_msgpack(std::vector<uint8_t>(), true, false).is_discarded());
|
||||
}
|
||||
|
||||
SECTION("too short byte vector")
|
||||
{
|
||||
CHECK_THROWS_AS(json::from_msgpack(std::vector<uint8_t>({0x87})), json::parse_error&);
|
||||
CHECK_THROWS_AS(json::from_msgpack(std::vector<uint8_t>({0xcc})), json::parse_error&);
|
||||
CHECK_THROWS_AS(json::from_msgpack(std::vector<uint8_t>({0xcd})), json::parse_error&);
|
||||
CHECK_THROWS_AS(json::from_msgpack(std::vector<uint8_t>({0xcd, 0x00})), json::parse_error&);
|
||||
@ -1038,7 +1075,11 @@ TEST_CASE("MessagePack")
|
||||
CHECK_THROWS_AS(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00})), json::parse_error&);
|
||||
CHECK_THROWS_AS(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})), json::parse_error&);
|
||||
CHECK_THROWS_AS(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})), json::parse_error&);
|
||||
CHECK_THROWS_AS(json::from_msgpack(std::vector<uint8_t>({0xa5, 0x68, 0x65})), json::parse_error&);
|
||||
CHECK_THROWS_AS(json::from_msgpack(std::vector<uint8_t>({0x92, 0x01})), json::parse_error&);
|
||||
|
||||
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0x87})),
|
||||
"[json.exception.parse_error.110] parse error at 2: unexpected end of input");
|
||||
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xcc})),
|
||||
"[json.exception.parse_error.110] parse error at 2: unexpected end of input");
|
||||
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xcd})),
|
||||
@ -1069,6 +1110,29 @@ TEST_CASE("MessagePack")
|
||||
"[json.exception.parse_error.110] parse error at 8: unexpected end of input");
|
||||
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})),
|
||||
"[json.exception.parse_error.110] parse error at 9: unexpected end of input");
|
||||
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xa5, 0x68, 0x65})),
|
||||
"[json.exception.parse_error.110] parse error at 4: unexpected end of input");
|
||||
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0x92, 0x01})),
|
||||
"[json.exception.parse_error.110] parse error at 3: unexpected end of input");
|
||||
|
||||
CHECK(json::from_msgpack(std::vector<uint8_t>({0x87}), true, false).is_discarded());
|
||||
CHECK(json::from_msgpack(std::vector<uint8_t>({0xcc}), true, false).is_discarded());
|
||||
CHECK(json::from_msgpack(std::vector<uint8_t>({0xcd}), true, false).is_discarded());
|
||||
CHECK(json::from_msgpack(std::vector<uint8_t>({0xcd, 0x00}), true, false).is_discarded());
|
||||
CHECK(json::from_msgpack(std::vector<uint8_t>({0xce}), true, false).is_discarded());
|
||||
CHECK(json::from_msgpack(std::vector<uint8_t>({0xce, 0x00}), true, false).is_discarded());
|
||||
CHECK(json::from_msgpack(std::vector<uint8_t>({0xce, 0x00, 0x00}), true, false).is_discarded());
|
||||
CHECK(json::from_msgpack(std::vector<uint8_t>({0xce, 0x00, 0x00, 0x00}), true, false).is_discarded());
|
||||
CHECK(json::from_msgpack(std::vector<uint8_t>({0xcf}), true, false).is_discarded());
|
||||
CHECK(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00}), true, false).is_discarded());
|
||||
CHECK(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00}), true, false).is_discarded());
|
||||
CHECK(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00}), true, false).is_discarded());
|
||||
CHECK(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00}), true, false).is_discarded());
|
||||
CHECK(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00}), true, false).is_discarded());
|
||||
CHECK(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}), true, false).is_discarded());
|
||||
CHECK(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}), true, false).is_discarded());
|
||||
CHECK(json::from_msgpack(std::vector<uint8_t>({0xa5, 0x68, 0x65}), true, false).is_discarded());
|
||||
CHECK(json::from_msgpack(std::vector<uint8_t>({0x92, 0x01}), true, false).is_discarded());
|
||||
}
|
||||
|
||||
SECTION("unsupported bytes")
|
||||
@ -1078,9 +1142,12 @@ TEST_CASE("MessagePack")
|
||||
CHECK_THROWS_AS(json::from_msgpack(std::vector<uint8_t>({0xc1})), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xc1})),
|
||||
"[json.exception.parse_error.112] parse error at 1: error reading MessagePack; last byte: 0xC1");
|
||||
CHECK(json::from_msgpack(std::vector<uint8_t>({0xc6}), true, false).is_discarded());
|
||||
|
||||
CHECK_THROWS_AS(json::from_msgpack(std::vector<uint8_t>({0xc6})), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0xc6})),
|
||||
"[json.exception.parse_error.112] parse error at 1: error reading MessagePack; last byte: 0xC6");
|
||||
CHECK(json::from_msgpack(std::vector<uint8_t>({0xc6}), true, false).is_discarded());
|
||||
}
|
||||
|
||||
SECTION("all unsupported bytes")
|
||||
@ -1098,6 +1165,7 @@ TEST_CASE("MessagePack")
|
||||
})
|
||||
{
|
||||
CHECK_THROWS_AS(json::from_msgpack(std::vector<uint8_t>({static_cast<uint8_t>(byte)})), json::parse_error&);
|
||||
CHECK(json::from_msgpack(std::vector<uint8_t>({static_cast<uint8_t>(byte)}), true, false).is_discarded());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1107,6 +1175,7 @@ TEST_CASE("MessagePack")
|
||||
CHECK_THROWS_AS(json::from_msgpack(std::vector<uint8_t>({0x81, 0xff, 0x01})), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0x81, 0xff, 0x01})),
|
||||
"[json.exception.parse_error.113] parse error at 2: expected a MessagePack string; last byte: 0xFF");
|
||||
CHECK(json::from_msgpack(std::vector<uint8_t>({0x81, 0xff, 0x01}), true, false).is_discarded());
|
||||
}
|
||||
|
||||
SECTION("strict mode")
|
||||
@ -1123,6 +1192,7 @@ TEST_CASE("MessagePack")
|
||||
CHECK_THROWS_AS(json::from_msgpack(vec), json::parse_error&);
|
||||
CHECK_THROWS_WITH(json::from_msgpack(vec),
|
||||
"[json.exception.parse_error.110] parse error at 2: expected end of input");
|
||||
CHECK(json::from_msgpack(vec, true, false).is_discarded());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user