Switched test case alias matcher to regex
This commit is contained in:
@@ -90,9 +90,9 @@ void generator::generate_relationships(
|
|||||||
for (const auto &r : p.relationships()) {
|
for (const auto &r : p.relationships()) {
|
||||||
std::stringstream relstr;
|
std::stringstream relstr;
|
||||||
try {
|
try {
|
||||||
relstr << m_model.to_alias(ns_relative(uns, r.destination()))
|
relstr << m_model.to_alias(ns_relative(uns, p.full_name(false)))
|
||||||
<< " <.. "
|
<< " ..> "
|
||||||
<< m_model.to_alias(ns_relative(uns, p.full_name(false)))
|
<< m_model.to_alias(ns_relative(uns, r.destination()))
|
||||||
<< '\n';
|
<< '\n';
|
||||||
ostr << relstr.str();
|
ostr << relstr.str();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,9 +49,30 @@ TEST_CASE("t30002", "[test-case][package]")
|
|||||||
REQUIRE_THAT(puml, Contains("component [A1]"));
|
REQUIRE_THAT(puml, Contains("component [A1]"));
|
||||||
REQUIRE_THAT(puml, Contains("component [A2]"));
|
REQUIRE_THAT(puml, Contains("component [A2]"));
|
||||||
REQUIRE_THAT(puml, Contains("component [A3]"));
|
REQUIRE_THAT(puml, Contains("component [A3]"));
|
||||||
|
REQUIRE_THAT(puml, Contains("component [A4]"));
|
||||||
|
REQUIRE_THAT(puml, Contains("component [A5]"));
|
||||||
|
REQUIRE_THAT(puml, Contains("component [A6]"));
|
||||||
|
REQUIRE_THAT(puml, Contains("component [A7]"));
|
||||||
|
REQUIRE_THAT(puml, Contains("component [A8]"));
|
||||||
|
REQUIRE_THAT(puml, Contains("component [A9]"));
|
||||||
|
REQUIRE_THAT(puml, Contains("component [A10]"));
|
||||||
|
REQUIRE_THAT(puml, Contains("component [A11]"));
|
||||||
REQUIRE_THAT(puml, Contains("component [A12]"));
|
REQUIRE_THAT(puml, Contains("component [A12]"));
|
||||||
|
REQUIRE_THAT(puml, Contains("component [A13]"));
|
||||||
|
|
||||||
// REQUIRE_THAT(puml, IsDependency(_A("BBB"), _A("AAA")));
|
REQUIRE_THAT(puml, IsDependency(_A("BBB"), _A("A1")));
|
||||||
|
REQUIRE_THAT(puml, IsDependency(_A("BBB"), _A("A2")));
|
||||||
|
REQUIRE_THAT(puml, IsDependency(_A("BBB"), _A("A3")));
|
||||||
|
REQUIRE_THAT(puml, IsDependency(_A("BBB"), _A("A4")));
|
||||||
|
REQUIRE_THAT(puml, IsDependency(_A("BBB"), _A("A5")));
|
||||||
|
REQUIRE_THAT(puml, IsDependency(_A("BBB"), _A("A6")));
|
||||||
|
REQUIRE_THAT(puml, IsDependency(_A("BBB"), _A("A7")));
|
||||||
|
REQUIRE_THAT(puml, IsDependency(_A("BBB"), _A("A8")));
|
||||||
|
REQUIRE_THAT(puml, IsDependency(_A("BBB"), _A("A9")));
|
||||||
|
REQUIRE_THAT(puml, IsDependency(_A("BBB"), _A("A10")));
|
||||||
|
REQUIRE_THAT(puml, IsDependency(_A("BBB"), _A("A11")));
|
||||||
|
REQUIRE_THAT(puml, IsDependency(_A("BBB"), _A("A12")));
|
||||||
|
REQUIRE_THAT(puml, IsDependency(_A("BBB"), _A("A13")));
|
||||||
|
|
||||||
save_puml(
|
save_puml(
|
||||||
"./" + config.output_directory + "/" + diagram->name + ".puml", puml);
|
"./" + config.output_directory + "/" + diagram->name + ".puml", puml);
|
||||||
|
|||||||
@@ -168,19 +168,31 @@ struct AliasMatcher {
|
|||||||
|
|
||||||
std::string operator()(const std::string &name)
|
std::string operator()(const std::string &name)
|
||||||
{
|
{
|
||||||
std::vector<std::string> patterns;
|
std::vector<std::regex> patterns;
|
||||||
patterns.push_back("class \"" + name + "\" as ");
|
|
||||||
patterns.push_back("abstract \"" + name + "\" as ");
|
const std::string alias_regex("([A-Z]_[0-9]+)");
|
||||||
patterns.push_back("enum \"" + name + "\" as ");
|
|
||||||
patterns.push_back("component \"" + name + "\" as ");
|
patterns.push_back(
|
||||||
patterns.push_back("component [" + name + "] as ");
|
std::regex{"class\\s\"" + name + "\"\\sas\\s" + alias_regex});
|
||||||
|
patterns.push_back(
|
||||||
|
std::regex{"abstract\\s\"" + name + "\"\\sas\\s" + alias_regex});
|
||||||
|
patterns.push_back(
|
||||||
|
std::regex{"enum\\s\"" + name + "\"\\sas\\s" + alias_regex});
|
||||||
|
patterns.push_back(
|
||||||
|
std::regex{"component\\s\"" + name + "\"\\sas\\s" + alias_regex});
|
||||||
|
patterns.push_back(
|
||||||
|
std::regex{"component\\s\\[" + name + "\\]\\sas\\s" + alias_regex});
|
||||||
|
|
||||||
|
std::smatch base_match;
|
||||||
|
|
||||||
for (const auto &line : puml) {
|
for (const auto &line : puml) {
|
||||||
for (const auto &pattern : patterns) {
|
for (const auto &pattern : patterns) {
|
||||||
const auto idx = line.find(pattern);
|
if (std::regex_search(line, base_match, pattern)) {
|
||||||
if (idx != std::string::npos) {
|
if (base_match.size() == 2) {
|
||||||
std::string res = line.substr(idx + pattern.size());
|
std::ssub_match base_sub_match = base_match[1];
|
||||||
return trim(res);
|
std::string alias = base_sub_match.str();
|
||||||
|
return trim(alias);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user