From 5a485d56a377c896d842e4f44174f10b937cc213 Mon Sep 17 00:00:00 2001 From: Qianqian Fang Date: Sat, 19 Feb 2022 09:35:44 -0500 Subject: [PATCH] add half precision error test --- test/src/unit-bjdata.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/src/unit-bjdata.cpp b/test/src/unit-bjdata.cpp index f0519c5ca..fb8e20bab 100644 --- a/test/src/unit-bjdata.cpp +++ b/test/src/unit-bjdata.cpp @@ -1034,6 +1034,18 @@ TEST_CASE("BJData") CHECK(json::parse("1.5") == json::from_bjdata(std::vector({'h', 0x00, 0x3e}))); CHECK(json::parse("65504.0") == json::from_bjdata(std::vector({'h', 0xff, 0x7b}))); } + + SECTION("errors") + { + json _; + // missing both bytes + std::vector vec0 = {'h'}; + 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); + + // missing the 2nd byte + std::vector vec1 = {'h', 0}; + 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); + } } SECTION("half-precision float (edge cases)")