Skip to content

Commit

Permalink
✅ improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
nlohmann committed Jul 24, 2020
1 parent b315fe4 commit 3366241
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
4 changes: 2 additions & 2 deletions include/nlohmann/detail/output/binary_writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1434,7 +1434,7 @@ class binary_writer
return 'L';
}
// anything else is treated as high-precision number
return 'H';
return 'H'; // LCOV_EXCL_LINE
}

case value_t::number_unsigned:
Expand All @@ -1460,7 +1460,7 @@ class binary_writer
return 'L';
}
// anything else is treated as high-precision number
return 'H';
return 'H'; // LCOV_EXCL_LINE
}

case value_t::number_float:
Expand Down
4 changes: 2 additions & 2 deletions single_include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14153,7 +14153,7 @@ class binary_writer
return 'L';
}
// anything else is treated as high-precision number
return 'H';
return 'H'; // LCOV_EXCL_LINE
}

case value_t::number_unsigned:
Expand All @@ -14179,7 +14179,7 @@ class binary_writer
return 'L';
}
// anything else is treated as high-precision number
return 'H';
return 'H'; // LCOV_EXCL_LINE
}

case value_t::number_float:
Expand Down
19 changes: 13 additions & 6 deletions test/src/unit-ubjson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -797,12 +797,19 @@ TEST_CASE("UBJSON")

SECTION("errors")
{
std::vector<uint8_t> vec1 = {'H', 'i', 2, '1', 'A', '3'};
CHECK_THROWS_WITH_AS(json::from_ubjson(vec1), "[json.exception.parse_error.115] parse error at byte 5: syntax error while parsing UBJSON high-precision number: invalid number text: 1A", json::parse_error);
std::vector<uint8_t> vec2 = {'H', 'i', 2, '1', '.'};
CHECK_THROWS_WITH_AS(json::from_ubjson(vec2), "[json.exception.parse_error.115] parse error at byte 5: syntax error while parsing UBJSON high-precision number: invalid number text: 1.", json::parse_error);
std::vector<uint8_t> vec3 = {'H', 2, '1', '0'};
CHECK_THROWS_WITH_AS(json::from_ubjson(vec3), "[json.exception.parse_error.113] parse error at byte 2: syntax error while parsing UBJSON size: expected length type specification (U, i, I, l, L) after '#'; last byte: 0x02", json::parse_error);
// error while parsing length
std::vector<uint8_t> vec0 = {'H', 'i'};
CHECK(json::from_ubjson(vec0, true, false).is_discarded());
// error while parsing string
std::vector<uint8_t> vec1 = {'H', 'i', '1'};
CHECK(json::from_ubjson(vec1, true, false).is_discarded());

std::vector<uint8_t> vec2 = {'H', 'i', 2, '1', 'A', '3'};
CHECK_THROWS_WITH_AS(json::from_ubjson(vec2), "[json.exception.parse_error.115] parse error at byte 5: syntax error while parsing UBJSON high-precision number: invalid number text: 1A", json::parse_error);
std::vector<uint8_t> vec3 = {'H', 'i', 2, '1', '.'};
CHECK_THROWS_WITH_AS(json::from_ubjson(vec3), "[json.exception.parse_error.115] parse error at byte 5: syntax error while parsing UBJSON high-precision number: invalid number text: 1.", json::parse_error);
std::vector<uint8_t> vec4 = {'H', 2, '1', '0'};
CHECK_THROWS_WITH_AS(json::from_ubjson(vec4), "[json.exception.parse_error.113] parse error at byte 2: syntax error while parsing UBJSON size: expected length type specification (U, i, I, l, L) after '#'; last byte: 0x02", json::parse_error);
}

SECTION("serialization")
Expand Down

0 comments on commit 3366241

Please sign in to comment.