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

@@ -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);
}
}
}
}