📝 cleanup after the last PRs

This commit is contained in:
Niels Lohmann 2017-10-22 09:12:35 +02:00
parent be4fba7baf
commit b0c380b0f8
No known key found for this signature in database
GPG key ID: 7F3CEA63AE251B69
6 changed files with 97 additions and 89 deletions

View file

@ -875,7 +875,12 @@ I deeply appreciate the help of the following people.
- [WebProdPP](https://github.com/WebProdPP) fixed a subtle error in a precondition check. - [WebProdPP](https://github.com/WebProdPP) fixed a subtle error in a precondition check.
- [Alex](https://github.com/leha-bot) noted an error in a code sample. - [Alex](https://github.com/leha-bot) noted an error in a code sample.
- [Tom de Geus](https://github.com/tdegeus) reported some warnings with ICC and helped fixing them. - [Tom de Geus](https://github.com/tdegeus) reported some warnings with ICC and helped fixing them.
- [Perry Kundert](https://github.com/pjkundert) simplified reading from input streams.
- [Sonu Lohani](https://github.com/sonulohani) fixed a small compilation error.
- [Jamie Seward](https://github.com/jseward) fixed all MSVC warnings.
- [Nate Vargas](https://github.com/eld00d) added a Doxygen tag file.
- [pvleuven](https://github.com/pvleuven) helped fixing a warning in ICC.
- [Pavel](https://github.com/crea7or) helped fixing some warnings in MSVC.
Thanks a lot for helping out! Please [let me know](mailto:mail@nlohmann.me) if I forgot someone. Thanks a lot for helping out! Please [let me know](mailto:mail@nlohmann.me) if I forgot someone.

View file

@ -1404,63 +1404,66 @@ consist of all valid char values as positive values (typically unsigned char),
plus an EOF value outside that range, specified by the value of the function plus an EOF value outside that range, specified by the value of the function
std::char_traits<char>::eof(). This value is typically -1, but could be any std::char_traits<char>::eof(). This value is typically -1, but could be any
arbitrary value which is not a valid char value. arbitrary value which is not a valid char value.
@return Typically [0,255] plus std::char_traits<char>::eof().
*/ */
struct input_adapter_protocol struct input_adapter_protocol
{ {
/// get a character [0,255] or std::char_traits<char>::eof().
virtual std::char_traits<char>::int_type get_character() = 0; virtual std::char_traits<char>::int_type get_character() = 0;
virtual void unget_character() = 0; // restore the last non-eof() character to input /// restore the last non-eof() character to input
virtual void unget_character() = 0;
virtual ~input_adapter_protocol() = default; virtual ~input_adapter_protocol() = default;
}; };
/// a type to simplify interfaces /// a type to simplify interfaces
using input_adapter_t = std::shared_ptr<input_adapter_protocol>; using input_adapter_t = std::shared_ptr<input_adapter_protocol>;
/// input adapter for a (caching) istream. Ignores a UFT Byte Order Mark at /*!
/// beginning of input. Does not support changing the underlying std::streambuf Input adapter for a (caching) istream. Ignores a UFT Byte Order Mark at
/// in mid-input. Maintains underlying std::istream and std::streambuf to beginning of input. Does not support changing the underlying std::streambuf
/// support subsequent use of standard std::istream operations to process any in mid-input. Maintains underlying std::istream and std::streambuf to support
/// input characters following those used in parsing the JSON input. Clears the subsequent use of standard std::istream operations to process any input
/// std::istream flags; any input errors (eg. EOF) will be detected by the first characters following those used in parsing the JSON input. Clears the
/// subsequent call for input from the std::istream. std::istream flags; any input errors (e.g., EOF) will be detected by the first
subsequent call for input from the std::istream.
*/
class input_stream_adapter : public input_adapter_protocol class input_stream_adapter : public input_adapter_protocol
{ {
public: public:
~input_stream_adapter() override ~input_stream_adapter() override
{ {
// clear stream flags; we use underlying streambuf I/O, do not maintain ifstream flags // clear stream flags; we use underlying streambuf I/O, do not
// maintain ifstream flags
is.clear(); is.clear();
} }
explicit input_stream_adapter(std::istream& i) explicit input_stream_adapter(std::istream& i)
: is(i) : is(i), sb(*i.rdbuf())
, sb(*i.rdbuf())
{ {
// Ignore Byte Order Mark at start of input // ignore Byte Order Mark at start of input
std::char_traits<char>::int_type c; std::char_traits<char>::int_type c;
if (( c = get_character() ) == 0xEF ) if ((c = get_character()) == 0xEF)
{ {
if (( c = get_character() ) == 0xBB ) if ((c = get_character()) == 0xBB)
{ {
if (( c = get_character() ) == 0xBF ) if ((c = get_character()) == 0xBF)
{ {
return; // Ignore BOM return; // Ignore BOM
} }
else if ( c != std::char_traits<char>::eof() ) else if (c != std::char_traits<char>::eof())
{ {
is.unget(); is.unget();
} }
is.putback( '\xBB' ); is.putback('\xBB');
} }
else if ( c != std::char_traits<char>::eof() ) else if (c != std::char_traits<char>::eof())
{ {
is.unget(); is.unget();
} }
is.putback( '\xEF' ); is.putback('\xEF');
} }
else if ( c != std::char_traits<char>::eof() ) else if (c != std::char_traits<char>::eof())
{ {
is.unget(); // Not BOM. Process as usual. is.unget(); // Not BOM. Process as usual.
} }
} }
@ -1478,13 +1481,13 @@ class input_stream_adapter : public input_adapter_protocol
void unget_character() override void unget_character() override
{ {
sb.sungetc(); // Avoided for performance: is.unget(); sb.sungetc(); // is.unget() avoided for performance
} }
private:
private:
/// the associated input stream /// the associated input stream
std::istream& is; std::istream& is;
std::streambuf &sb; std::streambuf& sb;
}; };
/// input adapter for buffer input /// input adapter for buffer input
@ -2691,7 +2694,7 @@ scan_number_done:
{ {
++chars_read; ++chars_read;
current = ia->get_character(); current = ia->get_character();
if (JSON_LIKELY( current != std::char_traits<char>::eof())) if (JSON_LIKELY(current != std::char_traits<char>::eof()))
{ {
token_string.push_back(std::char_traits<char>::to_char_type(current)); token_string.push_back(std::char_traits<char>::to_char_type(current));
} }
@ -2709,7 +2712,7 @@ scan_number_done:
token_string.pop_back(); token_string.pop_back();
} }
} }
/// add a character to yytext /// add a character to yytext
void add(int c) void add(int c)
{ {
@ -2742,7 +2745,7 @@ scan_number_done:
/// return current string value (implicitly resets the token; useful only once) /// return current string value (implicitly resets the token; useful only once)
std::string move_string() std::string move_string()
{ {
return std::move( yytext ); return std::move(yytext);
} }
///////////////////// /////////////////////

View file

@ -274,7 +274,7 @@ TEST_CASE("modifiers")
// invalid values (no string/val pair) // invalid values (no string/val pair)
CHECK_THROWS_AS(j.push_back({1}), json::type_error&); CHECK_THROWS_AS(j.push_back({1}), json::type_error&);
CHECK_THROWS_WITH(j.push_back({1}), "[json.exception.type_error.308] cannot use push_back() with object"); CHECK_THROWS_WITH(j.push_back({1}), "[json.exception.type_error.308] cannot use push_back() with object");
CHECK_THROWS_AS(j.push_back({1,2}), json::type_error&); CHECK_THROWS_AS(j.push_back({1, 2}), json::type_error&);
CHECK_THROWS_WITH(j.push_back({1, 2}), "[json.exception.type_error.308] cannot use push_back() with object"); CHECK_THROWS_WITH(j.push_back({1, 2}), "[json.exception.type_error.308] cannot use push_back() with object");
CHECK_THROWS_AS(j.push_back({1, 2, 3, 4}), json::type_error&); CHECK_THROWS_AS(j.push_back({1, 2, 3, 4}), json::type_error&);
CHECK_THROWS_WITH(j.push_back({1, 2, 3, 4}), "[json.exception.type_error.308] cannot use push_back() with object"); CHECK_THROWS_WITH(j.push_back({1, 2, 3, 4}), "[json.exception.type_error.308] cannot use push_back() with object");

View file

@ -39,8 +39,8 @@ using nlohmann::json;
#include <iostream> #include <iostream>
#if defined(_MSC_VER) #if defined(_MSC_VER)
#pragma warning (push) #pragma warning (push)
#pragma warning (disable : 4189) // local variable is initialized but not referenced #pragma warning (disable : 4189) // local variable is initialized but not referenced
#endif #endif
TEST_CASE("README", "[hide]") TEST_CASE("README", "[hide]")
@ -305,5 +305,5 @@ TEST_CASE("README", "[hide]")
} }
#if defined(_MSC_VER) #if defined(_MSC_VER)
#pragma warning (pop) #pragma warning (pop)
#endif #endif

View file

@ -66,22 +66,22 @@ TEST_CASE("reference access")
CHECK_NOTHROW(value.get_ref<json::object_t&>()); CHECK_NOTHROW(value.get_ref<json::object_t&>());
CHECK_THROWS_AS(value.get_ref<json::array_t&>(), json::type_error&); CHECK_THROWS_AS(value.get_ref<json::array_t&>(), json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::array_t&>(), CHECK_THROWS_WITH(value.get_ref<json::array_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object"); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object");
CHECK_THROWS_AS(value.get_ref<json::string_t&>(), json::type_error&); CHECK_THROWS_AS(value.get_ref<json::string_t&>(), json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::string_t&>(), CHECK_THROWS_WITH(value.get_ref<json::string_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object"); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object");
CHECK_THROWS_AS(value.get_ref<json::boolean_t&>(), json::type_error&); CHECK_THROWS_AS(value.get_ref<json::boolean_t&>(), json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::boolean_t&>(), CHECK_THROWS_WITH(value.get_ref<json::boolean_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object"); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object");
CHECK_THROWS_AS(value.get_ref<json::number_integer_t&>(), json::type_error&); CHECK_THROWS_AS(value.get_ref<json::number_integer_t&>(), json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::number_integer_t&>(), CHECK_THROWS_WITH(value.get_ref<json::number_integer_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object"); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object");
CHECK_THROWS_AS(value.get_ref<json::number_unsigned_t&>(), json::type_error&); CHECK_THROWS_AS(value.get_ref<json::number_unsigned_t&>(), json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::number_unsigned_t&>(), CHECK_THROWS_WITH(value.get_ref<json::number_unsigned_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object"); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object");
CHECK_THROWS_AS(value.get_ref<json::number_float_t&>(), json::type_error&); CHECK_THROWS_AS(value.get_ref<json::number_float_t&>(), json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::number_float_t&>(), CHECK_THROWS_WITH(value.get_ref<json::number_float_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object"); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object");
} }
SECTION("const reference access to const object_t") SECTION("const reference access to const object_t")
@ -115,23 +115,23 @@ TEST_CASE("reference access")
// check if mismatching references throw correctly // check if mismatching references throw correctly
CHECK_THROWS_AS(value.get_ref<json::object_t&>(), json::type_error&); CHECK_THROWS_AS(value.get_ref<json::object_t&>(), json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::object_t&>(), CHECK_THROWS_WITH(value.get_ref<json::object_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array"); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array");
CHECK_NOTHROW(value.get_ref<json::array_t&>()); CHECK_NOTHROW(value.get_ref<json::array_t&>());
CHECK_THROWS_AS(value.get_ref<json::string_t&>(), json::type_error&); CHECK_THROWS_AS(value.get_ref<json::string_t&>(), json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::string_t&>(), CHECK_THROWS_WITH(value.get_ref<json::string_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array"); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array");
CHECK_THROWS_AS(value.get_ref<json::boolean_t&>(), json::type_error&); CHECK_THROWS_AS(value.get_ref<json::boolean_t&>(), json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::boolean_t&>(), CHECK_THROWS_WITH(value.get_ref<json::boolean_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array"); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array");
CHECK_THROWS_AS(value.get_ref<json::number_integer_t&>(), json::type_error&); CHECK_THROWS_AS(value.get_ref<json::number_integer_t&>(), json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::number_integer_t&>(), CHECK_THROWS_WITH(value.get_ref<json::number_integer_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array"); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array");
CHECK_THROWS_AS(value.get_ref<json::number_unsigned_t&>(), json::type_error&); CHECK_THROWS_AS(value.get_ref<json::number_unsigned_t&>(), json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::number_unsigned_t&>(), CHECK_THROWS_WITH(value.get_ref<json::number_unsigned_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array"); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array");
CHECK_THROWS_AS(value.get_ref<json::number_float_t&>(), json::type_error&); CHECK_THROWS_AS(value.get_ref<json::number_float_t&>(), json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::number_float_t&>(), CHECK_THROWS_WITH(value.get_ref<json::number_float_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array"); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array");
} }
SECTION("reference access to string_t") SECTION("reference access to string_t")
@ -151,23 +151,23 @@ TEST_CASE("reference access")
// check if mismatching references throw correctly // check if mismatching references throw correctly
CHECK_THROWS_AS(value.get_ref<json::object_t&>(), json::type_error&); CHECK_THROWS_AS(value.get_ref<json::object_t&>(), json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::object_t&>(), CHECK_THROWS_WITH(value.get_ref<json::object_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string"); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string");
CHECK_THROWS_AS(value.get_ref<json::array_t&>(), json::type_error&); CHECK_THROWS_AS(value.get_ref<json::array_t&>(), json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::array_t&>(), CHECK_THROWS_WITH(value.get_ref<json::array_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string"); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string");
CHECK_NOTHROW(value.get_ref<json::string_t&>()); CHECK_NOTHROW(value.get_ref<json::string_t&>());
CHECK_THROWS_AS(value.get_ref<json::boolean_t&>(), json::type_error&); CHECK_THROWS_AS(value.get_ref<json::boolean_t&>(), json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::boolean_t&>(), CHECK_THROWS_WITH(value.get_ref<json::boolean_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string"); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string");
CHECK_THROWS_AS(value.get_ref<json::number_integer_t&>(), json::type_error&); CHECK_THROWS_AS(value.get_ref<json::number_integer_t&>(), json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::number_integer_t&>(), CHECK_THROWS_WITH(value.get_ref<json::number_integer_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string"); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string");
CHECK_THROWS_AS(value.get_ref<json::number_unsigned_t&>(), json::type_error&); CHECK_THROWS_AS(value.get_ref<json::number_unsigned_t&>(), json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::number_unsigned_t&>(), CHECK_THROWS_WITH(value.get_ref<json::number_unsigned_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string"); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string");
CHECK_THROWS_AS(value.get_ref<json::number_float_t&>(), json::type_error&); CHECK_THROWS_AS(value.get_ref<json::number_float_t&>(), json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::number_float_t&>(), CHECK_THROWS_WITH(value.get_ref<json::number_float_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string"); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string");
} }
SECTION("reference access to boolean_t") SECTION("reference access to boolean_t")
@ -187,23 +187,23 @@ TEST_CASE("reference access")
// check if mismatching references throw correctly // check if mismatching references throw correctly
CHECK_THROWS_AS(value.get_ref<json::object_t&>(), json::type_error&); CHECK_THROWS_AS(value.get_ref<json::object_t&>(), json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::object_t&>(), CHECK_THROWS_WITH(value.get_ref<json::object_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean"); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean");
CHECK_THROWS_AS(value.get_ref<json::array_t&>(), json::type_error&); CHECK_THROWS_AS(value.get_ref<json::array_t&>(), json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::array_t&>(), CHECK_THROWS_WITH(value.get_ref<json::array_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean"); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean");
CHECK_THROWS_AS(value.get_ref<json::string_t&>(), json::type_error&); CHECK_THROWS_AS(value.get_ref<json::string_t&>(), json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::string_t&>(), CHECK_THROWS_WITH(value.get_ref<json::string_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean"); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean");
CHECK_NOTHROW(value.get_ref<json::boolean_t&>()); CHECK_NOTHROW(value.get_ref<json::boolean_t&>());
CHECK_THROWS_AS(value.get_ref<json::number_integer_t&>(), json::type_error&); CHECK_THROWS_AS(value.get_ref<json::number_integer_t&>(), json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::number_integer_t&>(), CHECK_THROWS_WITH(value.get_ref<json::number_integer_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean"); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean");
CHECK_THROWS_AS(value.get_ref<json::number_unsigned_t&>(), json::type_error&); CHECK_THROWS_AS(value.get_ref<json::number_unsigned_t&>(), json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::number_unsigned_t&>(), CHECK_THROWS_WITH(value.get_ref<json::number_unsigned_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean"); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean");
CHECK_THROWS_AS(value.get_ref<json::number_float_t&>(), json::type_error&); CHECK_THROWS_AS(value.get_ref<json::number_float_t&>(), json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::number_float_t&>(), CHECK_THROWS_WITH(value.get_ref<json::number_float_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean"); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean");
} }
SECTION("reference access to number_integer_t") SECTION("reference access to number_integer_t")
@ -223,23 +223,23 @@ TEST_CASE("reference access")
// check if mismatching references throw correctly // check if mismatching references throw correctly
CHECK_THROWS_AS(value.get_ref<json::object_t&>(), json::type_error&); CHECK_THROWS_AS(value.get_ref<json::object_t&>(), json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::object_t&>(), CHECK_THROWS_WITH(value.get_ref<json::object_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number");
CHECK_THROWS_AS(value.get_ref<json::array_t&>(), json::type_error&); CHECK_THROWS_AS(value.get_ref<json::array_t&>(), json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::array_t&>(), CHECK_THROWS_WITH(value.get_ref<json::array_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number");
CHECK_THROWS_AS(value.get_ref<json::string_t&>(), json::type_error&); CHECK_THROWS_AS(value.get_ref<json::string_t&>(), json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::string_t&>(), CHECK_THROWS_WITH(value.get_ref<json::string_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number");
CHECK_THROWS_AS(value.get_ref<json::boolean_t&>(), json::type_error&); CHECK_THROWS_AS(value.get_ref<json::boolean_t&>(), json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::boolean_t&>(), CHECK_THROWS_WITH(value.get_ref<json::boolean_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number");
CHECK_NOTHROW(value.get_ref<json::number_integer_t&>()); CHECK_NOTHROW(value.get_ref<json::number_integer_t&>());
CHECK_THROWS_AS(value.get_ref<json::number_unsigned_t&>(), json::type_error&); CHECK_THROWS_AS(value.get_ref<json::number_unsigned_t&>(), json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::number_unsigned_t&>(), CHECK_THROWS_WITH(value.get_ref<json::number_unsigned_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number");
CHECK_THROWS_AS(value.get_ref<json::number_float_t&>(), json::type_error&); CHECK_THROWS_AS(value.get_ref<json::number_float_t&>(), json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::number_float_t&>(), CHECK_THROWS_WITH(value.get_ref<json::number_float_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number");
} }
SECTION("reference access to number_unsigned_t") SECTION("reference access to number_unsigned_t")
@ -259,23 +259,23 @@ TEST_CASE("reference access")
// check if mismatching references throw correctly // check if mismatching references throw correctly
CHECK_THROWS_AS(value.get_ref<json::object_t&>(), json::type_error&); CHECK_THROWS_AS(value.get_ref<json::object_t&>(), json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::object_t&>(), CHECK_THROWS_WITH(value.get_ref<json::object_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number");
CHECK_THROWS_AS(value.get_ref<json::array_t&>(), json::type_error&); CHECK_THROWS_AS(value.get_ref<json::array_t&>(), json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::array_t&>(), CHECK_THROWS_WITH(value.get_ref<json::array_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number");
CHECK_THROWS_AS(value.get_ref<json::string_t&>(), json::type_error&); CHECK_THROWS_AS(value.get_ref<json::string_t&>(), json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::string_t&>(), CHECK_THROWS_WITH(value.get_ref<json::string_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number");
CHECK_THROWS_AS(value.get_ref<json::boolean_t&>(), json::type_error&); CHECK_THROWS_AS(value.get_ref<json::boolean_t&>(), json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::boolean_t&>(), CHECK_THROWS_WITH(value.get_ref<json::boolean_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number");
//CHECK_THROWS_AS(value.get_ref<json::number_integer_t&>(), json::type_error&); //CHECK_THROWS_AS(value.get_ref<json::number_integer_t&>(), json::type_error&);
//CHECK_THROWS_WITH(value.get_ref<json::number_integer_t&>(), //CHECK_THROWS_WITH(value.get_ref<json::number_integer_t&>(),
// "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"); // "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number");
CHECK_NOTHROW(value.get_ref<json::number_unsigned_t&>()); CHECK_NOTHROW(value.get_ref<json::number_unsigned_t&>());
CHECK_THROWS_AS(value.get_ref<json::number_float_t&>(), json::type_error&); CHECK_THROWS_AS(value.get_ref<json::number_float_t&>(), json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::number_float_t&>(), CHECK_THROWS_WITH(value.get_ref<json::number_float_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number");
} }
SECTION("reference access to number_float_t") SECTION("reference access to number_float_t")
@ -295,22 +295,22 @@ TEST_CASE("reference access")
// check if mismatching references throw correctly // check if mismatching references throw correctly
CHECK_THROWS_AS(value.get_ref<json::object_t&>(), json::type_error&); CHECK_THROWS_AS(value.get_ref<json::object_t&>(), json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::object_t&>(), CHECK_THROWS_WITH(value.get_ref<json::object_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number");
CHECK_THROWS_AS(value.get_ref<json::array_t&>(), json::type_error&); CHECK_THROWS_AS(value.get_ref<json::array_t&>(), json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::array_t&>(), CHECK_THROWS_WITH(value.get_ref<json::array_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number");
CHECK_THROWS_AS(value.get_ref<json::string_t&>(), json::type_error&); CHECK_THROWS_AS(value.get_ref<json::string_t&>(), json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::string_t&>(), CHECK_THROWS_WITH(value.get_ref<json::string_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number");
CHECK_THROWS_AS(value.get_ref<json::boolean_t&>(), json::type_error&); CHECK_THROWS_AS(value.get_ref<json::boolean_t&>(), json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::boolean_t&>(), CHECK_THROWS_WITH(value.get_ref<json::boolean_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number");
CHECK_THROWS_AS(value.get_ref<json::number_integer_t&>(), json::type_error&); CHECK_THROWS_AS(value.get_ref<json::number_integer_t&>(), json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::number_integer_t&>(), CHECK_THROWS_WITH(value.get_ref<json::number_integer_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number");
CHECK_THROWS_AS(value.get_ref<json::number_unsigned_t&>(), json::type_error&); CHECK_THROWS_AS(value.get_ref<json::number_unsigned_t&>(), json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::number_unsigned_t&>(), CHECK_THROWS_WITH(value.get_ref<json::number_unsigned_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number");
CHECK_NOTHROW(value.get_ref<json::number_float_t&>()); CHECK_NOTHROW(value.get_ref<json::number_float_t&>());
} }
} }

View file

@ -1236,21 +1236,21 @@ TEST_CASE("regression tests")
SECTION("issue #367 - Behavior of operator>> should more closely resemble that of built-in overloads.") SECTION("issue #367 - Behavior of operator>> should more closely resemble that of built-in overloads.")
{ {
SECTION("example 1") SECTION("example 1")
{ {
std::istringstream i1_2_3( "{\"first\": \"one\" }{\"second\": \"two\"}3" ); std::istringstream i1_2_3( "{\"first\": \"one\" }{\"second\": \"two\"}3" );
json j1, j2, j3; json j1, j2, j3;
i1_2_3 >> j1; i1_2_3 >> j1;
i1_2_3 >> j2; i1_2_3 >> j2;
i1_2_3 >> j3; i1_2_3 >> j3;
std::map<std::string,std::string> m1 = j1; std::map<std::string, std::string> m1 = j1;
std::map<std::string,std::string> m2 = j2; std::map<std::string, std::string> m2 = j2;
int i3 = j3; int i3 = j3;
CHECK( m1 == ( std::map<std::string,std::string> {{ "first", "one" }} )); CHECK( m1 == ( std::map<std::string, std::string> {{ "first", "one" }} ));
CHECK( m2 == ( std::map<std::string,std::string> {{ "second", "two" }} )); CHECK( m2 == ( std::map<std::string, std::string> {{ "second", "two" }} ));
CHECK( i3 == 3 ); CHECK( i3 == 3 );
} }
} }
} }