|
|
@ -17,10 +17,10 @@ |
|
|
|
#include "testsuite.h" |
|
|
|
#include "testsuite.h" |
|
|
|
#include "util/json/array.h" |
|
|
|
#include "util/json/array.h" |
|
|
|
#include "util/json/job.h" |
|
|
|
#include "util/json/job.h" |
|
|
|
|
|
|
|
#include "util/json/json.h" |
|
|
|
#include "util/json/lexer.h" |
|
|
|
#include "util/json/lexer.h" |
|
|
|
#include "util/json/parser.h" |
|
|
|
#include "util/json/parser.h" |
|
|
|
#include "util/json/serializer.h" |
|
|
|
#include "util/json/serializer.h" |
|
|
|
#include "util/json/value.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define DONT_PRINT_PARSER_ERRORS |
|
|
|
#define DONT_PRINT_PARSER_ERRORS |
|
|
|
|
|
|
|
|
|
|
@ -33,20 +33,20 @@ |
|
|
|
stderr = Test::TestSuite::the().outputErr(); |
|
|
|
stderr = Test::TestSuite::the().outputErr(); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
std::vector<Json::Token> lex(const std::string& input) |
|
|
|
std::vector<Util::JSON::Token> lex(const std::string& input) |
|
|
|
{ |
|
|
|
{ |
|
|
|
EXEC( |
|
|
|
EXEC( |
|
|
|
Json::Job job(input); |
|
|
|
Util::JSON::Job job(input); |
|
|
|
Json::Lexer lexer(&job); |
|
|
|
Util::JSON::Lexer lexer(&job); |
|
|
|
lexer.analyze();); |
|
|
|
lexer.analyze();); |
|
|
|
return *job.tokens(); |
|
|
|
return *job.tokens(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Json::Value parse(const std::string& input) |
|
|
|
Util::Json parse(const std::string& input) |
|
|
|
{ |
|
|
|
{ |
|
|
|
EXEC( |
|
|
|
EXEC( |
|
|
|
Json::Job job(input); |
|
|
|
Util::JSON::Job job(input); |
|
|
|
Json::Lexer lexer(&job); |
|
|
|
Util::JSON::Lexer lexer(&job); |
|
|
|
lexer.analyze();); |
|
|
|
lexer.analyze();); |
|
|
|
|
|
|
|
|
|
|
|
if (!job.success()) { |
|
|
|
if (!job.success()) { |
|
|
@ -54,8 +54,8 @@ Json::Value parse(const std::string& input) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
EXEC( |
|
|
|
EXEC( |
|
|
|
Json::Parser parser(&job); |
|
|
|
Util::JSON::Parser parser(&job); |
|
|
|
Json::Value json = parser.parse();); |
|
|
|
Util::Json json = parser.parse();); |
|
|
|
|
|
|
|
|
|
|
|
if (!job.success()) { |
|
|
|
if (!job.success()) { |
|
|
|
return nullptr; |
|
|
|
return nullptr; |
|
|
@ -67,7 +67,7 @@ Json::Value parse(const std::string& input) |
|
|
|
std::string serialize(const std::string& input, uint32_t indent = 0) |
|
|
|
std::string serialize(const std::string& input, uint32_t indent = 0) |
|
|
|
{ |
|
|
|
{ |
|
|
|
EXEC( |
|
|
|
EXEC( |
|
|
|
auto json = Json::Value::parse(input);); |
|
|
|
auto json = Util::Json::parse(input);); |
|
|
|
return json.dump(indent); |
|
|
|
return json.dump(indent); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -75,59 +75,59 @@ std::string serialize(const std::string& input, uint32_t indent = 0) |
|
|
|
|
|
|
|
|
|
|
|
TEST_CASE(JsonLexer) |
|
|
|
TEST_CASE(JsonLexer) |
|
|
|
{ |
|
|
|
{ |
|
|
|
std::vector<Json::Token> tokens; |
|
|
|
std::vector<Util::JSON::Token> tokens; |
|
|
|
|
|
|
|
|
|
|
|
// Literal
|
|
|
|
// Literal
|
|
|
|
|
|
|
|
|
|
|
|
tokens = lex("true"); |
|
|
|
tokens = lex("true"); |
|
|
|
EXPECT_EQ(tokens.size(), 1); |
|
|
|
EXPECT_EQ(tokens.size(), 1); |
|
|
|
EXPECT_EQ(tokens[0].symbol, "true"); |
|
|
|
EXPECT_EQ(tokens[0].symbol, "true"); |
|
|
|
EXPECT(tokens[0].type == Json::Token::Type::Literal); |
|
|
|
EXPECT(tokens[0].type == Util::JSON::Token::Type::Literal); |
|
|
|
|
|
|
|
|
|
|
|
tokens = lex("false"); |
|
|
|
tokens = lex("false"); |
|
|
|
EXPECT_EQ(tokens.size(), 1); |
|
|
|
EXPECT_EQ(tokens.size(), 1); |
|
|
|
EXPECT_EQ(tokens[0].symbol, "false"); |
|
|
|
EXPECT_EQ(tokens[0].symbol, "false"); |
|
|
|
EXPECT(tokens[0].type == Json::Token::Type::Literal); |
|
|
|
EXPECT(tokens[0].type == Util::JSON::Token::Type::Literal); |
|
|
|
|
|
|
|
|
|
|
|
tokens = lex("null"); |
|
|
|
tokens = lex("null"); |
|
|
|
EXPECT_EQ(tokens.size(), 1); |
|
|
|
EXPECT_EQ(tokens.size(), 1); |
|
|
|
EXPECT_EQ(tokens[0].symbol, "null"); |
|
|
|
EXPECT_EQ(tokens[0].symbol, "null"); |
|
|
|
EXPECT(tokens[0].type == Json::Token::Type::Literal); |
|
|
|
EXPECT(tokens[0].type == Util::JSON::Token::Type::Literal); |
|
|
|
|
|
|
|
|
|
|
|
// Number
|
|
|
|
// Number
|
|
|
|
|
|
|
|
|
|
|
|
tokens = lex("3.14"); |
|
|
|
tokens = lex("3.14"); |
|
|
|
EXPECT_EQ(tokens.size(), 1); |
|
|
|
EXPECT_EQ(tokens.size(), 1); |
|
|
|
EXPECT_EQ(tokens[0].symbol, "3.14"); |
|
|
|
EXPECT_EQ(tokens[0].symbol, "3.14"); |
|
|
|
EXPECT(tokens[0].type == Json::Token::Type::Number); |
|
|
|
EXPECT(tokens[0].type == Util::JSON::Token::Type::Number); |
|
|
|
|
|
|
|
|
|
|
|
tokens = lex("-3.14e+2"); |
|
|
|
tokens = lex("-3.14e+2"); |
|
|
|
EXPECT_EQ(tokens.size(), 1); |
|
|
|
EXPECT_EQ(tokens.size(), 1); |
|
|
|
EXPECT_EQ(tokens[0].symbol, "-3.14e+2"); |
|
|
|
EXPECT_EQ(tokens[0].symbol, "-3.14e+2"); |
|
|
|
EXPECT(tokens[0].type == Json::Token::Type::Number); |
|
|
|
EXPECT(tokens[0].type == Util::JSON::Token::Type::Number); |
|
|
|
|
|
|
|
|
|
|
|
tokens = lex("+3.14"); |
|
|
|
tokens = lex("+3.14"); |
|
|
|
EXPECT_EQ(tokens.size(), 1); |
|
|
|
EXPECT_EQ(tokens.size(), 1); |
|
|
|
EXPECT_EQ(tokens[0].symbol, "+"); |
|
|
|
EXPECT_EQ(tokens[0].symbol, "+"); |
|
|
|
EXPECT(tokens[0].type == Json::Token::Type::None); |
|
|
|
EXPECT(tokens[0].type == Util::JSON::Token::Type::None); |
|
|
|
|
|
|
|
|
|
|
|
// String
|
|
|
|
// String
|
|
|
|
|
|
|
|
|
|
|
|
tokens = lex(R"("a string")"); |
|
|
|
tokens = lex(R"("a string")"); |
|
|
|
EXPECT_EQ(tokens.size(), 1); |
|
|
|
EXPECT_EQ(tokens.size(), 1); |
|
|
|
EXPECT_EQ(tokens[0].symbol, "a string"); |
|
|
|
EXPECT_EQ(tokens[0].symbol, "a string"); |
|
|
|
EXPECT(tokens[0].type == Json::Token::Type::String); |
|
|
|
EXPECT(tokens[0].type == Util::JSON::Token::Type::String); |
|
|
|
|
|
|
|
|
|
|
|
tokens = lex(R"("a string""another string")"); |
|
|
|
tokens = lex(R"("a string""another string")"); |
|
|
|
EXPECT_EQ(tokens.size(), 2); |
|
|
|
EXPECT_EQ(tokens.size(), 2); |
|
|
|
EXPECT_EQ(tokens[0].symbol, "a string"); |
|
|
|
EXPECT_EQ(tokens[0].symbol, "a string"); |
|
|
|
EXPECT_EQ(tokens[1].symbol, "another string"); |
|
|
|
EXPECT_EQ(tokens[1].symbol, "another string"); |
|
|
|
EXPECT(tokens[0].type == Json::Token::Type::String); |
|
|
|
EXPECT(tokens[0].type == Util::JSON::Token::Type::String); |
|
|
|
|
|
|
|
|
|
|
|
tokens = lex("\"a string\nwill break on the newline symbol\""); |
|
|
|
tokens = lex("\"a string\nwill break on the newline symbol\""); |
|
|
|
EXPECT_EQ(tokens.size(), 1); |
|
|
|
EXPECT_EQ(tokens.size(), 1); |
|
|
|
EXPECT_EQ(tokens[0].symbol, "a string"); |
|
|
|
EXPECT_EQ(tokens[0].symbol, "a string"); |
|
|
|
EXPECT(tokens[0].type == Json::Token::Type::String); |
|
|
|
EXPECT(tokens[0].type == Util::JSON::Token::Type::String); |
|
|
|
|
|
|
|
|
|
|
|
// Array
|
|
|
|
// Array
|
|
|
|
|
|
|
|
|
|
|
@ -156,186 +156,186 @@ TEST_CASE(JsonLexer) |
|
|
|
|
|
|
|
|
|
|
|
TEST_CASE(JsonParser) |
|
|
|
TEST_CASE(JsonParser) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Json::Value json; |
|
|
|
Util::Json json; |
|
|
|
|
|
|
|
|
|
|
|
json = parse("null"); |
|
|
|
json = parse("null"); |
|
|
|
EXPECT_EQ(json.size(), 0); |
|
|
|
EXPECT_EQ(json.size(), 0); |
|
|
|
EXPECT_EQ(json.type(), Json::Value::Type::Null); |
|
|
|
EXPECT_EQ(json.type(), Util::Json::Type::Null); |
|
|
|
|
|
|
|
|
|
|
|
json = parse("true"); |
|
|
|
json = parse("true"); |
|
|
|
EXPECT_EQ(json.size(), 1); |
|
|
|
EXPECT_EQ(json.size(), 1); |
|
|
|
EXPECT_EQ(json.type(), Json::Value::Type::Bool); |
|
|
|
EXPECT_EQ(json.type(), Util::Json::Type::Bool); |
|
|
|
|
|
|
|
|
|
|
|
json = parse("false"); |
|
|
|
json = parse("false"); |
|
|
|
EXPECT_EQ(json.size(), 1); |
|
|
|
EXPECT_EQ(json.size(), 1); |
|
|
|
EXPECT_EQ(json.type(), Json::Value::Type::Bool); |
|
|
|
EXPECT_EQ(json.type(), Util::Json::Type::Bool); |
|
|
|
|
|
|
|
|
|
|
|
json = parse("3.14"); |
|
|
|
json = parse("3.14"); |
|
|
|
EXPECT_EQ(json.size(), 1); |
|
|
|
EXPECT_EQ(json.size(), 1); |
|
|
|
EXPECT_EQ(json.type(), Json::Value::Type::Number); |
|
|
|
EXPECT_EQ(json.type(), Util::Json::Type::Number); |
|
|
|
|
|
|
|
|
|
|
|
json = parse(R"("a string")"); |
|
|
|
json = parse(R"("a string")"); |
|
|
|
EXPECT_EQ(json.size(), 1); |
|
|
|
EXPECT_EQ(json.size(), 1); |
|
|
|
EXPECT_EQ(json.type(), Json::Value::Type::String); |
|
|
|
EXPECT_EQ(json.type(), Util::Json::Type::String); |
|
|
|
|
|
|
|
|
|
|
|
// Array
|
|
|
|
// Array
|
|
|
|
|
|
|
|
|
|
|
|
json = parse("["); |
|
|
|
json = parse("["); |
|
|
|
EXPECT_EQ(json.size(), 0); |
|
|
|
EXPECT_EQ(json.size(), 0); |
|
|
|
EXPECT_EQ(json.type(), Json::Value::Type::Null); |
|
|
|
EXPECT_EQ(json.type(), Util::Json::Type::Null); |
|
|
|
|
|
|
|
|
|
|
|
json = parse("[ 123"); |
|
|
|
json = parse("[ 123"); |
|
|
|
EXPECT_EQ(json.size(), 0); |
|
|
|
EXPECT_EQ(json.size(), 0); |
|
|
|
EXPECT_EQ(json.type(), Json::Value::Type::Null); |
|
|
|
EXPECT_EQ(json.type(), Util::Json::Type::Null); |
|
|
|
|
|
|
|
|
|
|
|
json = parse("[ 123,"); |
|
|
|
json = parse("[ 123,"); |
|
|
|
EXPECT_EQ(json.size(), 0); |
|
|
|
EXPECT_EQ(json.size(), 0); |
|
|
|
EXPECT_EQ(json.type(), Json::Value::Type::Null); |
|
|
|
EXPECT_EQ(json.type(), Util::Json::Type::Null); |
|
|
|
|
|
|
|
|
|
|
|
json = parse("[ 123, ]"); |
|
|
|
json = parse("[ 123, ]"); |
|
|
|
EXPECT_EQ(json.size(), 0); |
|
|
|
EXPECT_EQ(json.size(), 0); |
|
|
|
EXPECT_EQ(json.type(), Json::Value::Type::Null); |
|
|
|
EXPECT_EQ(json.type(), Util::Json::Type::Null); |
|
|
|
|
|
|
|
|
|
|
|
json = parse("[ 123 456 ]"); |
|
|
|
json = parse("[ 123 456 ]"); |
|
|
|
EXPECT_EQ(json.size(), 0); |
|
|
|
EXPECT_EQ(json.size(), 0); |
|
|
|
EXPECT_EQ(json.type(), Json::Value::Type::Null); |
|
|
|
EXPECT_EQ(json.type(), Util::Json::Type::Null); |
|
|
|
|
|
|
|
|
|
|
|
json = parse("[]"); |
|
|
|
json = parse("[]"); |
|
|
|
EXPECT_EQ(json.size(), 0); |
|
|
|
EXPECT_EQ(json.size(), 0); |
|
|
|
EXPECT_EQ(json.type(), Json::Value::Type::Array); |
|
|
|
EXPECT_EQ(json.type(), Util::Json::Type::Array); |
|
|
|
|
|
|
|
|
|
|
|
json = parse(R"([ "element", 3.14 ])"); |
|
|
|
json = parse(R"([ "element", 3.14 ])"); |
|
|
|
EXPECT_EQ(json.size(), 2); |
|
|
|
EXPECT_EQ(json.size(), 2); |
|
|
|
EXPECT_EQ(json.type(), Json::Value::Type::Array); |
|
|
|
EXPECT_EQ(json.type(), Util::Json::Type::Array); |
|
|
|
|
|
|
|
|
|
|
|
// Object
|
|
|
|
// Object
|
|
|
|
|
|
|
|
|
|
|
|
json = parse("{"); |
|
|
|
json = parse("{"); |
|
|
|
EXPECT_EQ(json.size(), 0); |
|
|
|
EXPECT_EQ(json.size(), 0); |
|
|
|
EXPECT_EQ(json.type(), Json::Value::Type::Null); |
|
|
|
EXPECT_EQ(json.type(), Util::Json::Type::Null); |
|
|
|
|
|
|
|
|
|
|
|
json = parse(R"({ "name")"); |
|
|
|
json = parse(R"({ "name")"); |
|
|
|
EXPECT_EQ(json.size(), 0); |
|
|
|
EXPECT_EQ(json.size(), 0); |
|
|
|
EXPECT_EQ(json.type(), Json::Value::Type::Null); |
|
|
|
EXPECT_EQ(json.type(), Util::Json::Type::Null); |
|
|
|
|
|
|
|
|
|
|
|
json = parse(R"({ "name":)"); |
|
|
|
json = parse(R"({ "name":)"); |
|
|
|
EXPECT_EQ(json.size(), 0); |
|
|
|
EXPECT_EQ(json.size(), 0); |
|
|
|
EXPECT_EQ(json.type(), Json::Value::Type::Null); |
|
|
|
EXPECT_EQ(json.type(), Util::Json::Type::Null); |
|
|
|
|
|
|
|
|
|
|
|
json = parse(R"({ "name":,)"); |
|
|
|
json = parse(R"({ "name":,)"); |
|
|
|
EXPECT_EQ(json.size(), 0); |
|
|
|
EXPECT_EQ(json.size(), 0); |
|
|
|
EXPECT_EQ(json.type(), Json::Value::Type::Null); |
|
|
|
EXPECT_EQ(json.type(), Util::Json::Type::Null); |
|
|
|
|
|
|
|
|
|
|
|
json = parse(R"({ "name":"value")"); |
|
|
|
json = parse(R"({ "name":"value")"); |
|
|
|
EXPECT_EQ(json.size(), 0); |
|
|
|
EXPECT_EQ(json.size(), 0); |
|
|
|
EXPECT_EQ(json.type(), Json::Value::Type::Null); |
|
|
|
EXPECT_EQ(json.type(), Util::Json::Type::Null); |
|
|
|
|
|
|
|
|
|
|
|
json = parse(R"({ "name":"value",)"); |
|
|
|
json = parse(R"({ "name":"value",)"); |
|
|
|
EXPECT_EQ(json.size(), 0); |
|
|
|
EXPECT_EQ(json.size(), 0); |
|
|
|
EXPECT_EQ(json.type(), Json::Value::Type::Null); |
|
|
|
EXPECT_EQ(json.type(), Util::Json::Type::Null); |
|
|
|
|
|
|
|
|
|
|
|
json = parse(R"({ "name":"value", })"); |
|
|
|
json = parse(R"({ "name":"value", })"); |
|
|
|
EXPECT_EQ(json.size(), 0); |
|
|
|
EXPECT_EQ(json.size(), 0); |
|
|
|
EXPECT_EQ(json.type(), Json::Value::Type::Null); |
|
|
|
EXPECT_EQ(json.type(), Util::Json::Type::Null); |
|
|
|
|
|
|
|
|
|
|
|
json = parse(R"({ "name" "value" })"); |
|
|
|
json = parse(R"({ "name" "value" })"); |
|
|
|
EXPECT_EQ(json.size(), 0); |
|
|
|
EXPECT_EQ(json.size(), 0); |
|
|
|
EXPECT_EQ(json.type(), Json::Value::Type::Null); |
|
|
|
EXPECT_EQ(json.type(), Util::Json::Type::Null); |
|
|
|
|
|
|
|
|
|
|
|
json = parse(R"({ 123 })"); |
|
|
|
json = parse(R"({ 123 })"); |
|
|
|
EXPECT_EQ(json.size(), 0); |
|
|
|
EXPECT_EQ(json.size(), 0); |
|
|
|
EXPECT_EQ(json.type(), Json::Value::Type::Null); |
|
|
|
EXPECT_EQ(json.type(), Util::Json::Type::Null); |
|
|
|
|
|
|
|
|
|
|
|
json = parse("{}"); |
|
|
|
json = parse("{}"); |
|
|
|
EXPECT_EQ(json.size(), 0); |
|
|
|
EXPECT_EQ(json.size(), 0); |
|
|
|
EXPECT_EQ(json.type(), Json::Value::Type::Object); |
|
|
|
EXPECT_EQ(json.type(), Util::Json::Type::Object); |
|
|
|
|
|
|
|
|
|
|
|
json = parse(R"({ "name": "value", "name2": 3.14 })"); |
|
|
|
json = parse(R"({ "name": "value", "name2": 3.14 })"); |
|
|
|
EXPECT_EQ(json.size(), 2); |
|
|
|
EXPECT_EQ(json.size(), 2); |
|
|
|
EXPECT_EQ(json.type(), Json::Value::Type::Object); |
|
|
|
EXPECT_EQ(json.type(), Util::Json::Type::Object); |
|
|
|
|
|
|
|
|
|
|
|
// Multiple root elements
|
|
|
|
// Multiple root elements
|
|
|
|
|
|
|
|
|
|
|
|
json = parse("54 false"); |
|
|
|
json = parse("54 false"); |
|
|
|
EXPECT_EQ(json.type(), Json::Value::Type::Null); |
|
|
|
EXPECT_EQ(json.type(), Util::Json::Type::Null); |
|
|
|
|
|
|
|
|
|
|
|
json = parse("3.14, 666"); |
|
|
|
json = parse("3.14, 666"); |
|
|
|
EXPECT_EQ(json.type(), Json::Value::Type::Null); |
|
|
|
EXPECT_EQ(json.type(), Util::Json::Type::Null); |
|
|
|
|
|
|
|
|
|
|
|
json = parse("true\nfalse"); |
|
|
|
json = parse("true\nfalse"); |
|
|
|
EXPECT_EQ(json.type(), Json::Value::Type::Null); |
|
|
|
EXPECT_EQ(json.type(), Util::Json::Type::Null); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST_CASE(JsonToJsonValue) |
|
|
|
TEST_CASE(JsonToJsonValue) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Json::Value json; |
|
|
|
Util::Json json; |
|
|
|
|
|
|
|
|
|
|
|
json = {}; |
|
|
|
json = {}; |
|
|
|
EXPECT_EQ(json.size(), 0); |
|
|
|
EXPECT_EQ(json.size(), 0); |
|
|
|
EXPECT_EQ(json.type(), Json::Value::Type::Null); |
|
|
|
EXPECT_EQ(json.type(), Util::Json::Type::Null); |
|
|
|
|
|
|
|
|
|
|
|
json = nullptr; |
|
|
|
json = nullptr; |
|
|
|
EXPECT_EQ(json.size(), 0); |
|
|
|
EXPECT_EQ(json.size(), 0); |
|
|
|
EXPECT_EQ(json.type(), Json::Value::Type::Null); |
|
|
|
EXPECT_EQ(json.type(), Util::Json::Type::Null); |
|
|
|
|
|
|
|
|
|
|
|
json = true; |
|
|
|
json = true; |
|
|
|
EXPECT_EQ(json.size(), 1); |
|
|
|
EXPECT_EQ(json.size(), 1); |
|
|
|
EXPECT_EQ(json.type(), Json::Value::Type::Bool); |
|
|
|
EXPECT_EQ(json.type(), Util::Json::Type::Bool); |
|
|
|
|
|
|
|
|
|
|
|
json = false; |
|
|
|
json = false; |
|
|
|
EXPECT_EQ(json.size(), 1); |
|
|
|
EXPECT_EQ(json.size(), 1); |
|
|
|
EXPECT_EQ(json.type(), Json::Value::Type::Bool); |
|
|
|
EXPECT_EQ(json.type(), Util::Json::Type::Bool); |
|
|
|
|
|
|
|
|
|
|
|
json = 666; |
|
|
|
json = 666; |
|
|
|
EXPECT_EQ(json.size(), 1); |
|
|
|
EXPECT_EQ(json.size(), 1); |
|
|
|
EXPECT_EQ(json.type(), Json::Value::Type::Number); |
|
|
|
EXPECT_EQ(json.type(), Util::Json::Type::Number); |
|
|
|
|
|
|
|
|
|
|
|
json = 3.14; |
|
|
|
json = 3.14; |
|
|
|
EXPECT_EQ(json.size(), 1); |
|
|
|
EXPECT_EQ(json.size(), 1); |
|
|
|
EXPECT_EQ(json.type(), Json::Value::Type::Number); |
|
|
|
EXPECT_EQ(json.type(), Util::Json::Type::Number); |
|
|
|
|
|
|
|
|
|
|
|
const char* characters = "my string"; |
|
|
|
const char* characters = "my string"; |
|
|
|
json = characters; |
|
|
|
json = characters; |
|
|
|
EXPECT_EQ(json.size(), 1); |
|
|
|
EXPECT_EQ(json.size(), 1); |
|
|
|
EXPECT_EQ(json.type(), Json::Value::Type::String); |
|
|
|
EXPECT_EQ(json.type(), Util::Json::Type::String); |
|
|
|
|
|
|
|
|
|
|
|
std::string string = "my string"; |
|
|
|
std::string string = "my string"; |
|
|
|
json = string; |
|
|
|
json = string; |
|
|
|
EXPECT_EQ(json.size(), 1); |
|
|
|
EXPECT_EQ(json.size(), 1); |
|
|
|
EXPECT_EQ(json.type(), Json::Value::Type::String); |
|
|
|
EXPECT_EQ(json.type(), Util::Json::Type::String); |
|
|
|
|
|
|
|
|
|
|
|
// Nested Array with multiple types
|
|
|
|
// Nested Array with multiple types
|
|
|
|
json = { "element", 3.14, true, nullptr, { "nested element", { "more nesting", { 1, 2, 3, "yes" } } } }; |
|
|
|
json = { "element", 3.14, true, nullptr, { "nested element", { "more nesting", { 1, 2, 3, "yes" } } } }; |
|
|
|
EXPECT_EQ(json.size(), 5); |
|
|
|
EXPECT_EQ(json.size(), 5); |
|
|
|
EXPECT_EQ(json.type(), Json::Value::Type::Array); |
|
|
|
EXPECT_EQ(json.type(), Util::Json::Type::Array); |
|
|
|
|
|
|
|
|
|
|
|
// Nested Object with multiple types
|
|
|
|
// Nested Object with multiple types
|
|
|
|
json = { { "name", "value" }, { "name2", 3.14 }, { "name3", true }, { "name4", nullptr }, { "name5", { { "nested name", "value" } } } }; |
|
|
|
json = { { "name", "value" }, { "name2", 3.14 }, { "name3", true }, { "name4", nullptr }, { "name5", { { "nested name", "value" } } } }; |
|
|
|
EXPECT_EQ(json.size(), 5); |
|
|
|
EXPECT_EQ(json.size(), 5); |
|
|
|
EXPECT_EQ(json.type(), Json::Value::Type::Object); |
|
|
|
EXPECT_EQ(json.type(), Util::Json::Type::Object); |
|
|
|
|
|
|
|
|
|
|
|
// Array with singular type
|
|
|
|
// Array with singular type
|
|
|
|
std::vector<std::string> vector = { "element", "element2", "element3" }; |
|
|
|
std::vector<std::string> vector = { "element", "element2", "element3" }; |
|
|
|
json = vector; |
|
|
|
json = vector; |
|
|
|
EXPECT_EQ(json.size(), 3); |
|
|
|
EXPECT_EQ(json.size(), 3); |
|
|
|
EXPECT_EQ(json.type(), Json::Value::Type::Array); |
|
|
|
EXPECT_EQ(json.type(), Util::Json::Type::Array); |
|
|
|
|
|
|
|
|
|
|
|
// Object with singular type
|
|
|
|
// Object with singular type
|
|
|
|
std::map<std::string, std::string> map = { { "name", "value" }, { "name2", "value2" } }; |
|
|
|
std::map<std::string, std::string> map = { { "name", "value" }, { "name2", "value2" } }; |
|
|
|
json = map; |
|
|
|
json = map; |
|
|
|
EXPECT_EQ(json.size(), 2); |
|
|
|
EXPECT_EQ(json.size(), 2); |
|
|
|
EXPECT_EQ(json.type(), Json::Value::Type::Object); |
|
|
|
EXPECT_EQ(json.type(), Util::Json::Type::Object); |
|
|
|
|
|
|
|
|
|
|
|
// Object with singular type
|
|
|
|
// Object with singular type
|
|
|
|
std::unordered_map<std::string, std::string> unorderedMap = { { "name", "value" }, { "name2", "value2" } }; |
|
|
|
std::unordered_map<std::string, std::string> unorderedMap = { { "name", "value" }, { "name2", "value2" } }; |
|
|
|
json = unorderedMap; |
|
|
|
json = unorderedMap; |
|
|
|
EXPECT_EQ(json.size(), 2); |
|
|
|
EXPECT_EQ(json.size(), 2); |
|
|
|
EXPECT_EQ(json.type(), Json::Value::Type::Object); |
|
|
|
EXPECT_EQ(json.type(), Util::Json::Type::Object); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST_CASE(JsonFromJsonValue) |
|
|
|
TEST_CASE(JsonFromJsonValue) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Json::Value json; |
|
|
|
Util::Json json; |
|
|
|
|
|
|
|
|
|
|
|
json = nullptr; |
|
|
|
json = nullptr; |
|
|
|
EXPECT_EQ(json.get<std::nullptr_t>(), nullptr); |
|
|
|
EXPECT_EQ(json.get<std::nullptr_t>(), nullptr); |
|
|
@ -373,7 +373,7 @@ TEST_CASE(JsonFromJsonValue) |
|
|
|
EXPECT_EQ(json.at(1).get<double>(), 3.14); |
|
|
|
EXPECT_EQ(json.at(1).get<double>(), 3.14); |
|
|
|
EXPECT_EQ(json[2].get<bool>(), true); |
|
|
|
EXPECT_EQ(json[2].get<bool>(), true); |
|
|
|
EXPECT_EQ(json[3].get<std::nullptr_t>(), nullptr); |
|
|
|
EXPECT_EQ(json[3].get<std::nullptr_t>(), nullptr); |
|
|
|
auto valueArray = json.get<std::vector<Json::Value>>(); |
|
|
|
auto valueArray = json.get<std::vector<Util::Json>>(); |
|
|
|
EXPECT_EQ(valueArray.size(), 4); |
|
|
|
EXPECT_EQ(valueArray.size(), 4); |
|
|
|
EXPECT_EQ(valueArray[0].get<std::string>(), "string"); |
|
|
|
EXPECT_EQ(valueArray[0].get<std::string>(), "string"); |
|
|
|
EXPECT_EQ(valueArray[1].get<double>(), 3.14); |
|
|
|
EXPECT_EQ(valueArray[1].get<double>(), 3.14); |
|
|
@ -417,7 +417,7 @@ TEST_CASE(JsonFromJsonValue) |
|
|
|
EXPECT_EQ(json.at("name2").get<double>(), 3.14); |
|
|
|
EXPECT_EQ(json.at("name2").get<double>(), 3.14); |
|
|
|
EXPECT_EQ(json["name3"].get<bool>(), true); |
|
|
|
EXPECT_EQ(json["name3"].get<bool>(), true); |
|
|
|
EXPECT_EQ(json["name4"].get<std::nullptr_t>(), nullptr); |
|
|
|
EXPECT_EQ(json["name4"].get<std::nullptr_t>(), nullptr); |
|
|
|
auto valueObject = json.get<std::map<std::string, Json::Value>>(); |
|
|
|
auto valueObject = json.get<std::map<std::string, Util::Json>>(); |
|
|
|
EXPECT_EQ(valueObject.size(), 4); |
|
|
|
EXPECT_EQ(valueObject.size(), 4); |
|
|
|
EXPECT_EQ(valueObject["name"].get<std::string>(), "value"); |
|
|
|
EXPECT_EQ(valueObject["name"].get<std::string>(), "value"); |
|
|
|
EXPECT_EQ(valueObject["name2"].get<double>(), 3.14); |
|
|
|
EXPECT_EQ(valueObject["name2"].get<double>(), 3.14); |
|
|
@ -455,25 +455,25 @@ TEST_CASE(JsonFromJsonValue) |
|
|
|
|
|
|
|
|
|
|
|
TEST_CASE(JsonImplicitConversion) |
|
|
|
TEST_CASE(JsonImplicitConversion) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Json::Value array; |
|
|
|
Util::Json array; |
|
|
|
array[0]; |
|
|
|
array[0]; |
|
|
|
EXPECT_EQ(array.type(), Json::Value::Type::Array); |
|
|
|
EXPECT_EQ(array.type(), Util::Json::Type::Array); |
|
|
|
|
|
|
|
|
|
|
|
Json::Value arrayEmplace; |
|
|
|
Util::Json arrayEmplace; |
|
|
|
arrayEmplace.emplace_back("element"); |
|
|
|
arrayEmplace.emplace_back("element"); |
|
|
|
arrayEmplace.emplace_back({ "nested element" }); |
|
|
|
arrayEmplace.emplace_back({ "nested element" }); |
|
|
|
EXPECT_EQ(arrayEmplace.type(), Json::Value::Type::Array); |
|
|
|
EXPECT_EQ(arrayEmplace.type(), Util::Json::Type::Array); |
|
|
|
EXPECT_EQ(arrayEmplace[1].type(), Json::Value::Type::Array); |
|
|
|
EXPECT_EQ(arrayEmplace[1].type(), Util::Json::Type::Array); |
|
|
|
|
|
|
|
|
|
|
|
Json::Value object; |
|
|
|
Util::Json object; |
|
|
|
object[""]; |
|
|
|
object[""]; |
|
|
|
EXPECT_EQ(object.type(), Json::Value::Type::Object); |
|
|
|
EXPECT_EQ(object.type(), Util::Json::Type::Object); |
|
|
|
|
|
|
|
|
|
|
|
Json::Value objectEmplace; |
|
|
|
Util::Json objectEmplace; |
|
|
|
objectEmplace.emplace("name", "value"); |
|
|
|
objectEmplace.emplace("name", "value"); |
|
|
|
objectEmplace.emplace("name2", { { "nested name", "value" } }); |
|
|
|
objectEmplace.emplace("name2", { { "nested name", "value" } }); |
|
|
|
EXPECT_EQ(objectEmplace.type(), Json::Value::Type::Object); |
|
|
|
EXPECT_EQ(objectEmplace.type(), Util::Json::Type::Object); |
|
|
|
EXPECT_EQ(objectEmplace["name2"].type(), Json::Value::Type::Object); |
|
|
|
EXPECT_EQ(objectEmplace["name2"].type(), Util::Json::Type::Object); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST_CASE(JsonSerializer) |
|
|
|
TEST_CASE(JsonSerializer) |
|
|
|