From 2f007ca092f1bab33a1ade0dbfe05eef46998b90 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Tue, 20 Jun 2017 22:03:36 +0200 Subject: [PATCH] :white_check_mark: improved coverage --- src/json.hpp | 4 ++-- test/src/unit-cbor.cpp | 7 +++++++ test/src/unit-msgpack.cpp | 7 +++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/json.hpp b/src/json.hpp index c312dfbb..40c7e63a 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -9986,7 +9986,7 @@ class basic_json } else { - vec[i] = static_cast(current); + vec[i] = static_cast(current); // LCOV_EXCL_LINE } } @@ -10744,7 +10744,7 @@ class basic_json } else { - oa->write_character(vec[i]); + oa->write_character(vec[i]); // LCOV_EXCL_LINE } } } diff --git a/test/src/unit-cbor.cpp b/test/src/unit-cbor.cpp index debb3732..5638d490 100644 --- a/test/src/unit-cbor.cpp +++ b/test/src/unit-cbor.cpp @@ -1253,6 +1253,13 @@ TEST_CASE("CBOR") } } } + + SECTION("invalid string in map") + { + CHECK_THROWS_AS(json::from_cbor(std::vector({0xa1, 0xff, 0x01})), json::parse_error); + CHECK_THROWS_WITH(json::from_cbor(std::vector({0xa1, 0xff, 0x01})), + "[json.exception.parse_error.113] parse error at 2: expected a CBOR string; last byte: 0xff"); + } } } diff --git a/test/src/unit-msgpack.cpp b/test/src/unit-msgpack.cpp index a580913d..5b1c301d 100644 --- a/test/src/unit-msgpack.cpp +++ b/test/src/unit-msgpack.cpp @@ -1094,6 +1094,13 @@ TEST_CASE("MessagePack") } } } + + SECTION("invalid string in map") + { + CHECK_THROWS_AS(json::from_msgpack(std::vector({0x81, 0xff, 0x01})), json::parse_error); + CHECK_THROWS_WITH(json::from_msgpack(std::vector({0x81, 0xff, 0x01})), + "[json.exception.parse_error.113] parse error at 2: expected a MessagePack string; last byte: 0xff"); + } } }