Fixed base sequence diagram test cases after refactor
This commit is contained in:
@@ -29,14 +29,22 @@ common::model::diagram_t diagram::type() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
common::optional_ref<common::model::diagram_element> diagram::get(
|
common::optional_ref<common::model::diagram_element> diagram::get(
|
||||||
const std::string & /*full_name*/) const
|
const std::string & full_name) const
|
||||||
{
|
{
|
||||||
|
for(const auto& [id, participant] : participants) {
|
||||||
|
if(participant->full_name(false) == full_name)
|
||||||
|
return {*participant};
|
||||||
|
}
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
common::optional_ref<common::model::diagram_element> diagram::get(
|
common::optional_ref<common::model::diagram_element> diagram::get(
|
||||||
const common::model::diagram_element::id_t /*id*/) const
|
const common::model::diagram_element::id_t id) const
|
||||||
{
|
{
|
||||||
|
if(participants.find(id) != participants.end())
|
||||||
|
return {*participants.at(id)};
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,6 +61,11 @@ inja::json diagram::context() const
|
|||||||
|
|
||||||
inja::json::array_t elements{};
|
inja::json::array_t elements{};
|
||||||
|
|
||||||
|
// Add classes
|
||||||
|
for (const auto &[id, p] : participants) {
|
||||||
|
elements.emplace_back(p->context());
|
||||||
|
}
|
||||||
|
|
||||||
ctx["elements"] = elements;
|
ctx["elements"] = elements;
|
||||||
|
|
||||||
return ctx;
|
return ctx;
|
||||||
|
|||||||
@@ -201,7 +201,6 @@ std::string abbreviate(const std::string &s, const unsigned int max_length)
|
|||||||
bool find_element_alias(
|
bool find_element_alias(
|
||||||
const std::string &input, std::tuple<std::string, size_t, size_t> &result)
|
const std::string &input, std::tuple<std::string, size_t, size_t> &result)
|
||||||
{
|
{
|
||||||
|
|
||||||
std::regex alias_regex("(@A\\([^\\).]+\\))");
|
std::regex alias_regex("(@A\\([^\\).]+\\))");
|
||||||
|
|
||||||
auto alias_it =
|
auto alias_it =
|
||||||
|
|||||||
@@ -19,4 +19,4 @@ diagrams:
|
|||||||
before:
|
before:
|
||||||
- "' t20001 test sequence diagram"
|
- "' t20001 test sequence diagram"
|
||||||
after:
|
after:
|
||||||
- 'note over "tmain()": Main test function'
|
- '{% set e=element("clanguml::t20001::tmain()") %} note over {{ e.alias) }}: Main test function'
|
||||||
|
|||||||
@@ -33,15 +33,16 @@ TEST_CASE("t20001", "[test-case][sequence]")
|
|||||||
REQUIRE(!model->should_include("std::vector"));
|
REQUIRE(!model->should_include("std::vector"));
|
||||||
|
|
||||||
auto puml = generate_sequence_puml(diagram, *model);
|
auto puml = generate_sequence_puml(diagram, *model);
|
||||||
|
AliasMatcher _A(puml);
|
||||||
|
|
||||||
REQUIRE_THAT(puml, StartsWith("@startuml"));
|
REQUIRE_THAT(puml, StartsWith("@startuml"));
|
||||||
REQUIRE_THAT(puml, EndsWith("@enduml\n"));
|
REQUIRE_THAT(puml, EndsWith("@enduml\n"));
|
||||||
|
|
||||||
REQUIRE_THAT(puml, HasCall("A", "log_result"));
|
REQUIRE_THAT(puml, HasCall(_A("A"), "log_result"));
|
||||||
REQUIRE_THAT(puml, HasCall("B", "A", "log_result"));
|
REQUIRE_THAT(puml, HasCall(_A("B"), _A("A"), "log_result"));
|
||||||
REQUIRE_THAT(puml, HasCallWithResponse("B", "A", "add3"));
|
REQUIRE_THAT(puml, HasCallWithResponse(_A("B"), _A("A"), "add3"));
|
||||||
REQUIRE_THAT(puml, HasCall("A", "add"));
|
REQUIRE_THAT(puml, HasCall(_A("A"), "add"));
|
||||||
REQUIRE_THAT(puml, !HasCall("A", "detail::C", "add"));
|
REQUIRE_THAT(puml, !HasCall(_A("A"), _A("detail::C"), "add"));
|
||||||
|
|
||||||
save_puml(
|
save_puml(
|
||||||
"./" + config.output_directory() + "/" + diagram->name + ".puml", puml);
|
"./" + config.output_directory() + "/" + diagram->name + ".puml", puml);
|
||||||
|
|||||||
@@ -29,13 +29,14 @@ TEST_CASE("t20002", "[test-case][sequence]")
|
|||||||
REQUIRE(model->name() == "t20002_sequence");
|
REQUIRE(model->name() == "t20002_sequence");
|
||||||
|
|
||||||
auto puml = generate_sequence_puml(diagram, *model);
|
auto puml = generate_sequence_puml(diagram, *model);
|
||||||
|
AliasMatcher _A(puml);
|
||||||
|
|
||||||
REQUIRE_THAT(puml, StartsWith("@startuml"));
|
REQUIRE_THAT(puml, StartsWith("@startuml"));
|
||||||
REQUIRE_THAT(puml, EndsWith("@enduml\n"));
|
REQUIRE_THAT(puml, EndsWith("@enduml\n"));
|
||||||
|
|
||||||
REQUIRE_THAT(puml, HasFunctionCall("m1", "m2"));
|
REQUIRE_THAT(puml, HasCall(_A("m1()"), _A("m2()"), "m2"));
|
||||||
REQUIRE_THAT(puml, HasFunctionCall("m2", "m3"));
|
REQUIRE_THAT(puml, HasCall(_A("m2()"), _A("m3()"), "m3"));
|
||||||
REQUIRE_THAT(puml, HasFunctionCall("m3", "m4"));
|
REQUIRE_THAT(puml, HasCall(_A("m3()"), _A("m4()"), "m4"));
|
||||||
|
|
||||||
save_puml(
|
save_puml(
|
||||||
"./" + config.output_directory() + "/" + diagram->name + ".puml", puml);
|
"./" + config.output_directory() + "/" + diagram->name + ".puml", puml);
|
||||||
|
|||||||
@@ -29,13 +29,14 @@ TEST_CASE("t20003", "[test-case][sequence]")
|
|||||||
REQUIRE(model->name() == "t20003_sequence");
|
REQUIRE(model->name() == "t20003_sequence");
|
||||||
|
|
||||||
auto puml = generate_sequence_puml(diagram, *model);
|
auto puml = generate_sequence_puml(diagram, *model);
|
||||||
|
AliasMatcher _A(puml);
|
||||||
|
|
||||||
REQUIRE_THAT(puml, StartsWith("@startuml"));
|
REQUIRE_THAT(puml, StartsWith("@startuml"));
|
||||||
REQUIRE_THAT(puml, EndsWith("@enduml\n"));
|
REQUIRE_THAT(puml, EndsWith("@enduml\n"));
|
||||||
|
|
||||||
REQUIRE_THAT(puml, HasFunctionCall("m1<T>", "m2<T>"));
|
REQUIRE_THAT(puml, HasCall(_A("m1<T>()"), _A("m2<T>()")));
|
||||||
REQUIRE_THAT(puml, HasFunctionCall("m2<T>", "m3<T>"));
|
REQUIRE_THAT(puml, HasCall(_A("m2<T>()"), _A("m3<T>()")));
|
||||||
REQUIRE_THAT(puml, HasFunctionCall("m3<T>", "m4<T>"));
|
REQUIRE_THAT(puml, HasCall(_A("m3<T>()"), _A("m4<T>()")));
|
||||||
|
|
||||||
save_puml(
|
save_puml(
|
||||||
"./" + config.output_directory() + "/" + diagram->name + ".puml", puml);
|
"./" + config.output_directory() + "/" + diagram->name + ".puml", puml);
|
||||||
|
|||||||
@@ -32,15 +32,14 @@ TEST_CASE("t20004", "[test-case][sequence]")
|
|||||||
AliasMatcher _A(puml);
|
AliasMatcher _A(puml);
|
||||||
|
|
||||||
REQUIRE_THAT(puml, StartsWith("@startuml"));
|
REQUIRE_THAT(puml, StartsWith("@startuml"));
|
||||||
REQUIRE_THAT(puml, HasFunctionCall("main()", "m1<int>()"));
|
REQUIRE_THAT(puml, HasCall(_A("main()"), _A("m1<int>()")));
|
||||||
REQUIRE_THAT(puml, HasFunctionCall("m2<T>", "m3<T>"));
|
REQUIRE_THAT(puml, HasCall(_A("m2<T>()"), _A("m3<T>()")));
|
||||||
REQUIRE_THAT(puml, HasFunctionCall("m3<T>", "m4<T>"));
|
REQUIRE_THAT(puml, HasCall(_A("m3<T>()"), _A("m4<T>()")));
|
||||||
REQUIRE_THAT(puml, EndsWith("@enduml\n"));
|
REQUIRE_THAT(puml, EndsWith("@enduml\n"));
|
||||||
|
|
||||||
|
|
||||||
// Check if all calls exist
|
// Check if all calls exist
|
||||||
REQUIRE_THAT(puml, HasCall("A", "log_result"));
|
REQUIRE_THAT(puml, HasCall(_A("A"), "log_result"));
|
||||||
//REQUIRE_THAT(puml, HasCallWithResponse("B", "A", "add3"));
|
// REQUIRE_THAT(puml, HasCallWithResponse("B", "A", "add3"));
|
||||||
|
|
||||||
save_puml(
|
save_puml(
|
||||||
"./" + config.output_directory() + "/" + diagram->name + ".puml", puml);
|
"./" + config.output_directory() + "/" + diagram->name + ".puml", puml);
|
||||||
|
|||||||
@@ -123,25 +123,16 @@ ContainsMatcher HasCall(std::string const &from, std::string const &message,
|
|||||||
CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes)
|
CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes)
|
||||||
{
|
{
|
||||||
return ContainsMatcher(
|
return ContainsMatcher(
|
||||||
CasedString(fmt::format("\"{}\" -> \"{}\" : {}()", from, from, message),
|
CasedString(fmt::format("{} -> {} : {}()", from, from, message),
|
||||||
caseSensitivity));
|
caseSensitivity));
|
||||||
}
|
}
|
||||||
|
|
||||||
ContainsMatcher HasFunctionCall(std::string const &from,
|
|
||||||
std::string const &message,
|
|
||||||
CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes)
|
|
||||||
{
|
|
||||||
return ContainsMatcher(CasedString(
|
|
||||||
fmt::format("\"{}()\" -> \"{}()\" : {}()", from, message, message),
|
|
||||||
caseSensitivity));
|
|
||||||
}
|
|
||||||
|
|
||||||
ContainsMatcher HasCall(std::string const &from, std::string const &to,
|
ContainsMatcher HasCall(std::string const &from, std::string const &to,
|
||||||
std::string const &message,
|
std::string const &message,
|
||||||
CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes)
|
CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes)
|
||||||
{
|
{
|
||||||
return ContainsMatcher(
|
return ContainsMatcher(
|
||||||
CasedString(fmt::format("\"{}\" -> \"{}\" : {}()", from, to, message),
|
CasedString(fmt::format("{} -> {} : {}()", from, to, message),
|
||||||
caseSensitivity));
|
caseSensitivity));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,10 +141,10 @@ auto HasCallWithResponse(std::string const &from, std::string const &to,
|
|||||||
CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes)
|
CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes)
|
||||||
{
|
{
|
||||||
return HasCallWithResultMatcher(
|
return HasCallWithResultMatcher(
|
||||||
CasedString(fmt::format("\"{}\" -> \"{}\" : {}()", from, to, message),
|
CasedString(fmt::format("{} -> {} : {}()", from, to, message),
|
||||||
caseSensitivity),
|
caseSensitivity),
|
||||||
CasedString(
|
CasedString(
|
||||||
fmt::format("\"{}\" --> \"{}\"", to, from), caseSensitivity));
|
fmt::format("{} --> {}", to, from), caseSensitivity));
|
||||||
}
|
}
|
||||||
|
|
||||||
struct AliasMatcher {
|
struct AliasMatcher {
|
||||||
@@ -162,12 +153,15 @@ struct AliasMatcher {
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string operator()(const std::string &name)
|
std::string operator()(std::string name)
|
||||||
{
|
{
|
||||||
std::vector<std::regex> patterns;
|
std::vector<std::regex> patterns;
|
||||||
|
|
||||||
const std::string alias_regex("([A-Z]_[0-9]+)");
|
const std::string alias_regex("([A-Z]_[0-9]+)");
|
||||||
|
|
||||||
|
util::replace_all(name, "(", "\\(");
|
||||||
|
util::replace_all(name, ")", "\\)");
|
||||||
|
|
||||||
patterns.push_back(
|
patterns.push_back(
|
||||||
std::regex{"class\\s\"" + name + "\"\\sas\\s" + alias_regex});
|
std::regex{"class\\s\"" + name + "\"\\sas\\s" + alias_regex});
|
||||||
patterns.push_back(
|
patterns.push_back(
|
||||||
@@ -182,6 +176,8 @@ struct AliasMatcher {
|
|||||||
std::regex{"file\\s\"" + name + "\"\\sas\\s" + alias_regex});
|
std::regex{"file\\s\"" + name + "\"\\sas\\s" + alias_regex});
|
||||||
patterns.push_back(
|
patterns.push_back(
|
||||||
std::regex{"folder\\s\"" + name + "\"\\sas\\s" + alias_regex});
|
std::regex{"folder\\s\"" + name + "\"\\sas\\s" + alias_regex});
|
||||||
|
patterns.push_back(
|
||||||
|
std::regex{"participant\\s\"" + name + "\"\\sas\\s" + alias_regex});
|
||||||
|
|
||||||
std::smatch base_match;
|
std::smatch base_match;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user