1
0
mirror of https://github.com/nlohmann/json.git synced 2025-07-09 11:01:47 +03:00

added compliance test cases

This commit is contained in:
Niels
2015-05-09 13:56:51 +02:00
parent 9f9d293bad
commit 869035a6c9
39 changed files with 240 additions and 27 deletions

View File

@ -3669,7 +3669,7 @@ class basic_json
// string
quotation_mark = [\"];
escape = [\\];
unescaped = [^\"\\\000];
unescaped = [^\"\\\000\t\n\r];
single_escaped = [\"\\/bfnrt];
unicode_escaped = [u][0-9a-fA-F]{4};
escaped = escape (single_escaped | unicode_escaped);
@ -3701,7 +3701,7 @@ class basic_json
m_buffer.erase(0, static_cast<size_t>(offset_start));
std::string line;
std::getline(*m_stream, line);
m_buffer += line;
m_buffer += "\n" + line; // add line with newline symbol
m_content = reinterpret_cast<const lexer_char_t*>(m_buffer.c_str());
m_start = m_content;
@ -3947,6 +3947,9 @@ class basic_json
return result;
}
// no comma is expected here
unexpect(lexer::token_type::value_separator);
// otherwise: parse key-value pairs
do
{
@ -4013,6 +4016,9 @@ class basic_json
return result;
}
// no comma is expected here
unexpect(lexer::token_type::value_separator);
// otherwise: parse values
do
{
@ -4102,11 +4108,8 @@ class basic_json
default:
{
std::string error_msg = "parse error - unexpected \'";
error_msg += m_lexer.get_token();
error_msg += "\' (";
error_msg += lexer::token_type_name(last_token) + ")";
throw std::invalid_argument(error_msg);
// the last token was unexpected
unexpect(last_token);
}
}
@ -4136,6 +4139,18 @@ class basic_json
}
}
inline void unexpect(typename lexer::token_type t) const
{
if (t == last_token)
{
std::string error_msg = "parse error - unexpected \'";
error_msg += m_lexer.get_token();
error_msg += "\' (";
error_msg += lexer::token_type_name(last_token) + ")";
throw std::invalid_argument(error_msg);
}
}
private:
/// levels of recursion
int depth = 0;