Skip to content

Commit

Permalink
add code coverage
Browse files Browse the repository at this point in the history
Signed-off-by: PengFei Li <lpengfei2016@gmail.com>
  • Loading branch information
banmoy committed Feb 21, 2025
1 parent f4a223f commit a863aaa
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions be/test/exec/json_parser_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,14 @@ TEST_F(JsonParserTest, test_expanded_json_document_stream_parser_with_root_error
test_parse_error_msg_base(parser.get(), data, "parse", "the value should be array type");
}

// parse() error because the root is an invalid json
{
std::string data = R"({"root": :})";
std::unique_ptr<JsonParser> parser(new ExpandedJsonDocumentStreamParserWithRoot(&simdjson_parser, jsonroot));
test_parse_error_msg_base(parser.get(), data, "parse",
"Failed to parse json as expanded document stream with json root");
}

// get_current() error because the root is an invalid array
{
std::string data = R"({"root": [:]})";
Expand All @@ -1160,6 +1168,13 @@ TEST_F(JsonParserTest, test_expanded_json_document_stream_parser_with_root_error
std::unique_ptr<JsonParser> parser(new ExpandedJsonDocumentStreamParserWithRoot(&simdjson_parser, jsonroot));
test_parse_error_msg_base(parser.get(), data, "advance", "the value under json root should be array type ");
}

// advance() error because the second root is an invalid json
{
std::string data = R"({"root": [{"k1":1}]}{"root": :})";
std::unique_ptr<JsonParser> parser(new ExpandedJsonDocumentStreamParserWithRoot(&simdjson_parser, jsonroot));
test_parse_error_msg_base(parser.get(), data, "advance", "Failed to iterate document stream sub-array");
}
}

TEST_F(JsonParserTest, test_expanded_json_array_parser_with_root_error) {
Expand All @@ -1174,6 +1189,14 @@ TEST_F(JsonParserTest, test_expanded_json_array_parser_with_root_error) {
test_parse_error_msg_base(parser.get(), data, "parse", "the value under json root should be array type");
}

// parse() error because the root is not an array
{
std::string data = R"([{"root": :}])";
std::unique_ptr<JsonParser> parser(new ExpandedJsonArrayParserWithRoot(&simdjson_parser, jsonroot));
test_parse_error_msg_base(parser.get(), data, "parse",
"Failed to parse json as expanded json array with json root");
}

// get_current() error because the root is an invalid array
{
std::string data = R"([{"root": [:]}])";
Expand All @@ -1196,6 +1219,13 @@ TEST_F(JsonParserTest, test_expanded_json_array_parser_with_root_error) {
std::unique_ptr<JsonParser> parser(new ExpandedJsonArrayParserWithRoot(&simdjson_parser, jsonroot));
test_parse_error_msg_base(parser.get(), data, "advance", "the value under json root should be array type");
}

// advance() error because the second document is an invalid json
{
std::string data = R"([{"root": [{"k1":1}]},{"root": :}])";
std::unique_ptr<JsonParser> parser(new ExpandedJsonArrayParserWithRoot(&simdjson_parser, jsonroot));
test_parse_error_msg_base(parser.get(), data, "advance", "Failed to iterate json array sub-array");
}
}

} // namespace starrocks

0 comments on commit a863aaa

Please sign in to comment.