Skip to content

Commit

Permalink
[v0.0.3] Fix tag parser: allowed to use dots inside tag name + added …
Browse files Browse the repository at this point in the history
…simple test to check it
  • Loading branch information
DronCode committed Mar 19, 2024
1 parent f4b8da1 commit 327cfc2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cpp/source/Tag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace rg3::cpp
Tags Tag::parseFromCommentString(std::string_view commentText)
{
std::vector<Tag> tags;
std::regex tagRegex("@([a-zA-Z_]+)(\\([^)]*\\))?");
std::regex tagRegex("@([a-zA-Z_.]+)(\\([^)]*\\))?");
std::smatch tagMatch;

auto commentBegin = std::cregex_iterator(commentText.data(), commentText.data() + commentText.size(), tagRegex);
Expand Down
36 changes: 36 additions & 0 deletions Tests/Unit/source/Tests_Comment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,40 @@ struct MyCoolStructure
ASSERT_EQ(asClass->getFunctions()[0].vTags.getTag("use_anyway").getArgumentsCount(), 1) << "Expected to have 1 arg";
ASSERT_EQ(asClass->getFunctions()[0].vTags.getTag("use_anyway").getArguments()[0].getHoldedType(), rg3::cpp::TagArgumentType::AT_I64) << "Expected to have i64";
ASSERT_EQ(asClass->getFunctions()[0].vTags.getTag("use_anyway").getArguments()[0].asI64(0), 1) << "Expected to have 1";
}

TEST_F(Tests_Comments, CommentWithDots)
{
g_Analyzer->setSourceCode(R"(
/**
* @runtime
* @ecs.component(1024, true)
**/
class PlayerComponent
{
};
)");

g_Analyzer->getCompilerConfig().cppStandard = rg3::llvm::CxxStandard::CC_14;

const auto analyzeResult = g_Analyzer->analyze();

ASSERT_TRUE(analyzeResult.vIssues.empty()) << "No issues should be here";
ASSERT_EQ(analyzeResult.vFoundTypes.size(), 1) << "Only 1 type should be here";

const auto& tags = analyzeResult.vFoundTypes[0]->getTags();
ASSERT_EQ(analyzeResult.vFoundTypes[0]->getName(), "PlayerComponent");
ASSERT_TRUE(tags.hasTag("runtime")) << "Type must have 'runtime' tag";
ASSERT_TRUE(tags.hasTag("ecs.component")) << "Type must have 'ecs.component' tag";
ASSERT_FALSE(tags.hasTag("ecs")) << "Type must have not 'ecs' tag";
ASSERT_EQ(tags.getTag("ecs.component").getArgumentsCount(), 2) << "Invalid args count";
ASSERT_EQ(tags.getTag("ecs.component").getArguments()[0].getHoldedType(), rg3::cpp::TagArgumentType::AT_I64) << "A0 must be i64";
ASSERT_EQ(tags.getTag("ecs.component").getArguments()[0].asI64(0), 1024) << "A0 == 1024";
ASSERT_EQ(tags.getTag("ecs.component").getArguments()[1].getHoldedType(), rg3::cpp::TagArgumentType::AT_BOOL) << "A1 must be bool";
ASSERT_EQ(tags.getTag("ecs.component").getArguments()[1].asBool(false), true) << "A1 == true";

ASSERT_EQ(analyzeResult.vFoundTypes[0]->getKind(), rg3::cpp::TypeKind::TK_STRUCT_OR_CLASS) << "Type 0 must be struct or class";

auto asClass = static_cast<rg3::cpp::TypeClass*>(analyzeResult.vFoundTypes[0].get()); // NOLINT(*-pro-type-static-cast-downcast)
ASSERT_FALSE(asClass->isStruct()) << "T0 must be a class!";
}

0 comments on commit 327cfc2

Please sign in to comment.