Add test for invalid ast id.

This commit is contained in:
chriseth 2021-09-15 17:48:26 +02:00
parent 05d20446bb
commit 63993387d6
2 changed files with 79 additions and 0 deletions

View File

@ -193,6 +193,7 @@ def examine_id_coverage(top_dir, source_id_to_file_names, new_ids_only=False):
white_ids = { white_ids = {
"9804", # Tested in test/libyul/ObjectParser.cpp. "9804", # Tested in test/libyul/ObjectParser.cpp.
"1544", "1544",
"1749",
"2674", "2674",
"6367", "6367",
"8387", "8387",

View File

@ -848,6 +848,84 @@ BOOST_AUTO_TEST_CASE(astid_reset)
BOOST_CHECK(debugDataOf(result->statements.at(1))->astID == nullopt); BOOST_CHECK(debugDataOf(result->statements.at(1))->astID == nullopt);
} }
BOOST_AUTO_TEST_CASE(astid_multi)
{
ErrorList errorList;
ErrorReporter reporter(errorList);
auto const sourceText = R"(
/// @src -1:-1:-1 @ast-id 7 @src 1:1:1 @ast-id 8
{}
)";
EVMDialectTyped const& dialect = EVMDialectTyped::instance(EVMVersion{});
shared_ptr<Block> result = parse(sourceText, dialect, reporter);
BOOST_REQUIRE(!!result);
BOOST_CHECK(result->debugData->astID == int64_t(8));
}
BOOST_AUTO_TEST_CASE(astid_invalid)
{
ErrorList errorList;
ErrorReporter reporter(errorList);
auto const sourceText = R"(
/// @src -1:-1:-1 @ast-id abc @src 1:1:1
{}
)";
EVMDialectTyped const& dialect = EVMDialectTyped::instance(EVMVersion{});
shared_ptr<Block> result = parse(sourceText, dialect, reporter);
BOOST_REQUIRE(!!result);
BOOST_REQUIRE(errorList.size() == 1);
BOOST_TEST(errorList[0]->type() == Error::Type::SyntaxError);
BOOST_TEST(errorList[0]->errorId() == 1749_error);
CHECK_LOCATION(result->debugData->location, "", -1, -1);
}
BOOST_AUTO_TEST_CASE(astid_too_large)
{
ErrorList errorList;
ErrorReporter reporter(errorList);
auto const sourceText = R"(
/// @ast-id 9223372036854775808
{}
)";
EVMDialectTyped const& dialect = EVMDialectTyped::instance(EVMVersion{});
shared_ptr<Block> result = parse(sourceText, dialect, reporter);
BOOST_REQUIRE(!!result);
BOOST_REQUIRE(errorList.size() == 1);
BOOST_TEST(errorList[0]->type() == Error::Type::SyntaxError);
BOOST_TEST(errorList[0]->errorId() == 1749_error);
}
BOOST_AUTO_TEST_CASE(astid_way_too_large)
{
ErrorList errorList;
ErrorReporter reporter(errorList);
auto const sourceText = R"(
/// @ast-id 999999999999999999999999999999999999999
{}
)";
EVMDialectTyped const& dialect = EVMDialectTyped::instance(EVMVersion{});
shared_ptr<Block> result = parse(sourceText, dialect, reporter);
BOOST_REQUIRE(!!result);
BOOST_REQUIRE(errorList.size() == 1);
BOOST_TEST(errorList[0]->type() == Error::Type::SyntaxError);
BOOST_TEST(errorList[0]->errorId() == 1749_error);
}
BOOST_AUTO_TEST_CASE(astid_not_fully_numeric)
{
ErrorList errorList;
ErrorReporter reporter(errorList);
auto const sourceText = R"(
/// @ast-id 9x
{}
)";
EVMDialectTyped const& dialect = EVMDialectTyped::instance(EVMVersion{});
shared_ptr<Block> result = parse(sourceText, dialect, reporter);
BOOST_REQUIRE(!!result);
BOOST_REQUIRE(errorList.size() == 1);
BOOST_TEST(errorList[0]->type() == Error::Type::SyntaxError);
BOOST_TEST(errorList[0]->errorId() == 1749_error);
}
BOOST_AUTO_TEST_CASE(customSourceLocations_multiple_src_tags_on_one_line) BOOST_AUTO_TEST_CASE(customSourceLocations_multiple_src_tags_on_one_line)
{ {