full coverage, I hope
This commit is contained in:
parent
122e9fc7e8
commit
e9d0f420bc
@ -1037,14 +1037,23 @@ TEST_CASE("BJData")
|
|||||||
|
|
||||||
SECTION("errors")
|
SECTION("errors")
|
||||||
{
|
{
|
||||||
json _;
|
SECTION("no byte follows")
|
||||||
// missing both bytes
|
{
|
||||||
std::vector<uint8_t> vec0 = {'h'};
|
json _;
|
||||||
CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vec0), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing BJData number: unexpected end of input", json::parse_error);
|
std::vector<uint8_t> vec0 = {'h'};
|
||||||
|
CHECK_THROWS_AS(_ = json::from_bjdata(vec0), json::parse_error&);
|
||||||
|
CHECK_THROWS_WITH(_ = json::from_bjdata(vec0), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing BJData number: unexpected end of input");
|
||||||
|
CHECK(json::from_bjdata(vec0, true, false).is_discarded());
|
||||||
|
}
|
||||||
|
|
||||||
// missing the 2nd byte
|
SECTION("only one byte follows")
|
||||||
std::vector<uint8_t> vec1 = {'h', 0x00};
|
{
|
||||||
CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vec1), "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing BJData number: unexpected end of input", json::parse_error);
|
json _;
|
||||||
|
std::vector<uint8_t> vec1 = {'h', 0x00};
|
||||||
|
CHECK_THROWS_AS(_ = json::from_bjdata(vec1), json::parse_error&);
|
||||||
|
CHECK_THROWS_WITH(_ = json::from_bjdata(vec1), "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing BJData number: unexpected end of input");
|
||||||
|
CHECK(json::from_bjdata(vec1, true, false).is_discarded());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2679,6 +2688,11 @@ TEST_CASE("BJData")
|
|||||||
CHECK_THROWS_WITH(_ = json::from_bjdata(vT0), "[json.exception.parse_error.110] parse error at byte 7: syntax error while parsing BJData number: unexpected end of input");
|
CHECK_THROWS_WITH(_ = json::from_bjdata(vT0), "[json.exception.parse_error.110] parse error at byte 7: syntax error while parsing BJData number: unexpected end of input");
|
||||||
CHECK(json::from_bjdata(vT0, true, false).is_discarded());
|
CHECK(json::from_bjdata(vT0, true, false).is_discarded());
|
||||||
|
|
||||||
|
std::vector<uint8_t> vu = {'[', '$', 'i', '#', '[', '$', 'i', '#', 'u', 1, 0};
|
||||||
|
CHECK_THROWS_AS(_ = json::from_bjdata(vu), json::parse_error&);
|
||||||
|
CHECK_THROWS_WITH(_ = json::from_bjdata(vu), "[json.exception.parse_error.110] parse error at byte 12: syntax error while parsing BJData number: unexpected end of input");
|
||||||
|
CHECK(json::from_bjdata(vu, true, false).is_discarded());
|
||||||
|
|
||||||
std::vector<uint8_t> vm = {'[', '$', 'i', '#', '[', '$', 'i', '#', 'm', 1, 0, 0, 0};
|
std::vector<uint8_t> vm = {'[', '$', 'i', '#', '[', '$', 'i', '#', 'm', 1, 0, 0, 0};
|
||||||
CHECK_THROWS_AS(_ = json::from_bjdata(vm), json::parse_error&);
|
CHECK_THROWS_AS(_ = json::from_bjdata(vm), json::parse_error&);
|
||||||
CHECK_THROWS_WITH(_ = json::from_bjdata(vm), "[json.exception.parse_error.110] parse error at byte 14: syntax error while parsing BJData number: unexpected end of input");
|
CHECK_THROWS_WITH(_ = json::from_bjdata(vm), "[json.exception.parse_error.110] parse error at byte 14: syntax error while parsing BJData number: unexpected end of input");
|
||||||
@ -2760,6 +2774,13 @@ TEST_CASE("BJData")
|
|||||||
CHECK(json::to_bjdata(j, true, true) == expected);
|
CHECK(json::to_bjdata(j, true, true) == expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SECTION("array of u")
|
||||||
|
{
|
||||||
|
json j = {50000, 50001};
|
||||||
|
std::vector<uint8_t> expected = {'[', '$', 'u', '#', 'i', 2, 0x50, 0xC3, 0x51, 0xC3};
|
||||||
|
CHECK(json::to_bjdata(j, true, true) == expected);
|
||||||
|
}
|
||||||
|
|
||||||
SECTION("array of l")
|
SECTION("array of l")
|
||||||
{
|
{
|
||||||
json j = {70000, -70000};
|
json j = {70000, -70000};
|
||||||
@ -2767,6 +2788,13 @@ TEST_CASE("BJData")
|
|||||||
CHECK(json::to_bjdata(j, true, true) == expected);
|
CHECK(json::to_bjdata(j, true, true) == expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SECTION("array of m")
|
||||||
|
{
|
||||||
|
json j = {3147483647, 3147483648};
|
||||||
|
std::vector<uint8_t> expected = {'[', '$', 'm', '#', 'i', 2, 0xFF, 0xC9, 0x9A, 0xBB, 0x00, 0xCA, 0x9A, 0xBB};
|
||||||
|
CHECK(json::to_bjdata(j, true, true) == expected);
|
||||||
|
}
|
||||||
|
|
||||||
SECTION("array of L")
|
SECTION("array of L")
|
||||||
{
|
{
|
||||||
json j = {5000000000, -5000000000};
|
json j = {5000000000, -5000000000};
|
||||||
@ -2824,7 +2852,7 @@ TEST_CASE("BJData")
|
|||||||
|
|
||||||
SECTION("array of m")
|
SECTION("array of m")
|
||||||
{
|
{
|
||||||
json j = {3147483647, 3147483648};
|
json j = {3147483647u, 3147483648u};
|
||||||
std::vector<uint8_t> expected = {'[', '$', 'm', '#', 'i', 2, 0xFF, 0xC9, 0x9A, 0xBB, 0x00, 0xCA, 0x9A, 0xBB};
|
std::vector<uint8_t> expected = {'[', '$', 'm', '#', 'i', 2, 0xFF, 0xC9, 0x9A, 0xBB, 0x00, 0xCA, 0x9A, 0xBB};
|
||||||
std::vector<uint8_t> expected_size = {'[', '#', 'i', 2, 'm', 0xFF, 0xC9, 0x9A, 0xBB, 'm', 0x00, 0xCA, 0x9A, 0xBB};
|
std::vector<uint8_t> expected_size = {'[', '#', 'i', 2, 'm', 0xFF, 0xC9, 0x9A, 0xBB, 'm', 0x00, 0xCA, 0x9A, 0xBB};
|
||||||
CHECK(json::to_bjdata(j, true, true) == expected);
|
CHECK(json::to_bjdata(j, true, true) == expected);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user