Switched test case alias matcher to regex

This commit is contained in:
Bartek Kryza
2022-01-24 21:01:31 +01:00
parent 4aedc6e330
commit 48e00dd094
3 changed files with 47 additions and 14 deletions

View File

@@ -90,9 +90,9 @@ void generator::generate_relationships(
for (const auto &r : p.relationships()) {
std::stringstream relstr;
try {
relstr << m_model.to_alias(ns_relative(uns, r.destination()))
<< " <.. "
<< m_model.to_alias(ns_relative(uns, p.full_name(false)))
relstr << m_model.to_alias(ns_relative(uns, p.full_name(false)))
<< " ..> "
<< m_model.to_alias(ns_relative(uns, r.destination()))
<< '\n';
ostr << relstr.str();
}

View File

@@ -49,9 +49,30 @@ TEST_CASE("t30002", "[test-case][package]")
REQUIRE_THAT(puml, Contains("component [A1]"));
REQUIRE_THAT(puml, Contains("component [A2]"));
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 [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(
"./" + config.output_directory + "/" + diagram->name + ".puml", puml);

View File

@@ -168,19 +168,31 @@ struct AliasMatcher {
std::string operator()(const std::string &name)
{
std::vector<std::string> patterns;
patterns.push_back("class \"" + name + "\" as ");
patterns.push_back("abstract \"" + name + "\" as ");
patterns.push_back("enum \"" + name + "\" as ");
patterns.push_back("component \"" + name + "\" as ");
patterns.push_back("component [" + name + "] as ");
std::vector<std::regex> patterns;
const std::string alias_regex("([A-Z]_[0-9]+)");
patterns.push_back(
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 &pattern : patterns) {
const auto idx = line.find(pattern);
if (idx != std::string::npos) {
std::string res = line.substr(idx + pattern.size());
return trim(res);
if (std::regex_search(line, base_match, pattern)) {
if (base_match.size() == 2) {
std::ssub_match base_sub_match = base_match[1];
std::string alias = base_sub_match.str();
return trim(alias);
}
}
}
}