+ moved lexer to class
This commit is contained in:
parent
e845cd1db8
commit
8a4e127a57
3 changed files with 1010 additions and 1101 deletions
110
test/unit.cpp
110
test/unit.cpp
|
|
@ -3892,27 +3892,43 @@ TEST_CASE("deserialization")
|
|||
{
|
||||
SECTION("string")
|
||||
{
|
||||
auto s = "[\"foo\",1,2,3,false,{\"one\":1}]";
|
||||
// auto s = "[\"foo\",1,2,3,false,{\"one\":1}]";
|
||||
// json j = json::parse(s);
|
||||
// CHECK(j == json({"foo", 1, 2, 3, false, {{"one", 1}}}));
|
||||
|
||||
auto s = "null";
|
||||
json j = json::parse(s);
|
||||
CHECK(j == json({"foo", 1, 2, 3, false, {{"one", 1}}}));
|
||||
CHECK(j == json());
|
||||
}
|
||||
|
||||
SECTION("operator<<")
|
||||
{
|
||||
// std::stringstream ss;
|
||||
// ss << "[\"foo\",1,2,3,false,{\"one\":1}]";
|
||||
// json j;
|
||||
// j << ss;
|
||||
// CHECK(j == json({"foo", 1, 2, 3, false, {{"one", 1}}}));
|
||||
|
||||
std::stringstream ss;
|
||||
ss << "[\"foo\",1,2,3,false,{\"one\":1}]";
|
||||
ss << "null";
|
||||
json j;
|
||||
j << ss;
|
||||
CHECK(j == json({"foo", 1, 2, 3, false, {{"one", 1}}}));
|
||||
CHECK(j == json());
|
||||
}
|
||||
|
||||
SECTION("operator>>")
|
||||
{
|
||||
// std::stringstream ss;
|
||||
// ss << "[\"foo\",1,2,3,false,{\"one\":1}]";
|
||||
// json j;
|
||||
// ss >> j;
|
||||
// CHECK(j == json({"foo", 1, 2, 3, false, {{"one", 1}}}));
|
||||
|
||||
std::stringstream ss;
|
||||
ss << "[\"foo\",1,2,3,false,{\"one\":1}]";
|
||||
ss << "null";
|
||||
json j;
|
||||
ss >> j;
|
||||
CHECK(j == json({"foo", 1, 2, 3, false, {{"one", 1}}}));
|
||||
CHECK(j == json());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -3980,42 +3996,42 @@ TEST_CASE("parser class")
|
|||
{
|
||||
SECTION("structural characters")
|
||||
{
|
||||
CHECK(json::parser("[").last_token == json::parser::token_type::begin_array);
|
||||
CHECK(json::parser("]").last_token == json::parser::token_type::end_array);
|
||||
CHECK(json::parser("{").last_token == json::parser::token_type::begin_object);
|
||||
CHECK(json::parser("}").last_token == json::parser::token_type::end_object);
|
||||
CHECK(json::parser(",").last_token == json::parser::token_type::value_separator);
|
||||
CHECK(json::parser(":").last_token == json::parser::token_type::name_separator);
|
||||
CHECK(json::parser("[").last_token == json::lexer::token_type::begin_array);
|
||||
CHECK(json::parser("]").last_token == json::lexer::token_type::end_array);
|
||||
CHECK(json::parser("{").last_token == json::lexer::token_type::begin_object);
|
||||
CHECK(json::parser("}").last_token == json::lexer::token_type::end_object);
|
||||
CHECK(json::parser(",").last_token == json::lexer::token_type::value_separator);
|
||||
CHECK(json::parser(":").last_token == json::lexer::token_type::name_separator);
|
||||
}
|
||||
|
||||
SECTION("literal names")
|
||||
{
|
||||
CHECK(json::parser("null").last_token == json::parser::token_type::literal_null);
|
||||
CHECK(json::parser("true").last_token == json::parser::token_type::literal_true);
|
||||
CHECK(json::parser("false").last_token == json::parser::token_type::literal_false);
|
||||
CHECK(json::parser("null").last_token == json::lexer::token_type::literal_null);
|
||||
CHECK(json::parser("true").last_token == json::lexer::token_type::literal_true);
|
||||
CHECK(json::parser("false").last_token == json::lexer::token_type::literal_false);
|
||||
}
|
||||
|
||||
SECTION("numbers")
|
||||
{
|
||||
CHECK(json::parser("0").last_token == json::parser::token_type::value_number);
|
||||
CHECK(json::parser("1").last_token == json::parser::token_type::value_number);
|
||||
CHECK(json::parser("2").last_token == json::parser::token_type::value_number);
|
||||
CHECK(json::parser("3").last_token == json::parser::token_type::value_number);
|
||||
CHECK(json::parser("4").last_token == json::parser::token_type::value_number);
|
||||
CHECK(json::parser("5").last_token == json::parser::token_type::value_number);
|
||||
CHECK(json::parser("6").last_token == json::parser::token_type::value_number);
|
||||
CHECK(json::parser("7").last_token == json::parser::token_type::value_number);
|
||||
CHECK(json::parser("8").last_token == json::parser::token_type::value_number);
|
||||
CHECK(json::parser("9").last_token == json::parser::token_type::value_number);
|
||||
CHECK(json::parser("0").last_token == json::lexer::token_type::value_number);
|
||||
CHECK(json::parser("1").last_token == json::lexer::token_type::value_number);
|
||||
CHECK(json::parser("2").last_token == json::lexer::token_type::value_number);
|
||||
CHECK(json::parser("3").last_token == json::lexer::token_type::value_number);
|
||||
CHECK(json::parser("4").last_token == json::lexer::token_type::value_number);
|
||||
CHECK(json::parser("5").last_token == json::lexer::token_type::value_number);
|
||||
CHECK(json::parser("6").last_token == json::lexer::token_type::value_number);
|
||||
CHECK(json::parser("7").last_token == json::lexer::token_type::value_number);
|
||||
CHECK(json::parser("8").last_token == json::lexer::token_type::value_number);
|
||||
CHECK(json::parser("9").last_token == json::lexer::token_type::value_number);
|
||||
}
|
||||
|
||||
SECTION("whitespace")
|
||||
{
|
||||
CHECK(json::parser(" 0").last_token == json::parser::token_type::value_number);
|
||||
CHECK(json::parser("\t0").last_token == json::parser::token_type::value_number);
|
||||
CHECK(json::parser("\n0").last_token == json::parser::token_type::value_number);
|
||||
CHECK(json::parser("\r0").last_token == json::parser::token_type::value_number);
|
||||
CHECK(json::parser(" \t\n\r\n\t 0").last_token == json::parser::token_type::value_number);
|
||||
CHECK(json::parser(" 0").last_token == json::lexer::token_type::value_number);
|
||||
CHECK(json::parser("\t0").last_token == json::lexer::token_type::value_number);
|
||||
CHECK(json::parser("\n0").last_token == json::lexer::token_type::value_number);
|
||||
CHECK(json::parser("\r0").last_token == json::lexer::token_type::value_number);
|
||||
CHECK(json::parser(" \t\n\r\n\t 0").last_token == json::lexer::token_type::value_number);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -4049,7 +4065,7 @@ TEST_CASE("parser class")
|
|||
case ('9'):
|
||||
case ('"'):
|
||||
{
|
||||
CHECK(json::parser(s).last_token != json::parser::token_type::parse_error);
|
||||
CHECK(json::parser(s).last_token != json::lexer::token_type::parse_error);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -4058,13 +4074,13 @@ TEST_CASE("parser class")
|
|||
case ('\n'):
|
||||
case ('\r'):
|
||||
{
|
||||
CHECK(json::parser(s).last_token == json::parser::token_type::end_of_input);
|
||||
CHECK(json::parser(s).last_token == json::lexer::token_type::end_of_input);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
CHECK(json::parser(s).last_token == json::parser::token_type::parse_error);
|
||||
CHECK(json::parser(s).last_token == json::lexer::token_type::parse_error);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -4093,19 +4109,19 @@ TEST_CASE("parser class")
|
|||
|
||||
SECTION("token_type_name")
|
||||
{
|
||||
CHECK(json::parser::token_type_name(json::parser::token_type::uninitialized) == "<uninitialized>");
|
||||
CHECK(json::parser::token_type_name(json::parser::token_type::literal_true) == "true literal");
|
||||
CHECK(json::parser::token_type_name(json::parser::token_type::literal_false) == "false literal");
|
||||
CHECK(json::parser::token_type_name(json::parser::token_type::literal_null) == "null literal");
|
||||
CHECK(json::parser::token_type_name(json::parser::token_type::value_string) == "string literal");
|
||||
CHECK(json::parser::token_type_name(json::parser::token_type::value_number) == "number literal");
|
||||
CHECK(json::parser::token_type_name(json::parser::token_type::begin_array) == "[");
|
||||
CHECK(json::parser::token_type_name(json::parser::token_type::begin_object) == "{");
|
||||
CHECK(json::parser::token_type_name(json::parser::token_type::end_array) == "]");
|
||||
CHECK(json::parser::token_type_name(json::parser::token_type::end_object) == "}");
|
||||
CHECK(json::parser::token_type_name(json::parser::token_type::name_separator) == ":");
|
||||
CHECK(json::parser::token_type_name(json::parser::token_type::value_separator) == ",");
|
||||
CHECK(json::parser::token_type_name(json::parser::token_type::parse_error) == "<parse error>");
|
||||
CHECK(json::parser::token_type_name(json::parser::token_type::end_of_input) == "<end of input>");
|
||||
CHECK(json::parser::token_type_name(json::lexer::token_type::uninitialized) == "<uninitialized>");
|
||||
CHECK(json::parser::token_type_name(json::lexer::token_type::literal_true) == "true literal");
|
||||
CHECK(json::parser::token_type_name(json::lexer::token_type::literal_false) == "false literal");
|
||||
CHECK(json::parser::token_type_name(json::lexer::token_type::literal_null) == "null literal");
|
||||
CHECK(json::parser::token_type_name(json::lexer::token_type::value_string) == "string literal");
|
||||
CHECK(json::parser::token_type_name(json::lexer::token_type::value_number) == "number literal");
|
||||
CHECK(json::parser::token_type_name(json::lexer::token_type::begin_array) == "[");
|
||||
CHECK(json::parser::token_type_name(json::lexer::token_type::begin_object) == "{");
|
||||
CHECK(json::parser::token_type_name(json::lexer::token_type::end_array) == "]");
|
||||
CHECK(json::parser::token_type_name(json::lexer::token_type::end_object) == "}");
|
||||
CHECK(json::parser::token_type_name(json::lexer::token_type::name_separator) == ":");
|
||||
CHECK(json::parser::token_type_name(json::lexer::token_type::value_separator) == ",");
|
||||
CHECK(json::parser::token_type_name(json::lexer::token_type::parse_error) == "<parse error>");
|
||||
CHECK(json::parser::token_type_name(json::lexer::token_type::end_of_input) == "<end of input>");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue