From ef283e0cf87fca3da2c238e116fd6ef9d1430e2a Mon Sep 17 00:00:00 2001 From: Jonathan Dumaresq Date: Wed, 12 Dec 2018 10:18:37 -0500 Subject: [PATCH] add tests to cover the new input adapter --- .../nlohmann/detail/input/input_adapters.hpp | 16 ++++---- test/src/unit-testsuites.cpp | 40 +++++++++++++++++++ 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/include/nlohmann/detail/input/input_adapters.hpp b/include/nlohmann/detail/input/input_adapters.hpp index f623a230..e0945b3f 100644 --- a/include/nlohmann/detail/input/input_adapters.hpp +++ b/include/nlohmann/detail/input/input_adapters.hpp @@ -52,18 +52,18 @@ Input adapter for stdio file access. This adapter read only 1 byte and do not us */ class file_input_adapter : public input_adapter_protocol { -public: - explicit file_input_adapter(const FILE *file) noexcept - : file(file) + public: + explicit file_input_adapter(const FILE* file) noexcept + : file(file) {} std::char_traits::int_type get_character() noexcept override { - return fgetc(const_cast(file)); + return fgetc(const_cast(file)); } -private: + private: /// the file pointer to read from - const FILE * file; + const FILE* file; }; @@ -309,8 +309,8 @@ class input_adapter { public: // native support - input_adapter(FILE * file) - : ia(std::make_shared(file)) {} + input_adapter(FILE* file) + : ia(std::make_shared(file)) {} /// input adapter for input stream input_adapter(std::istream& i) : ia(std::make_shared(i)) {} diff --git a/test/src/unit-testsuites.cpp b/test/src/unit-testsuites.cpp index 3c00fada..782c3f52 100644 --- a/test/src/unit-testsuites.cpp +++ b/test/src/unit-testsuites.cpp @@ -384,6 +384,46 @@ TEST_CASE("json.org examples") json j; CHECK_NOTHROW(f >> j); } + SECTION("FILE 1.json") + { + auto f = fopen("test/data/json.org/1.json", "r"); + json j; + CHECK_NOTHROW(j.parse(f)); + fclose(f); + } + + SECTION("FILE 2.json") + { + auto f = fopen("test/data/json.org/2.json", "r"); + json j; + CHECK_NOTHROW(j.parse(f)); + fclose(f); + } + + SECTION("FILE 3.json") + { + auto f = fopen("test/data/json.org/3.json", "r"); + json j; + CHECK_NOTHROW(j.parse(f)); + fclose(f); + } + + SECTION("FILE 4.json") + { + auto f = fopen("test/data/json.org/4.json", "r"); + json j; + CHECK_NOTHROW(j.parse(f)); + fclose(f); + } + + SECTION("FILE 5.json") + { + auto f = fopen("test/data/json.org/5.json", "r"); + json j; + CHECK_NOTHROW(j.parse(f)); + fclose(f); + } + } TEST_CASE("RFC 7159 examples")