diff --git a/include/nlohmann/detail/output/binary_writer.hpp b/include/nlohmann/detail/output/binary_writer.hpp index 5f0fb55d8..f995d31ce 100644 --- a/include/nlohmann/detail/output/binary_writer.hpp +++ b/include/nlohmann/detail/output/binary_writer.hpp @@ -1851,11 +1851,13 @@ class binary_writer case input_format_t::bon8: oa->write_character(get_bon8_float_prefix(static_cast(n))); break; + // LCOV_EXCL_START case input_format_t::bson: case input_format_t::json: case input_format_t::ubjson: default: break; + // LCOV_EXCL_STOP } write_number(static_cast(n)); } @@ -1872,11 +1874,13 @@ class binary_writer case input_format_t::bon8: oa->write_character(get_bon8_float_prefix(n)); break; + // LCOV_EXCL_START case input_format_t::bson: case input_format_t::json: case input_format_t::ubjson: default: break; + // LCOV_EXCL_STOP } write_number(n); } diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 6d1a489a4..feda56644 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -15425,11 +15425,13 @@ class binary_writer case input_format_t::bon8: oa->write_character(get_bon8_float_prefix(static_cast(n))); break; + // LCOV_EXCL_START case input_format_t::bson: case input_format_t::json: case input_format_t::ubjson: default: break; + // LCOV_EXCL_STOP } write_number(static_cast(n)); } @@ -15446,11 +15448,13 @@ class binary_writer case input_format_t::bon8: oa->write_character(get_bon8_float_prefix(n)); break; + // LCOV_EXCL_START case input_format_t::bson: case input_format_t::json: case input_format_t::ubjson: default: break; + // LCOV_EXCL_STOP } write_number(n); } diff --git a/test/src/unit-bon8.cpp b/test/src/unit-bon8.cpp index 7be727343..4a56d7775 100644 --- a/test/src/unit-bon8.cpp +++ b/test/src/unit-bon8.cpp @@ -435,36 +435,61 @@ TEST_CASE("BON8") SECTION("floating-point numbers") { - SECTION("-1.0") + SECTION("special values") { - json j = -1.0; - std::vector expected = {0xFB}; - const auto result = json::to_bon8(j); - CHECK(result == expected); + SECTION("-1.0") + { + json j = -1.0; + std::vector expected = {0xFB}; + const auto result = json::to_bon8(j); + CHECK(result == expected); + } + + SECTION("0.0") + { + json j = 0.0; + std::vector expected = {0xFC}; + const auto result = json::to_bon8(j); + CHECK(result == expected); + } + + SECTION("1.0") + { + json j = 1.0; + std::vector expected = {0xFD}; + const auto result = json::to_bon8(j); + CHECK(result == expected); + } + + SECTION("-0.0") + { + json j = -0.0; + std::vector expected = {0x8E, 0x80, 0x00, 0x00, 0x00}; + const auto result = json::to_bon8(j); + CHECK(result == expected); + } } - SECTION("0.0") + SECTION("floats") { - json j = 0.0; - std::vector expected = {0xFC}; - const auto result = json::to_bon8(j); - CHECK(result == expected); + SECTION("2.0") + { + json j = 2.0; + std::vector expected = {0x8E, 0x40, 0x00, 0x00, 0x00}; + const auto result = json::to_bon8(j); + CHECK(result == expected); + } } - SECTION("1.0") + SECTION("doubles") { - json j = 1.0; - std::vector expected = {0xFD}; - const auto result = json::to_bon8(j); - CHECK(result == expected); - } - - SECTION("-0.0") - { - json j = -0.0; - std::vector expected = {0x8E, 0x80, 0x00, 0x00, 0x00}; - const auto result = json::to_bon8(j); - CHECK(result == expected); + SECTION("100000000.1") + { + json j = 100000000.1; + std::vector expected = {0x8F, 0x41, 0x97, 0xD7, 0x84, 0x00, 0x66, 0x66, 0x66}; + const auto result = json::to_bon8(j); + CHECK(result == expected); + } } }