From d7b032f565701aff9c05ed8c93a8de80b8323b3c Mon Sep 17 00:00:00 2001
From: Niels Lohmann <mail@nlohmann.me>
Date: Wed, 13 May 2020 21:28:43 +0200
Subject: [PATCH] :white_check_mark: add tests to improve coverage

---
 include/nlohmann/detail/input/binary_reader.hpp  | 4 ++--
 include/nlohmann/detail/output/binary_writer.hpp | 4 +---
 single_include/nlohmann/json.hpp                 | 8 +++-----
 test/src/unit-json_pointer.cpp                   | 3 +++
 test/src/unit-regression.cpp                     | 5 +++++
 5 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/include/nlohmann/detail/input/binary_reader.hpp b/include/nlohmann/detail/input/binary_reader.hpp
index 25de9bda..a5dc00b1 100644
--- a/include/nlohmann/detail/input/binary_reader.hpp
+++ b/include/nlohmann/detail/input/binary_reader.hpp
@@ -1577,8 +1577,8 @@ class binary_reader
                 return get_number(input_format_t::msgpack, result.subtype) and get_binary(input_format_t::msgpack, 16, result);
             }
 
-            default:            // LCOV_EXCL_LINE
-                assert(false);  // LCOV_EXCL_LINE
+            default:           // LCOV_EXCL_LINE
+                return false;  // LCOV_EXCL_LINE
         }
     }
 
diff --git a/include/nlohmann/detail/output/binary_writer.hpp b/include/nlohmann/detail/output/binary_writer.hpp
index f1f901ee..d9688096 100644
--- a/include/nlohmann/detail/output/binary_writer.hpp
+++ b/include/nlohmann/detail/output/binary_writer.hpp
@@ -1092,9 +1092,7 @@ class binary_writer
         }
         write_number(subtype);
 
-        oa->write_characters(
-            reinterpret_cast<const CharType*>(value.data()),
-            value.size());
+        oa->write_characters(reinterpret_cast<const CharType*>(value.data()), value.size());
     }
 
     /*!
diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp
index abec8d3f..f5abd465 100644
--- a/single_include/nlohmann/json.hpp
+++ b/single_include/nlohmann/json.hpp
@@ -7104,8 +7104,8 @@ class binary_reader
                 return get_number(input_format_t::msgpack, result.subtype) and get_binary(input_format_t::msgpack, 16, result);
             }
 
-            default:            // LCOV_EXCL_LINE
-                assert(false);  // LCOV_EXCL_LINE
+            default:           // LCOV_EXCL_LINE
+                return false;  // LCOV_EXCL_LINE
         }
     }
 
@@ -13041,9 +13041,7 @@ class binary_writer
         }
         write_number(subtype);
 
-        oa->write_characters(
-            reinterpret_cast<const CharType*>(value.data()),
-            value.size());
+        oa->write_characters(reinterpret_cast<const CharType*>(value.data()), value.size());
     }
 
     /*!
diff --git a/test/src/unit-json_pointer.cpp b/test/src/unit-json_pointer.cpp
index 2cc9dac6..1e68bc83 100644
--- a/test/src/unit-json_pointer.cpp
+++ b/test/src/unit-json_pointer.cpp
@@ -101,6 +101,9 @@ TEST_CASE("JSON pointers")
             CHECK(j["/foo/1"_json_pointer] == j["foo"][1]);
             CHECK(j.contains(json::json_pointer("/foo/0")));
             CHECK(j.contains(json::json_pointer("/foo/1")));
+            CHECK(not j.contains(json::json_pointer("/foo/3")));
+            CHECK(not j.contains(json::json_pointer("/foo/+")));
+            CHECK(not j.contains(json::json_pointer("/foo/1+2")));
             CHECK(not j.contains(json::json_pointer("/foo/-")));
 
             // checked array access
diff --git a/test/src/unit-regression.cpp b/test/src/unit-regression.cpp
index 1fb372f5..c191628a 100644
--- a/test/src/unit-regression.cpp
+++ b/test/src/unit-regression.cpp
@@ -464,6 +464,11 @@ TEST_CASE("regression tests")
         s2 = o["name"];
 
         CHECK(s2 == "value");
+
+        // improve coverage
+        o["int"] = 1;
+        CHECK_THROWS_AS(s2 = o["int"], json::type_error);
+        CHECK_THROWS_WITH(s2 = o["int"], "[json.exception.type_error.302] type must be string, but is number");
     }
 
     SECTION("issue #146 - character following a surrogate pair is skipped")