Added sequence diagram JSON test matchers

This commit is contained in:
Bartek Kryza
2023-03-23 00:25:33 +01:00
parent 491fb2b443
commit 49a40723a7
33 changed files with 883 additions and 570 deletions

View File

@@ -95,14 +95,42 @@ void generator::generate_call(const message &m, nlohmann::json &parent) const
msg["name"] = message;
msg["type"] = "message";
msg["from"]["name"] = from.value().full_name(false);
msg["from"]["id"] = std::to_string(from.value().id());
msg["from"]["activity_name"] = from.value().full_name(false);
msg["from"]["activity_id"] = std::to_string(from.value().id());
msg["to"]["activity_id"] = std::to_string(to.value().id());
msg["to"]["activity_name"] = to.value().full_name(false);
if (from.value().type_name() == "method") {
const auto &class_participant =
m_model.get_participant<model::method>(from.value().id()).value();
msg["from"]["participant_id"] =
std::to_string(class_participant.class_id());
msg["from"]["participant_name"] =
m_model.get_participant<model::class_>(class_participant.class_id())
.value()
.full_name(false);
}
else if (from.value().type_name() == "function" ||
from.value().type_name() == "function_template") {
if (m_config.combine_free_functions_into_file_participants()) {
const auto &file_participant =
m_model.get_participant<model::function>(from.value().id())
.value();
msg["from"]["participant_id"] =
std::to_string(common::to_id(file_participant.file()));
msg["from"]["participant_name"] = file_participant.file_relative();
}
else {
msg["from"]["participant_id"] = std::to_string(from.value().id());
msg["from"]["participant_name"] = from.value().full_name(false);
}
}
if (to.value().type_name() == "method") {
const auto &class_participant =
m_model.get_participant<model::method>(to.value().id()).value();
msg["to"]["participant_id"] =
std::to_string(class_participant.class_id());
msg["to"]["participant_name"] =
@@ -110,13 +138,20 @@ void generator::generate_call(const message &m, nlohmann::json &parent) const
.value()
.full_name(false);
}
else if (to.value().type_name() == "function" &&
m_config.combine_free_functions_into_file_participants()) {
const auto &file_participant =
m_model.get_participant<model::function>(to.value().id()).value();
msg["to"]["participant_id"] =
std::to_string(common::to_id(file_participant.file()));
msg["to"]["participant_name"] = file_participant.file_relative();
else if (to.value().type_name() == "function" ||
to.value().type_name() == "function_template") {
if (m_config.combine_free_functions_into_file_participants()) {
const auto &file_participant =
m_model.get_participant<model::function>(to.value().id())
.value();
msg["to"]["participant_id"] =
std::to_string(common::to_id(file_participant.file()));
msg["to"]["participant_name"] = file_participant.file_relative();
}
else {
msg["to"]["participant_id"] = std::to_string(to.value().id());
msg["to"]["participant_name"] = to.value().full_name(false);
}
}
msg["source_location"] =

View File

@@ -69,8 +69,10 @@ void generator::generate_call(const message &m, std::ostream &ostr) const
render_mode = model::function::message_render_mode::no_arguments;
if (to.value().type_name() == "method") {
message = dynamic_cast<const model::function &>(to.value())
.message_name(render_mode);
const auto &f = dynamic_cast<const model::method &>(to.value());
const std::string_view style = f.is_static() ? "__" : "";
message =
fmt::format("{}{}{}", style, f.message_name(render_mode), style);
}
else if (m_config.combine_free_functions_into_file_participants()) {
if (to.value().type_name() == "function") {

View File

@@ -185,7 +185,7 @@ std::string method::message_name(message_render_mode mode) const
{
constexpr auto kAbbreviatedMethodArgumentsLength{15};
const std::string style = is_static() ? "__" : "";
const std::string style = "";
if (mode == message_render_mode::no_arguments) {
return fmt::format("{}{}(){}{}", style, method_name(),