This commit is contained in:
efp 2018-10-06 14:48:05 +00:00 committed by GitHub
commit 8943c965cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 259 additions and 175 deletions

View File

@ -12,6 +12,22 @@ namespace detail
// exceptions // // exceptions //
//////////////// ////////////////
//! struct for positions
struct input_position {
std::size_t chars_read ;
std::size_t lines_read ;
std::size_t chars_read_this_line ;
input_position(size_t chars, size_t lines, size_t chars_this_line) :
chars_read(chars),
lines_read(lines),
chars_read_this_line(chars_this_line)
{}
//! Converts to chars_read
operator size_t() {return chars_read; }
} ;
/*! /*!
@brief general exception of the @ref basic_json class @brief general exception of the @ref basic_json class
@ -119,12 +135,21 @@ class parse_error : public exception
@param[in] what_arg the explanatory string @param[in] what_arg the explanatory string
@return parse_error object @return parse_error object
*/ */
static parse_error create(int id_, std::size_t byte_, const std::string& what_arg) static parse_error create(int id_, const input_position pos_, const std::string& what_arg)
{ {
std::string w = exception::name("parse_error", id_) + "parse error" + std::string w = exception::name("parse_error", id_) + "parse error" +
(byte_ != 0 ? (" at " + std::to_string(byte_)) : "") + " at line " + std::to_string(pos_.lines_read + 1) +
" col " + std::to_string(pos_.chars_read_this_line) +
": " + what_arg; ": " + what_arg;
return parse_error(id_, byte_, w.c_str()); return parse_error(id_, pos_, w.c_str());
}
static parse_error create(int id_, size_t bytes_, const std::string& what_arg)
{
std::string w = exception::name("parse_error", id_) + "parse error" +
" at " + std::to_string(bytes_) +
": " + what_arg;
return parse_error(id_, bytes_, w.c_str());
} }
/*! /*!
@ -136,11 +161,18 @@ class parse_error : public exception
n+1 is the index of the terminating null byte or the end of file. n+1 is the index of the terminating null byte or the end of file.
This also holds true when reading a byte vector (CBOR or MessagePack). This also holds true when reading a byte vector (CBOR or MessagePack).
*/ */
const std::size_t byte; input_position position ;
private: private:
parse_error(int id_, std::size_t byte_, const char* what_arg) parse_error(int id_, const input_position& pos_, const char* what_arg)
: exception(id_, what_arg), byte(byte_) {} : exception(id_, what_arg),
position( pos_ )
{}
parse_error(int id_, const size_t bytes_, const char* what_arg)
: exception(id_, what_arg),
position( bytes_, 0, 0)
{}
}; };
/*! /*!

View File

@ -92,13 +92,11 @@ class lexer
return "end of input"; return "end of input";
case token_type::literal_or_value: case token_type::literal_or_value:
return "'[', '{', or a literal"; return "'[', '{', or a literal";
// LCOV_EXCL_START
default: // catch non-enum values default: // catch non-enum values
return "unknown token"; return "unknown token"; // LCOV_EXCL_LINE
// LCOV_EXCL_STOP
} }
} }
explicit lexer(detail::input_adapter_t&& adapter) explicit lexer(detail::input_adapter_t&& adapter)
: ia(std::move(adapter)), decimal_point_char(get_decimal_point()) {} : ia(std::move(adapter)), decimal_point_char(get_decimal_point()) {}
@ -747,13 +745,11 @@ class lexer
goto scan_number_any1; goto scan_number_any1;
} }
// LCOV_EXCL_START
default: default:
{ {
// all other characters are rejected outside scan_number() // all other characters are rejected outside scan_number()
assert(false); assert(false); // LCOV_EXCL_LINE
} }
// LCOV_EXCL_STOP
} }
scan_number_minus: scan_number_minus:
@ -1082,7 +1078,8 @@ scan_number_done:
*/ */
std::char_traits<char>::int_type get() std::char_traits<char>::int_type get()
{ {
++chars_read; ++position.chars_read;
++position.chars_read_this_line;
if (next_unget) if (next_unget)
{ {
// just reset the next_unget variable and work with current // just reset the next_unget variable and work with current
@ -1097,6 +1094,13 @@ scan_number_done:
{ {
token_string.push_back(std::char_traits<char>::to_char_type(current)); token_string.push_back(std::char_traits<char>::to_char_type(current));
} }
if ( current == '\n' )
{
++position.lines_read ;
position.chars_read_this_line = 0 ;
}
return current; return current;
} }
@ -1111,12 +1115,18 @@ scan_number_done:
void unget() void unget()
{ {
next_unget = true; next_unget = true;
--chars_read; --position.chars_read;
--position.chars_read_this_line;
if (JSON_LIKELY(current != std::char_traits<char>::eof())) if (JSON_LIKELY(current != std::char_traits<char>::eof()))
{ {
assert(token_string.size() != 0); assert(token_string.size() != 0);
token_string.pop_back(); token_string.pop_back();
} }
if ( (position.lines_read != 0 ) && (position.chars_read_this_line == 0) )
{
// chars_read_this_line will be invalid, but reset the next get()
--position.lines_read ;
}
} }
/// add a character to token_buffer /// add a character to token_buffer
@ -1159,9 +1169,9 @@ scan_number_done:
///////////////////// /////////////////////
/// return position of last read token /// return position of last read token
constexpr std::size_t get_position() const noexcept constexpr input_position get_position() const noexcept
{ {
return chars_read; return position ;
} }
/// return the last read token (for errors only). Will never contain EOF /// return the last read token (for errors only). Will never contain EOF
@ -1177,7 +1187,7 @@ scan_number_done:
{ {
// escape control characters // escape control characters
char cs[9]; char cs[9];
snprintf(cs, 9, "<U+%.4X>", static_cast<unsigned char>(c)); snprintf(cs, 9, "<U+%.4hhX>", static_cast<unsigned char>(c));
result += cs; result += cs;
} }
else else
@ -1231,7 +1241,7 @@ scan_number_done:
token_type scan() token_type scan()
{ {
// initially, skip the BOM // initially, skip the BOM
if (chars_read == 0 and not skip_bom()) if (position.chars_read == 0 and not skip_bom())
{ {
error_message = "invalid BOM; must be 0xEF 0xBB 0xBF if given"; error_message = "invalid BOM; must be 0xEF 0xBB 0xBF if given";
return token_type::parse_error; return token_type::parse_error;
@ -1309,9 +1319,9 @@ scan_number_done:
/// whether the next get() call should just return current /// whether the next get() call should just return current
bool next_unget = false; bool next_unget = false;
/// the number of characters read /// the current location in the input (defined in exceptions.hpp)
std::size_t chars_read = 0; input_position position {0,0,0} ;
/// raw input token string (for error messages) /// raw input token string (for error messages)
std::vector<char> token_string {}; std::vector<char> token_string {};

View File

@ -625,6 +625,22 @@ namespace detail
// exceptions // // exceptions //
//////////////// ////////////////
//! struct for positions
struct input_position {
std::size_t chars_read ;
std::size_t lines_read ;
std::size_t chars_read_this_line ;
input_position(size_t chars, size_t lines, size_t chars_this_line) :
chars_read(chars),
lines_read(lines),
chars_read_this_line(chars_this_line)
{}
//! Converts to chars_read
operator size_t() {return chars_read; }
} ;
/*! /*!
@brief general exception of the @ref basic_json class @brief general exception of the @ref basic_json class
@ -732,12 +748,21 @@ class parse_error : public exception
@param[in] what_arg the explanatory string @param[in] what_arg the explanatory string
@return parse_error object @return parse_error object
*/ */
static parse_error create(int id_, std::size_t byte_, const std::string& what_arg) static parse_error create(int id_, const input_position pos_, const std::string& what_arg)
{ {
std::string w = exception::name("parse_error", id_) + "parse error" + std::string w = exception::name("parse_error", id_) + "parse error" +
(byte_ != 0 ? (" at " + std::to_string(byte_)) : "") + " at line " + std::to_string(pos_.lines_read + 1) +
" col " + std::to_string(pos_.chars_read_this_line) +
": " + what_arg; ": " + what_arg;
return parse_error(id_, byte_, w.c_str()); return parse_error(id_, pos_, w.c_str());
}
static parse_error create(int id_, size_t bytes_, const std::string& what_arg)
{
std::string w = exception::name("parse_error", id_) + "parse error" +
" at " + std::to_string(bytes_) +
": " + what_arg;
return parse_error(id_, bytes_, w.c_str());
} }
/*! /*!
@ -749,11 +774,18 @@ class parse_error : public exception
n+1 is the index of the terminating null byte or the end of file. n+1 is the index of the terminating null byte or the end of file.
This also holds true when reading a byte vector (CBOR or MessagePack). This also holds true when reading a byte vector (CBOR or MessagePack).
*/ */
const std::size_t byte; input_position position ;
private: private:
parse_error(int id_, std::size_t byte_, const char* what_arg) parse_error(int id_, const input_position& pos_, const char* what_arg)
: exception(id_, what_arg), byte(byte_) {} : exception(id_, what_arg),
position( pos_ )
{}
parse_error(int id_, const size_t bytes_, const char* what_arg)
: exception(id_, what_arg),
position( bytes_, 0, 0)
{}
}; };
/*! /*!
@ -2359,13 +2391,11 @@ class lexer
return "end of input"; return "end of input";
case token_type::literal_or_value: case token_type::literal_or_value:
return "'[', '{', or a literal"; return "'[', '{', or a literal";
// LCOV_EXCL_START
default: // catch non-enum values default: // catch non-enum values
return "unknown token"; return "unknown token"; // LCOV_EXCL_LINE
// LCOV_EXCL_STOP
} }
} }
explicit lexer(detail::input_adapter_t&& adapter) explicit lexer(detail::input_adapter_t&& adapter)
: ia(std::move(adapter)), decimal_point_char(get_decimal_point()) {} : ia(std::move(adapter)), decimal_point_char(get_decimal_point()) {}
@ -3014,13 +3044,11 @@ class lexer
goto scan_number_any1; goto scan_number_any1;
} }
// LCOV_EXCL_START
default: default:
{ {
// all other characters are rejected outside scan_number() // all other characters are rejected outside scan_number()
assert(false); assert(false); // LCOV_EXCL_LINE
} }
// LCOV_EXCL_STOP
} }
scan_number_minus: scan_number_minus:
@ -3349,7 +3377,8 @@ scan_number_done:
*/ */
std::char_traits<char>::int_type get() std::char_traits<char>::int_type get()
{ {
++chars_read; ++position.chars_read;
++position.chars_read_this_line;
if (next_unget) if (next_unget)
{ {
// just reset the next_unget variable and work with current // just reset the next_unget variable and work with current
@ -3364,6 +3393,13 @@ scan_number_done:
{ {
token_string.push_back(std::char_traits<char>::to_char_type(current)); token_string.push_back(std::char_traits<char>::to_char_type(current));
} }
if ( current == '\n' )
{
++position.lines_read ;
position.chars_read_this_line = 0 ;
}
return current; return current;
} }
@ -3378,12 +3414,18 @@ scan_number_done:
void unget() void unget()
{ {
next_unget = true; next_unget = true;
--chars_read; --position.chars_read;
--position.chars_read_this_line;
if (JSON_LIKELY(current != std::char_traits<char>::eof())) if (JSON_LIKELY(current != std::char_traits<char>::eof()))
{ {
assert(token_string.size() != 0); assert(token_string.size() != 0);
token_string.pop_back(); token_string.pop_back();
} }
if ( (position.lines_read != 0 ) && (position.chars_read_this_line == 0) )
{
// chars_read_this_line will be invalid, but reset the next get()
--position.lines_read ;
}
} }
/// add a character to token_buffer /// add a character to token_buffer
@ -3426,9 +3468,9 @@ scan_number_done:
///////////////////// /////////////////////
/// return position of last read token /// return position of last read token
constexpr std::size_t get_position() const noexcept constexpr input_position get_position() const noexcept
{ {
return chars_read; return position ;
} }
/// return the last read token (for errors only). Will never contain EOF /// return the last read token (for errors only). Will never contain EOF
@ -3444,7 +3486,7 @@ scan_number_done:
{ {
// escape control characters // escape control characters
char cs[9]; char cs[9];
snprintf(cs, 9, "<U+%.4X>", static_cast<unsigned char>(c)); snprintf(cs, 9, "<U+%.4hhX>", static_cast<unsigned char>(c));
result += cs; result += cs;
} }
else else
@ -3498,7 +3540,7 @@ scan_number_done:
token_type scan() token_type scan()
{ {
// initially, skip the BOM // initially, skip the BOM
if (chars_read == 0 and not skip_bom()) if (position.chars_read == 0 and not skip_bom())
{ {
error_message = "invalid BOM; must be 0xEF 0xBB 0xBF if given"; error_message = "invalid BOM; must be 0xEF 0xBB 0xBF if given";
return token_type::parse_error; return token_type::parse_error;
@ -3576,9 +3618,9 @@ scan_number_done:
/// whether the next get() call should just return current /// whether the next get() call should just return current
bool next_unget = false; bool next_unget = false;
/// the number of characters read /// the current location in the input (defined in exceptions.hpp)
std::size_t chars_read = 0; input_position position {0,0,0} ;
/// raw input token string (for error messages) /// raw input token string (for error messages)
std::vector<char> token_string {}; std::vector<char> token_string {};
@ -3641,119 +3683,119 @@ using number_integer_function_t =
template <typename T, typename Unsigned> template <typename T, typename Unsigned>
using number_unsigned_function_t = using number_unsigned_function_t =
decltype(std::declval<T&>().number_unsigned(std::declval<Unsigned>())); decltype(std::declval<T &>().number_unsigned(std::declval<Unsigned>()));
template <typename T, typename Float, typename String> template <typename T, typename Float, typename String>
using number_float_function_t = decltype(std::declval<T&>().number_float( using number_float_function_t = decltype(std::declval<T &>().number_float(
std::declval<Float>(), std::declval<const String&>())); std::declval<Float>(), std::declval<const String &>()));
template <typename T, typename String> template <typename T, typename String>
using string_function_t = using string_function_t =
decltype(std::declval<T&>().string(std::declval<String&>())); decltype(std::declval<T &>().string(std::declval<String &>()));
template <typename T> template <typename T>
using start_object_function_t = using start_object_function_t =
decltype(std::declval<T&>().start_object(std::declval<std::size_t>())); decltype(std::declval<T &>().start_object(std::declval<std::size_t>()));
template <typename T, typename String> template <typename T, typename String>
using key_function_t = using key_function_t =
decltype(std::declval<T&>().key(std::declval<String&>())); decltype(std::declval<T &>().key(std::declval<String &>()));
template <typename T> template <typename T>
using end_object_function_t = decltype(std::declval<T&>().end_object()); using end_object_function_t = decltype(std::declval<T &>().end_object());
template <typename T> template <typename T>
using start_array_function_t = using start_array_function_t =
decltype(std::declval<T&>().start_array(std::declval<std::size_t>())); decltype(std::declval<T &>().start_array(std::declval<std::size_t>()));
template <typename T> template <typename T>
using end_array_function_t = decltype(std::declval<T&>().end_array()); using end_array_function_t = decltype(std::declval<T &>().end_array());
template <typename T, typename Exception> template <typename T, typename Exception>
using parse_error_function_t = decltype(std::declval<T&>().parse_error( using parse_error_function_t = decltype(std::declval<T &>().parse_error(
std::declval<std::size_t>(), std::declval<const std::string&>(), std::declval<std::size_t>(), std::declval<const std::string &>(),
std::declval<const Exception&>())); std::declval<const Exception &>()));
template <typename SAX, typename BasicJsonType> template <typename SAX, typename BasicJsonType>
struct is_sax struct is_sax
{ {
private: private:
static_assert(is_basic_json<BasicJsonType>::value, static_assert(is_basic_json<BasicJsonType>::value,
"BasicJsonType must be of type basic_json<...>"); "BasicJsonType must be of type basic_json<...>");
using number_integer_t = typename BasicJsonType::number_integer_t; using number_integer_t = typename BasicJsonType::number_integer_t;
using number_unsigned_t = typename BasicJsonType::number_unsigned_t; using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
using number_float_t = typename BasicJsonType::number_float_t; using number_float_t = typename BasicJsonType::number_float_t;
using string_t = typename BasicJsonType::string_t; using string_t = typename BasicJsonType::string_t;
using exception_t = typename BasicJsonType::exception; using exception_t = typename BasicJsonType::exception;
public: public:
static constexpr bool value = static constexpr bool value =
is_detected_exact<bool, null_function_t, SAX>::value && is_detected_exact<bool, null_function_t, SAX>::value &&
is_detected_exact<bool, boolean_function_t, SAX>::value && is_detected_exact<bool, boolean_function_t, SAX>::value &&
is_detected_exact<bool, number_integer_function_t, SAX, is_detected_exact<bool, number_integer_function_t, SAX,
number_integer_t>::value && number_integer_t>::value &&
is_detected_exact<bool, number_unsigned_function_t, SAX, is_detected_exact<bool, number_unsigned_function_t, SAX,
number_unsigned_t>::value && number_unsigned_t>::value &&
is_detected_exact<bool, number_float_function_t, SAX, number_float_t, is_detected_exact<bool, number_float_function_t, SAX, number_float_t,
string_t>::value && string_t>::value &&
is_detected_exact<bool, string_function_t, SAX, string_t>::value && is_detected_exact<bool, string_function_t, SAX, string_t>::value &&
is_detected_exact<bool, start_object_function_t, SAX>::value && is_detected_exact<bool, start_object_function_t, SAX>::value &&
is_detected_exact<bool, key_function_t, SAX, string_t>::value && is_detected_exact<bool, key_function_t, SAX, string_t>::value &&
is_detected_exact<bool, end_object_function_t, SAX>::value && is_detected_exact<bool, end_object_function_t, SAX>::value &&
is_detected_exact<bool, start_array_function_t, SAX>::value && is_detected_exact<bool, start_array_function_t, SAX>::value &&
is_detected_exact<bool, end_array_function_t, SAX>::value && is_detected_exact<bool, end_array_function_t, SAX>::value &&
is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value; is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value;
}; };
template <typename SAX, typename BasicJsonType> template <typename SAX, typename BasicJsonType>
struct is_sax_static_asserts struct is_sax_static_asserts
{ {
private: private:
static_assert(is_basic_json<BasicJsonType>::value, static_assert(is_basic_json<BasicJsonType>::value,
"BasicJsonType must be of type basic_json<...>"); "BasicJsonType must be of type basic_json<...>");
using number_integer_t = typename BasicJsonType::number_integer_t; using number_integer_t = typename BasicJsonType::number_integer_t;
using number_unsigned_t = typename BasicJsonType::number_unsigned_t; using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
using number_float_t = typename BasicJsonType::number_float_t; using number_float_t = typename BasicJsonType::number_float_t;
using string_t = typename BasicJsonType::string_t; using string_t = typename BasicJsonType::string_t;
using exception_t = typename BasicJsonType::exception; using exception_t = typename BasicJsonType::exception;
public: public:
static_assert(is_detected_exact<bool, null_function_t, SAX>::value, static_assert(is_detected_exact<bool, null_function_t, SAX>::value,
"Missing/invalid function: bool null()"); "Missing/invalid function: bool null()");
static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value, static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value,
"Missing/invalid function: bool boolean(bool)"); "Missing/invalid function: bool boolean(bool)");
static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value, static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value,
"Missing/invalid function: bool boolean(bool)"); "Missing/invalid function: bool boolean(bool)");
static_assert( static_assert(
is_detected_exact<bool, number_integer_function_t, SAX, is_detected_exact<bool, number_integer_function_t, SAX,
number_integer_t>::value, number_integer_t>::value,
"Missing/invalid function: bool number_integer(number_integer_t)"); "Missing/invalid function: bool number_integer(number_integer_t)");
static_assert( static_assert(
is_detected_exact<bool, number_unsigned_function_t, SAX, is_detected_exact<bool, number_unsigned_function_t, SAX,
number_unsigned_t>::value, number_unsigned_t>::value,
"Missing/invalid function: bool number_unsigned(number_unsigned_t)"); "Missing/invalid function: bool number_unsigned(number_unsigned_t)");
static_assert(is_detected_exact<bool, number_float_function_t, SAX, static_assert(is_detected_exact<bool, number_float_function_t, SAX,
number_float_t, string_t>::value, number_float_t, string_t>::value,
"Missing/invalid function: bool number_float(number_float_t, const string_t&)"); "Missing/invalid function: bool number_float(number_float_t, const string_t&)");
static_assert( static_assert(
is_detected_exact<bool, string_function_t, SAX, string_t>::value, is_detected_exact<bool, string_function_t, SAX, string_t>::value,
"Missing/invalid function: bool string(string_t&)"); "Missing/invalid function: bool string(string_t&)");
static_assert(is_detected_exact<bool, start_object_function_t, SAX>::value, static_assert(is_detected_exact<bool, start_object_function_t, SAX>::value,
"Missing/invalid function: bool start_object(std::size_t)"); "Missing/invalid function: bool start_object(std::size_t)");
static_assert(is_detected_exact<bool, key_function_t, SAX, string_t>::value, static_assert(is_detected_exact<bool, key_function_t, SAX, string_t>::value,
"Missing/invalid function: bool key(string_t&)"); "Missing/invalid function: bool key(string_t&)");
static_assert(is_detected_exact<bool, end_object_function_t, SAX>::value, static_assert(is_detected_exact<bool, end_object_function_t, SAX>::value,
"Missing/invalid function: bool end_object()"); "Missing/invalid function: bool end_object()");
static_assert(is_detected_exact<bool, start_array_function_t, SAX>::value, static_assert(is_detected_exact<bool, start_array_function_t, SAX>::value,
"Missing/invalid function: bool start_array(std::size_t)"); "Missing/invalid function: bool start_array(std::size_t)");
static_assert(is_detected_exact<bool, end_array_function_t, SAX>::value, static_assert(is_detected_exact<bool, end_array_function_t, SAX>::value,
"Missing/invalid function: bool end_array()"); "Missing/invalid function: bool end_array()");
static_assert( static_assert(
is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value, is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value,
"Missing/invalid function: bool parse_error(std::size_t, const " "Missing/invalid function: bool parse_error(std::size_t, const "
"std::string&, const exception&)"); "std::string&, const exception&)");
}; };
} }
} }

View File

@ -313,18 +313,18 @@ TEST_CASE("parser class")
// error: tab in string // error: tab in string
CHECK_THROWS_AS(parser_helper("\"\t\""), json::parse_error&); CHECK_THROWS_AS(parser_helper("\"\t\""), json::parse_error&);
CHECK_THROWS_WITH(parser_helper("\"\t\""), CHECK_THROWS_WITH(parser_helper("\"\t\""),
"[json.exception.parse_error.101] parse error at 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+0009>'"); "[json.exception.parse_error.101] parse error at line 1 col 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+0009>'");
// error: newline in string // error: newline in string
CHECK_THROWS_AS(parser_helper("\"\n\""), json::parse_error&); CHECK_THROWS_AS(parser_helper("\"\n\""), json::parse_error&);
CHECK_THROWS_AS(parser_helper("\"\r\""), json::parse_error&); CHECK_THROWS_AS(parser_helper("\"\r\""), json::parse_error&);
CHECK_THROWS_WITH(parser_helper("\"\n\""), CHECK_THROWS_WITH(parser_helper("\"\n\""),
"[json.exception.parse_error.101] parse error at 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+000A>'"); "[json.exception.parse_error.101] parse error at line 1 col 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+000A>'");
CHECK_THROWS_WITH(parser_helper("\"\r\""), CHECK_THROWS_WITH(parser_helper("\"\r\""),
"[json.exception.parse_error.101] parse error at 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+000D>'"); "[json.exception.parse_error.101] parse error at line 1 col 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+000D>'");
// error: backspace in string // error: backspace in string
CHECK_THROWS_AS(parser_helper("\"\b\""), json::parse_error&); CHECK_THROWS_AS(parser_helper("\"\b\""), json::parse_error&);
CHECK_THROWS_WITH(parser_helper("\"\b\""), CHECK_THROWS_WITH(parser_helper("\"\b\""),
"[json.exception.parse_error.101] parse error at 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+0008>'"); "[json.exception.parse_error.101] parse error at line 1 col 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+0008>'");
// improve code coverage // improve code coverage
CHECK_THROWS_AS(parser_helper("\uFF01"), json::parse_error&); CHECK_THROWS_AS(parser_helper("\uFF01"), json::parse_error&);
CHECK_THROWS_AS(parser_helper("[-4:1,]"), json::parse_error&); CHECK_THROWS_AS(parser_helper("[-4:1,]"), json::parse_error&);
@ -361,38 +361,38 @@ TEST_CASE("parser class")
CHECK_THROWS_AS(parser_helper("\"\x1d\""), json::parse_error&); CHECK_THROWS_AS(parser_helper("\"\x1d\""), json::parse_error&);
CHECK_THROWS_AS(parser_helper("\"\x1e\""), json::parse_error&); CHECK_THROWS_AS(parser_helper("\"\x1e\""), json::parse_error&);
CHECK_THROWS_AS(parser_helper("\"\x1f\""), json::parse_error&); CHECK_THROWS_AS(parser_helper("\"\x1f\""), json::parse_error&);
CHECK_THROWS_WITH(parser_helper("\"\x00\""), "[json.exception.parse_error.101] parse error at 2: syntax error - invalid string: missing closing quote; last read: '\"'"); CHECK_THROWS_WITH(parser_helper("\"\x00\""), "[json.exception.parse_error.101] parse error at line 1 col 2: syntax error - invalid string: missing closing quote; last read: '\"'");
CHECK_THROWS_WITH(parser_helper("\"\x01\""), "[json.exception.parse_error.101] parse error at 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+0001>'"); CHECK_THROWS_WITH(parser_helper("\"\x01\""), "[json.exception.parse_error.101] parse error at line 1 col 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+0001>'");
CHECK_THROWS_WITH(parser_helper("\"\x02\""), "[json.exception.parse_error.101] parse error at 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+0002>'"); CHECK_THROWS_WITH(parser_helper("\"\x02\""), "[json.exception.parse_error.101] parse error at line 1 col 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+0002>'");
CHECK_THROWS_WITH(parser_helper("\"\x03\""), "[json.exception.parse_error.101] parse error at 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+0003>'"); CHECK_THROWS_WITH(parser_helper("\"\x03\""), "[json.exception.parse_error.101] parse error at line 1 col 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+0003>'");
CHECK_THROWS_WITH(parser_helper("\"\x04\""), "[json.exception.parse_error.101] parse error at 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+0004>'"); CHECK_THROWS_WITH(parser_helper("\"\x04\""), "[json.exception.parse_error.101] parse error at line 1 col 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+0004>'");
CHECK_THROWS_WITH(parser_helper("\"\x05\""), "[json.exception.parse_error.101] parse error at 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+0005>'"); CHECK_THROWS_WITH(parser_helper("\"\x05\""), "[json.exception.parse_error.101] parse error at line 1 col 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+0005>'");
CHECK_THROWS_WITH(parser_helper("\"\x06\""), "[json.exception.parse_error.101] parse error at 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+0006>'"); CHECK_THROWS_WITH(parser_helper("\"\x06\""), "[json.exception.parse_error.101] parse error at line 1 col 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+0006>'");
CHECK_THROWS_WITH(parser_helper("\"\x07\""), "[json.exception.parse_error.101] parse error at 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+0007>'"); CHECK_THROWS_WITH(parser_helper("\"\x07\""), "[json.exception.parse_error.101] parse error at line 1 col 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+0007>'");
CHECK_THROWS_WITH(parser_helper("\"\x08\""), "[json.exception.parse_error.101] parse error at 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+0008>'"); CHECK_THROWS_WITH(parser_helper("\"\x08\""), "[json.exception.parse_error.101] parse error at line 1 col 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+0008>'");
CHECK_THROWS_WITH(parser_helper("\"\x09\""), "[json.exception.parse_error.101] parse error at 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+0009>'"); CHECK_THROWS_WITH(parser_helper("\"\x09\""), "[json.exception.parse_error.101] parse error at line 1 col 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+0009>'");
CHECK_THROWS_WITH(parser_helper("\"\x0a\""), "[json.exception.parse_error.101] parse error at 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+000A>'"); CHECK_THROWS_WITH(parser_helper("\"\x0a\""), "[json.exception.parse_error.101] parse error at line 1 col 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+000A>'");
CHECK_THROWS_WITH(parser_helper("\"\x0b\""), "[json.exception.parse_error.101] parse error at 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+000B>'"); CHECK_THROWS_WITH(parser_helper("\"\x0b\""), "[json.exception.parse_error.101] parse error at line 1 col 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+000B>'");
CHECK_THROWS_WITH(parser_helper("\"\x0c\""), "[json.exception.parse_error.101] parse error at 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+000C>'"); CHECK_THROWS_WITH(parser_helper("\"\x0c\""), "[json.exception.parse_error.101] parse error at line 1 col 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+000C>'");
CHECK_THROWS_WITH(parser_helper("\"\x0d\""), "[json.exception.parse_error.101] parse error at 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+000D>'"); CHECK_THROWS_WITH(parser_helper("\"\x0d\""), "[json.exception.parse_error.101] parse error at line 1 col 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+000D>'");
CHECK_THROWS_WITH(parser_helper("\"\x0e\""), "[json.exception.parse_error.101] parse error at 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+000E>'"); CHECK_THROWS_WITH(parser_helper("\"\x0e\""), "[json.exception.parse_error.101] parse error at line 1 col 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+000E>'");
CHECK_THROWS_WITH(parser_helper("\"\x0f\""), "[json.exception.parse_error.101] parse error at 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+000F>'"); CHECK_THROWS_WITH(parser_helper("\"\x0f\""), "[json.exception.parse_error.101] parse error at line 1 col 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+000F>'");
CHECK_THROWS_WITH(parser_helper("\"\x10\""), "[json.exception.parse_error.101] parse error at 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+0010>'"); CHECK_THROWS_WITH(parser_helper("\"\x10\""), "[json.exception.parse_error.101] parse error at line 1 col 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+0010>'");
CHECK_THROWS_WITH(parser_helper("\"\x11\""), "[json.exception.parse_error.101] parse error at 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+0011>'"); CHECK_THROWS_WITH(parser_helper("\"\x11\""), "[json.exception.parse_error.101] parse error at line 1 col 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+0011>'");
CHECK_THROWS_WITH(parser_helper("\"\x12\""), "[json.exception.parse_error.101] parse error at 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+0012>'"); CHECK_THROWS_WITH(parser_helper("\"\x12\""), "[json.exception.parse_error.101] parse error at line 1 col 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+0012>'");
CHECK_THROWS_WITH(parser_helper("\"\x13\""), "[json.exception.parse_error.101] parse error at 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+0013>'"); CHECK_THROWS_WITH(parser_helper("\"\x13\""), "[json.exception.parse_error.101] parse error at line 1 col 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+0013>'");
CHECK_THROWS_WITH(parser_helper("\"\x14\""), "[json.exception.parse_error.101] parse error at 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+0014>'"); CHECK_THROWS_WITH(parser_helper("\"\x14\""), "[json.exception.parse_error.101] parse error at line 1 col 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+0014>'");
CHECK_THROWS_WITH(parser_helper("\"\x15\""), "[json.exception.parse_error.101] parse error at 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+0015>'"); CHECK_THROWS_WITH(parser_helper("\"\x15\""), "[json.exception.parse_error.101] parse error at line 1 col 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+0015>'");
CHECK_THROWS_WITH(parser_helper("\"\x16\""), "[json.exception.parse_error.101] parse error at 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+0016>'"); CHECK_THROWS_WITH(parser_helper("\"\x16\""), "[json.exception.parse_error.101] parse error at line 1 col 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+0016>'");
CHECK_THROWS_WITH(parser_helper("\"\x17\""), "[json.exception.parse_error.101] parse error at 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+0017>'"); CHECK_THROWS_WITH(parser_helper("\"\x17\""), "[json.exception.parse_error.101] parse error at line 1 col 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+0017>'");
CHECK_THROWS_WITH(parser_helper("\"\x18\""), "[json.exception.parse_error.101] parse error at 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+0018>'"); CHECK_THROWS_WITH(parser_helper("\"\x18\""), "[json.exception.parse_error.101] parse error at 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+0018>'");
CHECK_THROWS_WITH(parser_helper("\"\x19\""), "[json.exception.parse_error.101] parse error at 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+0019>'"); CHECK_THROWS_WITH(parser_helper("\"\x19\""), "[json.exception.parse_error.101] parse error at line 1 col 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+0019>'");
CHECK_THROWS_WITH(parser_helper("\"\x1a\""), "[json.exception.parse_error.101] parse error at 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+001A>'"); CHECK_THROWS_WITH(parser_helper("\"\x1a\""), "[json.exception.parse_error.101] parse error at line 1 col 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+001A>'");
CHECK_THROWS_WITH(parser_helper("\"\x1b\""), "[json.exception.parse_error.101] parse error at 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+001B>'"); CHECK_THROWS_WITH(parser_helper("\"\x1b\""), "[json.exception.parse_error.101] parse error at line 1 col 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+001B>'");
CHECK_THROWS_WITH(parser_helper("\"\x1c\""), "[json.exception.parse_error.101] parse error at 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+001C>'"); CHECK_THROWS_WITH(parser_helper("\"\x1c\""), "[json.exception.parse_error.101] parse error at line 1 col 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+001C>'");
CHECK_THROWS_WITH(parser_helper("\"\x1d\""), "[json.exception.parse_error.101] parse error at 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+001D>'"); CHECK_THROWS_WITH(parser_helper("\"\x1d\""), "[json.exception.parse_error.101] parse error at line 1 col 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+001D>'");
CHECK_THROWS_WITH(parser_helper("\"\x1e\""), "[json.exception.parse_error.101] parse error at 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+001E>'"); CHECK_THROWS_WITH(parser_helper("\"\x1e\""), "[json.exception.parse_error.101] parse error at line 1 col 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+001E>'");
CHECK_THROWS_WITH(parser_helper("\"\x1f\""), "[json.exception.parse_error.101] parse error at 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+001F>'"); CHECK_THROWS_WITH(parser_helper("\"\x1f\""), "[json.exception.parse_error.101] parse error at line 1 col 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+001F>'");
SECTION("additional test for null byte") SECTION("additional test for null byte")
{ {
@ -403,7 +403,7 @@ TEST_CASE("parser class")
std::string s = "\"1\""; std::string s = "\"1\"";
s[1] = '\0'; s[1] = '\0';
CHECK_THROWS_AS(json::parse(s.begin(), s.end()), json::parse_error&); CHECK_THROWS_AS(json::parse(s.begin(), s.end()), json::parse_error&);
CHECK_THROWS_WITH(json::parse(s.begin(), s.end()), "[json.exception.parse_error.101] parse error at 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+0000>'"); CHECK_THROWS_WITH(json::parse(s.begin(), s.end()), "[json.exception.parse_error.101] parse error at line 1 col 2: syntax error - invalid string: control character must be escaped; last read: '\"<U+0000>'");
} }
} }
@ -603,11 +603,11 @@ TEST_CASE("parser class")
CHECK_THROWS_AS(parser_helper("+0"), json::parse_error&); CHECK_THROWS_AS(parser_helper("+0"), json::parse_error&);
CHECK_THROWS_WITH(parser_helper("01"), CHECK_THROWS_WITH(parser_helper("01"),
"[json.exception.parse_error.101] parse error at 2: syntax error - unexpected number literal; expected end of input"); "[json.exception.parse_error.101] parse error at line 1 col 2: syntax error - unexpected number literal; expected end of input");
CHECK_THROWS_WITH(parser_helper("-01"), CHECK_THROWS_WITH(parser_helper("-01"),
"[json.exception.parse_error.101] parse error at 3: syntax error - unexpected number literal; expected end of input"); "[json.exception.parse_error.101] parse error at 3: syntax error - unexpected number literal; expected end of input");
CHECK_THROWS_WITH(parser_helper("--1"), CHECK_THROWS_WITH(parser_helper("--1"),
"[json.exception.parse_error.101] parse error at 2: syntax error - invalid number; expected digit after '-'; last read: '--'"); "[json.exception.parse_error.101] parse error at line 1 col 2: syntax error - invalid number; expected digit after '-'; last read: '--'");
CHECK_THROWS_WITH(parser_helper("1."), CHECK_THROWS_WITH(parser_helper("1."),
"[json.exception.parse_error.101] parse error at 3: syntax error - invalid number; expected digit after '.'; last read: '1.'"); "[json.exception.parse_error.101] parse error at 3: syntax error - invalid number; expected digit after '.'; last read: '1.'");
CHECK_THROWS_WITH(parser_helper("1E"), CHECK_THROWS_WITH(parser_helper("1E"),
@ -922,15 +922,15 @@ TEST_CASE("parser class")
CHECK_THROWS_WITH(parser_helper("0."), CHECK_THROWS_WITH(parser_helper("0."),
"[json.exception.parse_error.101] parse error at 3: syntax error - invalid number; expected digit after '.'; last read: '0.'"); "[json.exception.parse_error.101] parse error at 3: syntax error - invalid number; expected digit after '.'; last read: '0.'");
CHECK_THROWS_WITH(parser_helper("-"), CHECK_THROWS_WITH(parser_helper("-"),
"[json.exception.parse_error.101] parse error at 2: syntax error - invalid number; expected digit after '-'; last read: '-'"); "[json.exception.parse_error.101] parse error at line 1 col 2: syntax error - invalid number; expected digit after '-'; last read: '-'");
CHECK_THROWS_WITH(parser_helper("--"), CHECK_THROWS_WITH(parser_helper("--"),
"[json.exception.parse_error.101] parse error at 2: syntax error - invalid number; expected digit after '-'; last read: '--'"); "[json.exception.parse_error.101] parse error at line 1 col 2: syntax error - invalid number; expected digit after '-'; last read: '--'");
CHECK_THROWS_WITH(parser_helper("-0."), CHECK_THROWS_WITH(parser_helper("-0."),
"[json.exception.parse_error.101] parse error at 4: syntax error - invalid number; expected digit after '.'; last read: '-0.'"); "[json.exception.parse_error.101] parse error at 4: syntax error - invalid number; expected digit after '.'; last read: '-0.'");
CHECK_THROWS_WITH(parser_helper("-."), CHECK_THROWS_WITH(parser_helper("-."),
"[json.exception.parse_error.101] parse error at 2: syntax error - invalid number; expected digit after '-'; last read: '-.'"); "[json.exception.parse_error.101] parse error at line 1 col 2: syntax error - invalid number; expected digit after '-'; last read: '-.'");
CHECK_THROWS_WITH(parser_helper("-:"), CHECK_THROWS_WITH(parser_helper("-:"),
"[json.exception.parse_error.101] parse error at 2: syntax error - invalid number; expected digit after '-'; last read: '-:'"); "[json.exception.parse_error.101] parse error at line 1 col 2: syntax error - invalid number; expected digit after '-'; last read: '-:'");
CHECK_THROWS_WITH(parser_helper("0.:"), CHECK_THROWS_WITH(parser_helper("0.:"),
"[json.exception.parse_error.101] parse error at 3: syntax error - invalid number; expected digit after '.'; last read: '0.:'"); "[json.exception.parse_error.101] parse error at 3: syntax error - invalid number; expected digit after '.'; last read: '0.:'");
CHECK_THROWS_WITH(parser_helper("e."), CHECK_THROWS_WITH(parser_helper("e."),
@ -955,7 +955,7 @@ TEST_CASE("parser class")
CHECK_THROWS_AS(parser_helper("nulk"), json::parse_error&); CHECK_THROWS_AS(parser_helper("nulk"), json::parse_error&);
CHECK_THROWS_AS(parser_helper("nulm"), json::parse_error&); CHECK_THROWS_AS(parser_helper("nulm"), json::parse_error&);
CHECK_THROWS_WITH(parser_helper("n"), CHECK_THROWS_WITH(parser_helper("n"),
"[json.exception.parse_error.101] parse error at 2: syntax error - invalid literal; last read: 'n'"); "[json.exception.parse_error.101] parse error at line 1 col 2: syntax error - invalid literal; last read: 'n'");
CHECK_THROWS_WITH(parser_helper("nu"), CHECK_THROWS_WITH(parser_helper("nu"),
"[json.exception.parse_error.101] parse error at 3: syntax error - invalid literal; last read: 'nu'"); "[json.exception.parse_error.101] parse error at 3: syntax error - invalid literal; last read: 'nu'");
CHECK_THROWS_WITH(parser_helper("nul"), CHECK_THROWS_WITH(parser_helper("nul"),
@ -972,7 +972,7 @@ TEST_CASE("parser class")
CHECK_THROWS_AS(parser_helper("trud"), json::parse_error&); CHECK_THROWS_AS(parser_helper("trud"), json::parse_error&);
CHECK_THROWS_AS(parser_helper("truf"), json::parse_error&); CHECK_THROWS_AS(parser_helper("truf"), json::parse_error&);
CHECK_THROWS_WITH(parser_helper("t"), CHECK_THROWS_WITH(parser_helper("t"),
"[json.exception.parse_error.101] parse error at 2: syntax error - invalid literal; last read: 't'"); "[json.exception.parse_error.101] parse error at line 1 col 2: syntax error - invalid literal; last read: 't'");
CHECK_THROWS_WITH(parser_helper("tr"), CHECK_THROWS_WITH(parser_helper("tr"),
"[json.exception.parse_error.101] parse error at 3: syntax error - invalid literal; last read: 'tr'"); "[json.exception.parse_error.101] parse error at 3: syntax error - invalid literal; last read: 'tr'");
CHECK_THROWS_WITH(parser_helper("tru"), CHECK_THROWS_WITH(parser_helper("tru"),
@ -990,7 +990,7 @@ TEST_CASE("parser class")
CHECK_THROWS_AS(parser_helper("falsd"), json::parse_error&); CHECK_THROWS_AS(parser_helper("falsd"), json::parse_error&);
CHECK_THROWS_AS(parser_helper("falsf"), json::parse_error&); CHECK_THROWS_AS(parser_helper("falsf"), json::parse_error&);
CHECK_THROWS_WITH(parser_helper("f"), CHECK_THROWS_WITH(parser_helper("f"),
"[json.exception.parse_error.101] parse error at 2: syntax error - invalid literal; last read: 'f'"); "[json.exception.parse_error.101] parse error at line 1 col 2: syntax error - invalid literal; last read: 'f'");
CHECK_THROWS_WITH(parser_helper("fa"), CHECK_THROWS_WITH(parser_helper("fa"),
"[json.exception.parse_error.101] parse error at 3: syntax error - invalid literal; last read: 'fa'"); "[json.exception.parse_error.101] parse error at 3: syntax error - invalid literal; last read: 'fa'");
CHECK_THROWS_WITH(parser_helper("fal"), CHECK_THROWS_WITH(parser_helper("fal"),
@ -1009,7 +1009,7 @@ TEST_CASE("parser class")
CHECK_THROWS_AS(parser_helper("[1,]"), json::parse_error&); CHECK_THROWS_AS(parser_helper("[1,]"), json::parse_error&);
CHECK_THROWS_AS(parser_helper("]"), json::parse_error&); CHECK_THROWS_AS(parser_helper("]"), json::parse_error&);
CHECK_THROWS_WITH(parser_helper("["), CHECK_THROWS_WITH(parser_helper("["),
"[json.exception.parse_error.101] parse error at 2: syntax error - unexpected end of input; expected '[', '{', or a literal"); "[json.exception.parse_error.101] parse error at line 1 col 2: syntax error - unexpected end of input; expected '[', '{', or a literal");
CHECK_THROWS_WITH(parser_helper("[1"), CHECK_THROWS_WITH(parser_helper("[1"),
"[json.exception.parse_error.101] parse error at 3: syntax error - unexpected end of input; expected ']'"); "[json.exception.parse_error.101] parse error at 3: syntax error - unexpected end of input; expected ']'");
CHECK_THROWS_WITH(parser_helper("[1,"), CHECK_THROWS_WITH(parser_helper("[1,"),
@ -1027,7 +1027,7 @@ TEST_CASE("parser class")
CHECK_THROWS_AS(parser_helper("{\"foo\":1,}"), json::parse_error&); CHECK_THROWS_AS(parser_helper("{\"foo\":1,}"), json::parse_error&);
CHECK_THROWS_AS(parser_helper("}"), json::parse_error&); CHECK_THROWS_AS(parser_helper("}"), json::parse_error&);
CHECK_THROWS_WITH(parser_helper("{"), CHECK_THROWS_WITH(parser_helper("{"),
"[json.exception.parse_error.101] parse error at 2: syntax error - unexpected end of input; expected string literal"); "[json.exception.parse_error.101] parse error at line 1 col 2: syntax error - unexpected end of input; expected string literal");
CHECK_THROWS_WITH(parser_helper("{\"foo\""), CHECK_THROWS_WITH(parser_helper("{\"foo\""),
"[json.exception.parse_error.101] parse error at 7: syntax error - unexpected end of input; expected ':'"); "[json.exception.parse_error.101] parse error at 7: syntax error - unexpected end of input; expected ':'");
CHECK_THROWS_WITH(parser_helper("{\"foo\":"), CHECK_THROWS_WITH(parser_helper("{\"foo\":"),
@ -1051,7 +1051,7 @@ TEST_CASE("parser class")
CHECK_THROWS_AS(parser_helper("\"\\u01"), json::parse_error&); CHECK_THROWS_AS(parser_helper("\"\\u01"), json::parse_error&);
CHECK_THROWS_AS(parser_helper("\"\\u012"), json::parse_error&); CHECK_THROWS_AS(parser_helper("\"\\u012"), json::parse_error&);
CHECK_THROWS_WITH(parser_helper("\""), CHECK_THROWS_WITH(parser_helper("\""),
"[json.exception.parse_error.101] parse error at 2: syntax error - invalid string: missing closing quote; last read: '\"'"); "[json.exception.parse_error.101] parse error at line 1 col 2: syntax error - invalid string: missing closing quote; last read: '\"'");
CHECK_THROWS_WITH(parser_helper("\"\\\""), CHECK_THROWS_WITH(parser_helper("\"\\\""),
"[json.exception.parse_error.101] parse error at 4: syntax error - invalid string: missing closing quote; last read: '\"\\\"'"); "[json.exception.parse_error.101] parse error at 4: syntax error - invalid string: missing closing quote; last read: '\"\\\"'");
CHECK_THROWS_WITH(parser_helper("\"\\u\""), CHECK_THROWS_WITH(parser_helper("\"\\u\""),
@ -1419,11 +1419,11 @@ TEST_CASE("parser class")
// test case to make sure no comma preceeds the first key // test case to make sure no comma preceeds the first key
CHECK_THROWS_AS(parser_helper("{,\"key\": false}"), json::parse_error&); CHECK_THROWS_AS(parser_helper("{,\"key\": false}"), json::parse_error&);
CHECK_THROWS_WITH(parser_helper("{,\"key\": false}"), CHECK_THROWS_WITH(parser_helper("{,\"key\": false}"),
"[json.exception.parse_error.101] parse error at 2: syntax error - unexpected ','; expected string literal"); "[json.exception.parse_error.101] parse error at line 1 col 2: syntax error - unexpected ','; expected string literal");
// test case to make sure an object is properly closed // test case to make sure an object is properly closed
CHECK_THROWS_AS(parser_helper("[{\"key\": false true]"), json::parse_error&); CHECK_THROWS_AS(parser_helper("[{\"key\": false true]"), json::parse_error&);
CHECK_THROWS_WITH(parser_helper("[{\"key\": false true]"), CHECK_THROWS_WITH(parser_helper("[{\"key\": false true]"),
"[json.exception.parse_error.101] parse error at 19: syntax error - unexpected true literal; expected '}'"); "[json.exception.parse_error.101] parse error at line 1 col 19: syntax error - unexpected true literal; expected '}'");
// test case to make sure the callback is properly evaluated after reading a key // test case to make sure the callback is properly evaluated after reading a key
{ {