Added json class generator test cases
This commit is contained in:
@@ -34,6 +34,9 @@ void to_json(nlohmann::json &j, const element &c)
|
|||||||
{"namespace", c.get_namespace().to_string()}, {"type", c.type_name()},
|
{"namespace", c.get_namespace().to_string()}, {"type", c.type_name()},
|
||||||
{"display_name", c.full_name(false)}};
|
{"display_name", c.full_name(false)}};
|
||||||
|
|
||||||
|
if (c.comment())
|
||||||
|
j["comment"] = c.comment().value();
|
||||||
|
|
||||||
if (!c.file().empty())
|
if (!c.file().empty())
|
||||||
j["source_location"] =
|
j["source_location"] =
|
||||||
dynamic_cast<const common::model::source_location &>(c);
|
dynamic_cast<const common::model::source_location &>(c);
|
||||||
@@ -60,7 +63,12 @@ void to_json(nlohmann::json &j, const relationship &c)
|
|||||||
j["multiplicity_source"] = c.multiplicity_source();
|
j["multiplicity_source"] = c.multiplicity_source();
|
||||||
if (!c.multiplicity_destination().empty())
|
if (!c.multiplicity_destination().empty())
|
||||||
j["multiplicity_destination"] = c.multiplicity_destination();
|
j["multiplicity_destination"] = c.multiplicity_destination();
|
||||||
j["access"] = to_string(c.access());
|
if (c.access() != access_t::kNone)
|
||||||
|
j["access"] = to_string(c.access());
|
||||||
|
if (!c.label().empty())
|
||||||
|
j["label"] = c.label();
|
||||||
|
if (c.comment())
|
||||||
|
j["comment"] = c.comment().value();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -69,11 +77,15 @@ namespace clanguml::class_diagram::model {
|
|||||||
using nlohmann::json;
|
using nlohmann::json;
|
||||||
void to_json(nlohmann::json &j, const class_element &c)
|
void to_json(nlohmann::json &j, const class_element &c)
|
||||||
{
|
{
|
||||||
j = {{"name", c.name()}, {"type", c.type()},
|
j["name"] = c.name();
|
||||||
{"access", to_string(c.access())}};
|
j["type"] = c.type();
|
||||||
|
if (c.access() != common::model::access_t::kNone)
|
||||||
|
j["access"] = to_string(c.access());
|
||||||
if (!c.file().empty())
|
if (!c.file().empty())
|
||||||
j["source_location"] =
|
j["source_location"] =
|
||||||
dynamic_cast<const common::model::source_location &>(c);
|
dynamic_cast<const common::model::source_location &>(c);
|
||||||
|
if (c.comment())
|
||||||
|
j["comment"] = c.comment().value();
|
||||||
}
|
}
|
||||||
|
|
||||||
void to_json(nlohmann::json &j, const class_member &c)
|
void to_json(nlohmann::json &j, const class_member &c)
|
||||||
@@ -92,6 +104,8 @@ void to_json(nlohmann::json &j, const method_parameter &c)
|
|||||||
|
|
||||||
void to_json(nlohmann::json &j, const class_method &c)
|
void to_json(nlohmann::json &j, const class_method &c)
|
||||||
{
|
{
|
||||||
|
j = dynamic_cast<const class_element &>(c);
|
||||||
|
|
||||||
j["is_static"] = c.is_static();
|
j["is_static"] = c.is_static();
|
||||||
j["is_const"] = c.is_const();
|
j["is_const"] = c.is_const();
|
||||||
j["is_defaulted"] = c.is_defaulted();
|
j["is_defaulted"] = c.is_defaulted();
|
||||||
@@ -106,7 +120,8 @@ void to_json(nlohmann::json &j, const class_parent &c)
|
|||||||
{
|
{
|
||||||
j["is_virtual"] = c.is_virtual();
|
j["is_virtual"] = c.is_virtual();
|
||||||
j["id"] = std::to_string(c.id());
|
j["id"] = std::to_string(c.id());
|
||||||
j["access"] = to_string(c.access());
|
if (c.access() != common::model::access_t::kNone)
|
||||||
|
j["access"] = to_string(c.access());
|
||||||
j["name"] = c.name();
|
j["name"] = c.name();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,6 +167,8 @@ void generator::generate(std::ostream &ostr) const
|
|||||||
{
|
{
|
||||||
generate_top_level_elements(json_);
|
generate_top_level_elements(json_);
|
||||||
|
|
||||||
|
generate_relationships(json_);
|
||||||
|
|
||||||
ostr << json_;
|
ostr << json_;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,6 +184,16 @@ void generator::generate_top_level_elements(nlohmann::json &parent) const
|
|||||||
generate(*cls, parent);
|
generate(*cls, parent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (auto *enm = dynamic_cast<enum_ *>(p.get()); enm) {
|
||||||
|
if (m_model.should_include(*enm)) {
|
||||||
|
generate(*enm, parent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (auto *cpt = dynamic_cast<concept_ *>(p.get()); cpt) {
|
||||||
|
if (m_model.should_include(*cpt)) {
|
||||||
|
generate(*cpt, parent);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,11 +204,11 @@ void generator::generate(const package &p, nlohmann::json &parent) const
|
|||||||
nlohmann::json package_object;
|
nlohmann::json package_object;
|
||||||
|
|
||||||
if (m_config.generate_packages()) {
|
if (m_config.generate_packages()) {
|
||||||
LOG_DBG("Generating package {}", p.name());
|
|
||||||
|
|
||||||
// Don't generate packages from namespaces filtered out by
|
// Don't generate packages from namespaces filtered out by
|
||||||
// using_namespace
|
// using_namespace
|
||||||
if (!uns.starts_with({p.full_name(false)})) {
|
if (!uns.starts_with({p.full_name(false)})) {
|
||||||
|
LOG_DBG("Generating package {}", p.name());
|
||||||
|
|
||||||
package_object["type"] = "namespace";
|
package_object["type"] = "namespace";
|
||||||
package_object["name"] = p.name();
|
package_object["name"] = p.name();
|
||||||
package_object["display_name"] = p.full_name(false);
|
package_object["display_name"] = p.full_name(false);
|
||||||
@@ -190,7 +217,6 @@ void generator::generate(const package &p, nlohmann::json &parent) const
|
|||||||
|
|
||||||
for (const auto &subpackage : p) {
|
for (const auto &subpackage : p) {
|
||||||
if (dynamic_cast<package *>(subpackage.get()) != nullptr) {
|
if (dynamic_cast<package *>(subpackage.get()) != nullptr) {
|
||||||
// TODO: add option - generate_empty_packages
|
|
||||||
const auto &sp = dynamic_cast<package &>(*subpackage);
|
const auto &sp = dynamic_cast<package &>(*subpackage);
|
||||||
if (!sp.is_empty()) {
|
if (!sp.is_empty()) {
|
||||||
if (m_config.generate_packages())
|
if (m_config.generate_packages())
|
||||||
@@ -200,35 +226,32 @@ void generator::generate(const package &p, nlohmann::json &parent) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (auto *cls = dynamic_cast<class_ *>(subpackage.get()); cls) {
|
else if (auto *cls = dynamic_cast<class_ *>(subpackage.get()); cls) {
|
||||||
const auto &sp = dynamic_cast<class_ &>(*subpackage);
|
if (m_model.should_include(*cls)) {
|
||||||
if (m_model.should_include(*subpackage)) {
|
|
||||||
if (m_config.generate_packages())
|
if (m_config.generate_packages())
|
||||||
generate(sp, package_object);
|
generate(*cls, package_object);
|
||||||
else
|
else
|
||||||
generate(sp, parent);
|
generate(*cls, parent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (auto *enm = dynamic_cast<enum_ *>(subpackage.get()); enm) {
|
else if (auto *enm = dynamic_cast<enum_ *>(subpackage.get()); enm) {
|
||||||
const auto &sp = dynamic_cast<enum_ &>(*subpackage);
|
if (m_model.should_include(*enm)) {
|
||||||
if (m_model.should_include(*subpackage)) {
|
|
||||||
if (m_config.generate_packages())
|
if (m_config.generate_packages())
|
||||||
generate(sp, package_object);
|
generate(*enm, package_object);
|
||||||
else
|
else
|
||||||
generate(sp, parent);
|
generate(*enm, parent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (auto *cpt = dynamic_cast<concept_ *>(subpackage.get()); cpt) {
|
else if (auto *cpt = dynamic_cast<concept_ *>(subpackage.get()); cpt) {
|
||||||
const auto &sp = dynamic_cast<concept_ &>(*subpackage);
|
if (m_model.should_include(*cpt)) {
|
||||||
if (m_model.should_include(*subpackage)) {
|
|
||||||
if (m_config.generate_packages())
|
if (m_config.generate_packages())
|
||||||
generate(sp, package_object);
|
generate(*cpt, package_object);
|
||||||
else
|
else
|
||||||
generate(sp, parent);
|
generate(*cpt, parent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_config.generate_packages()) {
|
if (m_config.generate_packages() && !package_object.empty()) {
|
||||||
parent["elements"].push_back(std::move(package_object));
|
parent["elements"].push_back(std::move(package_object));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -236,20 +259,19 @@ void generator::generate(const package &p, nlohmann::json &parent) const
|
|||||||
void generator::generate(const class_ &c, nlohmann::json &parent) const
|
void generator::generate(const class_ &c, nlohmann::json &parent) const
|
||||||
{
|
{
|
||||||
nlohmann::json object = c;
|
nlohmann::json object = c;
|
||||||
json_["elements"].push_back(std::move(object));
|
parent["elements"].push_back(std::move(object));
|
||||||
}
|
}
|
||||||
|
|
||||||
void generator::generate(const enum_ &e, nlohmann::json &parent) const
|
void generator::generate(const enum_ &e, nlohmann::json &parent) const
|
||||||
{
|
{
|
||||||
nlohmann::json object = e;
|
nlohmann::json object = e;
|
||||||
json_["elements"].push_back(std::move(object));
|
parent["elements"].push_back(std::move(object));
|
||||||
}
|
}
|
||||||
|
|
||||||
void generator::generate(const concept_ &c, nlohmann::json &parent) const
|
void generator::generate(const concept_ &c, nlohmann::json &parent) const
|
||||||
{
|
{
|
||||||
nlohmann::json object = c;
|
nlohmann::json object = c;
|
||||||
json_["elements"].push_back(std::move(object));
|
parent["elements"].push_back(std::move(object));
|
||||||
generate_relationships(json_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void generator::generate_relationships(nlohmann::json &parent) const
|
void generator::generate_relationships(nlohmann::json &parent) const
|
||||||
@@ -280,6 +302,14 @@ void generator::generate_relationships(
|
|||||||
const class_ &c, nlohmann::json &parent) const
|
const class_ &c, nlohmann::json &parent) const
|
||||||
{
|
{
|
||||||
for (const auto &r : c.relationships()) {
|
for (const auto &r : c.relationships()) {
|
||||||
|
auto target_element = m_model.get(r.destination());
|
||||||
|
if (!target_element.has_value()) {
|
||||||
|
LOG_DBG("Skipping {} relation from {} to {} due "
|
||||||
|
"to unresolved destination id",
|
||||||
|
to_string(r.type()), c.full_name(), r.destination());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
nlohmann::json rel = r;
|
nlohmann::json rel = r;
|
||||||
rel["source"] = std::to_string(c.id());
|
rel["source"] = std::to_string(c.id());
|
||||||
parent["relationships"].push_back(rel);
|
parent["relationships"].push_back(rel);
|
||||||
@@ -300,6 +330,14 @@ void generator::generate_relationships(
|
|||||||
const enum_ &c, nlohmann::json &parent) const
|
const enum_ &c, nlohmann::json &parent) const
|
||||||
{
|
{
|
||||||
for (const auto &r : c.relationships()) {
|
for (const auto &r : c.relationships()) {
|
||||||
|
auto target_element = m_model.get(r.destination());
|
||||||
|
if (!target_element.has_value()) {
|
||||||
|
LOG_DBG("Skipping {} relation from {} to {} due "
|
||||||
|
"to unresolved destination id",
|
||||||
|
to_string(r.type()), c.full_name(), r.destination());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
nlohmann::json rel = r;
|
nlohmann::json rel = r;
|
||||||
rel["source"] = std::to_string(c.id());
|
rel["source"] = std::to_string(c.id());
|
||||||
parent["relationships"].push_back(rel);
|
parent["relationships"].push_back(rel);
|
||||||
@@ -310,6 +348,14 @@ void generator::generate_relationships(
|
|||||||
const concept_ &c, nlohmann::json &parent) const
|
const concept_ &c, nlohmann::json &parent) const
|
||||||
{
|
{
|
||||||
for (const auto &r : c.relationships()) {
|
for (const auto &r : c.relationships()) {
|
||||||
|
auto target_element = m_model.get(r.destination());
|
||||||
|
if (!target_element.has_value()) {
|
||||||
|
LOG_DBG("Skipping {} relation from {} to {} due "
|
||||||
|
"to unresolved destination id",
|
||||||
|
to_string(r.type()), c.full_name(), r.destination());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
nlohmann::json rel = r;
|
nlohmann::json rel = r;
|
||||||
rel["source"] = std::to_string(c.id());
|
rel["source"] = std::to_string(c.id());
|
||||||
parent["relationships"].push_back(rel);
|
parent["relationships"].push_back(rel);
|
||||||
@@ -319,6 +365,31 @@ void generator::generate_relationships(
|
|||||||
void generator::generate_relationships(
|
void generator::generate_relationships(
|
||||||
const package &p, nlohmann::json &parent) const
|
const package &p, nlohmann::json &parent) const
|
||||||
{
|
{
|
||||||
|
for (const auto &subpackage : p) {
|
||||||
|
if (dynamic_cast<package *>(subpackage.get()) != nullptr) {
|
||||||
|
const auto &sp = dynamic_cast<package &>(*subpackage);
|
||||||
|
if (!sp.is_empty())
|
||||||
|
generate_relationships(sp, parent);
|
||||||
|
}
|
||||||
|
else if (dynamic_cast<class_ *>(subpackage.get()) != nullptr) {
|
||||||
|
if (m_model.should_include(*subpackage)) {
|
||||||
|
generate_relationships(
|
||||||
|
dynamic_cast<class_ &>(*subpackage), parent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (dynamic_cast<enum_ *>(subpackage.get()) != nullptr) {
|
||||||
|
if (m_model.should_include(*subpackage)) {
|
||||||
|
generate_relationships(
|
||||||
|
dynamic_cast<enum_ &>(*subpackage), parent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (dynamic_cast<concept_ *>(subpackage.get()) != nullptr) {
|
||||||
|
if (m_model.should_include(*subpackage)) {
|
||||||
|
generate_relationships(
|
||||||
|
dynamic_cast<concept_ &>(*subpackage), parent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace clanguml::class_diagram::generators::plantuml
|
} // namespace clanguml::class_diagram::generators::plantuml
|
||||||
|
|||||||
@@ -74,4 +74,445 @@ TEST_CASE("t00002", "[test-case][class]")
|
|||||||
"This is class B"));
|
"This is class B"));
|
||||||
|
|
||||||
save_puml(config.output_directory() + "/" + diagram->name + ".puml", puml);
|
save_puml(config.output_directory() + "/" + diagram->name + ".puml", puml);
|
||||||
|
|
||||||
|
const std::string expected_json = R"##(
|
||||||
|
{
|
||||||
|
"elements": [
|
||||||
|
{
|
||||||
|
"bases": [],
|
||||||
|
"comment": {
|
||||||
|
"brief": [
|
||||||
|
" This is class A\n"
|
||||||
|
],
|
||||||
|
"formatted": "\\brief This is class A",
|
||||||
|
"paragraph": [
|
||||||
|
" \n"
|
||||||
|
],
|
||||||
|
"raw": "/// \\brief This is class A",
|
||||||
|
"text": "\n \n"
|
||||||
|
},
|
||||||
|
"display_name": "clanguml::t00002::A",
|
||||||
|
"id": "987634239855407298",
|
||||||
|
"is_abstract": true,
|
||||||
|
"is_nested": false,
|
||||||
|
"is_struct": false,
|
||||||
|
"is_template": false,
|
||||||
|
"is_union": false,
|
||||||
|
"members": [],
|
||||||
|
"methods": [
|
||||||
|
{
|
||||||
|
"access": "public",
|
||||||
|
"comment": {
|
||||||
|
"formatted": "Abstract foo_a",
|
||||||
|
"paragraph": [
|
||||||
|
" Abstract foo_a\n"
|
||||||
|
],
|
||||||
|
"raw": "/// Abstract foo_a",
|
||||||
|
"text": "\n Abstract foo_a\n"
|
||||||
|
},
|
||||||
|
"is_const": false,
|
||||||
|
"is_defaulted": false,
|
||||||
|
"is_implicit": false,
|
||||||
|
"is_pure_virtual": true,
|
||||||
|
"is_static": false,
|
||||||
|
"is_virtual": true,
|
||||||
|
"name": "foo_a",
|
||||||
|
"parameters": [],
|
||||||
|
"type": "void"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"access": "public",
|
||||||
|
"comment": {
|
||||||
|
"formatted": "Abstract foo_c",
|
||||||
|
"paragraph": [
|
||||||
|
" Abstract foo_c\n"
|
||||||
|
],
|
||||||
|
"raw": "/// Abstract foo_c",
|
||||||
|
"text": "\n Abstract foo_c\n"
|
||||||
|
},
|
||||||
|
"is_const": false,
|
||||||
|
"is_defaulted": false,
|
||||||
|
"is_implicit": false,
|
||||||
|
"is_pure_virtual": true,
|
||||||
|
"is_static": false,
|
||||||
|
"is_virtual": true,
|
||||||
|
"name": "foo_c",
|
||||||
|
"parameters": [],
|
||||||
|
"type": "void"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "A",
|
||||||
|
"namespace": "clanguml::t00002",
|
||||||
|
"source_location": {
|
||||||
|
"file": "/home/bartek/devel/clang-uml/tests/t00002/t00002.cc",
|
||||||
|
"line": 7
|
||||||
|
},
|
||||||
|
"template_parameters": [],
|
||||||
|
"type": "class"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"bases": [
|
||||||
|
{
|
||||||
|
"access": "public",
|
||||||
|
"id": "987634239855407298",
|
||||||
|
"is_virtual": false,
|
||||||
|
"name": "clanguml::t00002::A"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"comment": {
|
||||||
|
"brief": [
|
||||||
|
" This is class B\n"
|
||||||
|
],
|
||||||
|
"formatted": "\\brief This is class B",
|
||||||
|
"paragraph": [
|
||||||
|
" \n"
|
||||||
|
],
|
||||||
|
"raw": "/// \\brief This is class B",
|
||||||
|
"text": "\n \n"
|
||||||
|
},
|
||||||
|
"display_name": "clanguml::t00002::B",
|
||||||
|
"id": "594234458687375950",
|
||||||
|
"is_abstract": false,
|
||||||
|
"is_nested": false,
|
||||||
|
"is_struct": false,
|
||||||
|
"is_template": false,
|
||||||
|
"is_union": false,
|
||||||
|
"members": [],
|
||||||
|
"methods": [
|
||||||
|
{
|
||||||
|
"access": "public",
|
||||||
|
"is_const": false,
|
||||||
|
"is_defaulted": false,
|
||||||
|
"is_implicit": false,
|
||||||
|
"is_pure_virtual": false,
|
||||||
|
"is_static": false,
|
||||||
|
"is_virtual": true,
|
||||||
|
"name": "foo_a",
|
||||||
|
"parameters": [],
|
||||||
|
"type": "void"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "B",
|
||||||
|
"namespace": "clanguml::t00002",
|
||||||
|
"source_location": {
|
||||||
|
"file": "/home/bartek/devel/clang-uml/tests/t00002/t00002.cc",
|
||||||
|
"line": 16
|
||||||
|
},
|
||||||
|
"template_parameters": [],
|
||||||
|
"type": "class"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"bases": [
|
||||||
|
{
|
||||||
|
"access": "public",
|
||||||
|
"id": "987634239855407298",
|
||||||
|
"is_virtual": false,
|
||||||
|
"name": "clanguml::t00002::A"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"comment": {
|
||||||
|
"brief": [
|
||||||
|
" This is class C - class C has a long comment\n"
|
||||||
|
],
|
||||||
|
"formatted": "@brief This is class C - class C has a long comment\n\nVivamus integer non suscipit taciti mus etiam at primis tempor sagittis sit,\neuismod libero facilisi aptent elementum felis blandit cursus gravida sociis\nerat ante, eleifend lectus nullam dapibus netus feugiat curae curabitur est\nad.",
|
||||||
|
"paragraph": [
|
||||||
|
" \n",
|
||||||
|
" Vivamus integer non suscipit taciti mus etiam at primis tempor sagittis sit,\n euismod libero facilisi aptent elementum felis blandit cursus gravida sociis\n erat ante, eleifend lectus nullam dapibus netus feugiat curae curabitur est\n ad.\n"
|
||||||
|
],
|
||||||
|
"raw": "/// @brief This is class C - class C has a long comment\n///\n/// Vivamus integer non suscipit taciti mus etiam at primis tempor sagittis sit,\n/// euismod libero facilisi aptent elementum felis blandit cursus gravida sociis\n/// erat ante, eleifend lectus nullam dapibus netus feugiat curae curabitur est\n/// ad.",
|
||||||
|
"text": "\n \n\n Vivamus integer non suscipit taciti mus etiam at primis tempor sagittis sit,\n euismod libero facilisi aptent elementum felis blandit cursus gravida sociis\n erat ante, eleifend lectus nullam dapibus netus feugiat curae curabitur est\n ad.\n"
|
||||||
|
},
|
||||||
|
"display_name": "clanguml::t00002::C",
|
||||||
|
"id": "1142499429598587507",
|
||||||
|
"is_abstract": false,
|
||||||
|
"is_nested": false,
|
||||||
|
"is_struct": false,
|
||||||
|
"is_template": false,
|
||||||
|
"is_union": false,
|
||||||
|
"members": [],
|
||||||
|
"methods": [
|
||||||
|
{
|
||||||
|
"access": "public",
|
||||||
|
"comment": {
|
||||||
|
"formatted": "Do nothing unless override is provided",
|
||||||
|
"paragraph": [
|
||||||
|
" Do nothing unless override is provided\n"
|
||||||
|
],
|
||||||
|
"raw": "/// Do nothing unless override is provided",
|
||||||
|
"text": "\n Do nothing unless override is provided\n"
|
||||||
|
},
|
||||||
|
"is_const": false,
|
||||||
|
"is_defaulted": false,
|
||||||
|
"is_implicit": false,
|
||||||
|
"is_pure_virtual": false,
|
||||||
|
"is_static": false,
|
||||||
|
"is_virtual": true,
|
||||||
|
"name": "foo_c",
|
||||||
|
"parameters": [],
|
||||||
|
"type": "void"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "C",
|
||||||
|
"namespace": "clanguml::t00002",
|
||||||
|
"source_location": {
|
||||||
|
"file": "/home/bartek/devel/clang-uml/tests/t00002/t00002.cc",
|
||||||
|
"line": 27
|
||||||
|
},
|
||||||
|
"template_parameters": [],
|
||||||
|
"type": "class"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"bases": [
|
||||||
|
{
|
||||||
|
"access": "public",
|
||||||
|
"id": "594234458687375950",
|
||||||
|
"is_virtual": false,
|
||||||
|
"name": "clanguml::t00002::B"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"access": "public",
|
||||||
|
"id": "1142499429598587507",
|
||||||
|
"is_virtual": false,
|
||||||
|
"name": "clanguml::t00002::C"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"comment": {
|
||||||
|
"formatted": "This is class D\nwhich is a little like B\nand a little like C",
|
||||||
|
"paragraph": [
|
||||||
|
" This is class D\n which is a little like B\n and a little like C\n"
|
||||||
|
],
|
||||||
|
"raw": "/// This is class D\n/// which is a little like B\n/// and a little like C",
|
||||||
|
"text": "\n This is class D\n which is a little like B\n and a little like C\n"
|
||||||
|
},
|
||||||
|
"display_name": "clanguml::t00002::D",
|
||||||
|
"id": "60950494980414724",
|
||||||
|
"is_abstract": false,
|
||||||
|
"is_nested": false,
|
||||||
|
"is_struct": false,
|
||||||
|
"is_template": false,
|
||||||
|
"is_union": false,
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"access": "private",
|
||||||
|
"comment": {
|
||||||
|
"formatted": "All the A pointers",
|
||||||
|
"paragraph": [
|
||||||
|
" All the A pointers\n"
|
||||||
|
],
|
||||||
|
"raw": "/// All the A pointers",
|
||||||
|
"text": "\n All the A pointers\n"
|
||||||
|
},
|
||||||
|
"is_static": false,
|
||||||
|
"name": "as",
|
||||||
|
"source_location": {
|
||||||
|
"file": "/home/bartek/devel/clang-uml/tests/t00002/t00002.cc",
|
||||||
|
"line": 58
|
||||||
|
},
|
||||||
|
"type": "std::vector<A *>"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"methods": [
|
||||||
|
{
|
||||||
|
"access": "public",
|
||||||
|
"comment": {
|
||||||
|
"formatted": "\n Forward foo_a\n ",
|
||||||
|
"paragraph": [
|
||||||
|
" Forward foo_a\n"
|
||||||
|
],
|
||||||
|
"raw": "/**\n * Forward foo_a\n */",
|
||||||
|
"text": "\n Forward foo_a\n"
|
||||||
|
},
|
||||||
|
"is_const": false,
|
||||||
|
"is_defaulted": false,
|
||||||
|
"is_implicit": false,
|
||||||
|
"is_pure_virtual": false,
|
||||||
|
"is_static": false,
|
||||||
|
"is_virtual": true,
|
||||||
|
"name": "foo_a",
|
||||||
|
"parameters": [],
|
||||||
|
"type": "void"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"access": "public",
|
||||||
|
"comment": {
|
||||||
|
"formatted": "\n Forward foo_c\n ",
|
||||||
|
"paragraph": [
|
||||||
|
" Forward foo_c\n"
|
||||||
|
],
|
||||||
|
"raw": "/**\n * Forward foo_c\n */",
|
||||||
|
"text": "\n Forward foo_c\n"
|
||||||
|
},
|
||||||
|
"is_const": false,
|
||||||
|
"is_defaulted": false,
|
||||||
|
"is_implicit": false,
|
||||||
|
"is_pure_virtual": false,
|
||||||
|
"is_static": false,
|
||||||
|
"is_virtual": true,
|
||||||
|
"name": "foo_c",
|
||||||
|
"parameters": [],
|
||||||
|
"type": "void"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "D",
|
||||||
|
"namespace": "clanguml::t00002",
|
||||||
|
"source_location": {
|
||||||
|
"file": "/home/bartek/devel/clang-uml/tests/t00002/t00002.cc",
|
||||||
|
"line": 36
|
||||||
|
},
|
||||||
|
"template_parameters": [],
|
||||||
|
"type": "class"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"bases": [
|
||||||
|
{
|
||||||
|
"access": "public",
|
||||||
|
"id": "594234458687375950",
|
||||||
|
"is_virtual": true,
|
||||||
|
"name": "clanguml::t00002::B"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"access": "public",
|
||||||
|
"id": "1142499429598587507",
|
||||||
|
"is_virtual": true,
|
||||||
|
"name": "clanguml::t00002::C"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"display_name": "clanguml::t00002::E",
|
||||||
|
"id": "2237886670308966220",
|
||||||
|
"is_abstract": false,
|
||||||
|
"is_nested": false,
|
||||||
|
"is_struct": false,
|
||||||
|
"is_template": false,
|
||||||
|
"is_union": false,
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"access": "private",
|
||||||
|
"comment": {
|
||||||
|
"formatted": "All the A pointers",
|
||||||
|
"paragraph": [
|
||||||
|
" All the A pointers\n"
|
||||||
|
],
|
||||||
|
"raw": "/// All the A pointers",
|
||||||
|
"text": "\n All the A pointers\n"
|
||||||
|
},
|
||||||
|
"is_static": false,
|
||||||
|
"name": "as",
|
||||||
|
"source_location": {
|
||||||
|
"file": "/home/bartek/devel/clang-uml/tests/t00002/t00002.cc",
|
||||||
|
"line": 83
|
||||||
|
},
|
||||||
|
"type": "std::vector<A *>"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"methods": [
|
||||||
|
{
|
||||||
|
"access": "public",
|
||||||
|
"comment": {
|
||||||
|
"formatted": "\n Forward foo_a",
|
||||||
|
"paragraph": [
|
||||||
|
" Forward foo_a\n"
|
||||||
|
],
|
||||||
|
"raw": "///\n /// Forward foo_a\n ///",
|
||||||
|
"text": "\n Forward foo_a\n"
|
||||||
|
},
|
||||||
|
"is_const": false,
|
||||||
|
"is_defaulted": false,
|
||||||
|
"is_implicit": false,
|
||||||
|
"is_pure_virtual": false,
|
||||||
|
"is_static": false,
|
||||||
|
"is_virtual": true,
|
||||||
|
"name": "foo_a",
|
||||||
|
"parameters": [],
|
||||||
|
"type": "void"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"access": "public",
|
||||||
|
"comment": {
|
||||||
|
"formatted": "\n Forward foo_c",
|
||||||
|
"paragraph": [
|
||||||
|
" Forward foo_c\n"
|
||||||
|
],
|
||||||
|
"raw": "///\n /// Forward foo_c\n ///",
|
||||||
|
"text": "\n Forward foo_c\n"
|
||||||
|
},
|
||||||
|
"is_const": false,
|
||||||
|
"is_defaulted": false,
|
||||||
|
"is_implicit": false,
|
||||||
|
"is_pure_virtual": false,
|
||||||
|
"is_static": false,
|
||||||
|
"is_virtual": true,
|
||||||
|
"name": "foo_c",
|
||||||
|
"parameters": [],
|
||||||
|
"type": "void"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "E",
|
||||||
|
"namespace": "clanguml::t00002",
|
||||||
|
"source_location": {
|
||||||
|
"file": "/home/bartek/devel/clang-uml/tests/t00002/t00002.cc",
|
||||||
|
"line": 61
|
||||||
|
},
|
||||||
|
"template_parameters": [],
|
||||||
|
"type": "class"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"relationships": [
|
||||||
|
{
|
||||||
|
"access": "public",
|
||||||
|
"destination": "987634239855407298",
|
||||||
|
"source": "594234458687375950",
|
||||||
|
"type": "extension"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"access": "public",
|
||||||
|
"destination": "987634239855407298",
|
||||||
|
"source": "1142499429598587507",
|
||||||
|
"type": "extension"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"access": "private",
|
||||||
|
"destination": "987634239855407298",
|
||||||
|
"label": "as",
|
||||||
|
"source": "60950494980414724",
|
||||||
|
"type": "association"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"access": "public",
|
||||||
|
"destination": "594234458687375950",
|
||||||
|
"source": "60950494980414724",
|
||||||
|
"type": "extension"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"access": "public",
|
||||||
|
"destination": "1142499429598587507",
|
||||||
|
"source": "60950494980414724",
|
||||||
|
"type": "extension"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"access": "private",
|
||||||
|
"destination": "987634239855407298",
|
||||||
|
"label": "as",
|
||||||
|
"source": "2237886670308966220",
|
||||||
|
"type": "association"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"access": "public",
|
||||||
|
"destination": "594234458687375950",
|
||||||
|
"source": "2237886670308966220",
|
||||||
|
"type": "extension"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"access": "public",
|
||||||
|
"destination": "1142499429598587507",
|
||||||
|
"source": "2237886670308966220",
|
||||||
|
"type": "extension"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
)##";
|
||||||
|
auto j = generate_class_json(diagram, *model);
|
||||||
|
|
||||||
|
REQUIRE(j == nlohmann::json::parse(expected_json));
|
||||||
|
|
||||||
|
save_json(config.output_directory() + "/" + diagram->name + ".json", j);
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -46,4 +46,197 @@ TEST_CASE("t00036", "[test-case][class]")
|
|||||||
REQUIRE_THAT(puml, IsAggregation(_A("B"), _A("A<int>"), "+a_int"));
|
REQUIRE_THAT(puml, IsAggregation(_A("B"), _A("A<int>"), "+a_int"));
|
||||||
|
|
||||||
save_puml(config.output_directory() + "/" + diagram->name + ".puml", puml);
|
save_puml(config.output_directory() + "/" + diagram->name + ".puml", puml);
|
||||||
|
|
||||||
|
const std::string expected_json = R"##(
|
||||||
|
{
|
||||||
|
"elements": [
|
||||||
|
{
|
||||||
|
"display_name": "clanguml::t00036::ns1",
|
||||||
|
"elements": [
|
||||||
|
{
|
||||||
|
"constants": [
|
||||||
|
"blue",
|
||||||
|
"yellow"
|
||||||
|
],
|
||||||
|
"display_name": "clanguml::t00036::ns1::E",
|
||||||
|
"id": "2144761953049158478",
|
||||||
|
"is_nested": false,
|
||||||
|
"name": "E",
|
||||||
|
"namespace": "clanguml::t00036::ns1",
|
||||||
|
"source_location": {
|
||||||
|
"file": "/home/bartek/devel/clang-uml/tests/t00036/t00036.cc",
|
||||||
|
"line": 6
|
||||||
|
},
|
||||||
|
"type": "enum"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"display_name": "clanguml::t00036::ns1::ns11",
|
||||||
|
"elements": [
|
||||||
|
{
|
||||||
|
"bases": [],
|
||||||
|
"display_name": "clanguml::t00036::ns1::ns11::A<T>",
|
||||||
|
"id": "571573305652194946",
|
||||||
|
"is_abstract": false,
|
||||||
|
"is_nested": false,
|
||||||
|
"is_struct": true,
|
||||||
|
"is_template": false,
|
||||||
|
"is_union": false,
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"access": "public",
|
||||||
|
"is_static": false,
|
||||||
|
"name": "a",
|
||||||
|
"source_location": {
|
||||||
|
"file": "/home/bartek/devel/clang-uml/tests/t00036/t00036.cc",
|
||||||
|
"line": 11
|
||||||
|
},
|
||||||
|
"type": "T"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"methods": [],
|
||||||
|
"name": "A",
|
||||||
|
"namespace": "clanguml::t00036::ns1::ns11",
|
||||||
|
"source_location": {
|
||||||
|
"file": "/home/bartek/devel/clang-uml/tests/t00036/t00036.cc",
|
||||||
|
"line": 10
|
||||||
|
},
|
||||||
|
"template_parameters": [
|
||||||
|
{
|
||||||
|
"is_template_parameter": true,
|
||||||
|
"is_template_template_parameter": false,
|
||||||
|
"is_variadic": false,
|
||||||
|
"name": "T",
|
||||||
|
"type": ""
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"type": "class"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"display_name": "clanguml::t00036::ns1::ns11::ns111",
|
||||||
|
"elements": [
|
||||||
|
{
|
||||||
|
"bases": [],
|
||||||
|
"display_name": "clanguml::t00036::ns1::ns11::ns111::B",
|
||||||
|
"id": "1964031933563607376",
|
||||||
|
"is_abstract": false,
|
||||||
|
"is_nested": false,
|
||||||
|
"is_struct": true,
|
||||||
|
"is_template": false,
|
||||||
|
"is_union": false,
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"access": "public",
|
||||||
|
"is_static": false,
|
||||||
|
"name": "a_int",
|
||||||
|
"source_location": {
|
||||||
|
"file": "/home/bartek/devel/clang-uml/tests/t00036/t00036.cc",
|
||||||
|
"line": 17
|
||||||
|
},
|
||||||
|
"type": "A<int>"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"methods": [],
|
||||||
|
"name": "B",
|
||||||
|
"namespace": "clanguml::t00036::ns1::ns11::ns111",
|
||||||
|
"source_location": {
|
||||||
|
"file": "/home/bartek/devel/clang-uml/tests/t00036/t00036.cc",
|
||||||
|
"line": 16
|
||||||
|
},
|
||||||
|
"template_parameters": [],
|
||||||
|
"type": "class"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "ns111",
|
||||||
|
"type": "namespace"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"bases": [],
|
||||||
|
"display_name": "clanguml::t00036::ns1::ns11::A<int>",
|
||||||
|
"id": "1832710427462319797",
|
||||||
|
"is_abstract": false,
|
||||||
|
"is_nested": false,
|
||||||
|
"is_struct": false,
|
||||||
|
"is_template": false,
|
||||||
|
"is_union": false,
|
||||||
|
"members": [],
|
||||||
|
"methods": [],
|
||||||
|
"name": "A",
|
||||||
|
"namespace": "clanguml::t00036::ns1::ns11",
|
||||||
|
"template_parameters": [
|
||||||
|
{
|
||||||
|
"is_template_parameter": false,
|
||||||
|
"is_template_template_parameter": false,
|
||||||
|
"is_variadic": false,
|
||||||
|
"name": "int",
|
||||||
|
"type": ""
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"type": "class"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "ns11",
|
||||||
|
"type": "namespace"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "ns1",
|
||||||
|
"type": "namespace"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"display_name": "clanguml::t00036::ns2",
|
||||||
|
"elements": [
|
||||||
|
{
|
||||||
|
"display_name": "clanguml::t00036::ns2::ns22",
|
||||||
|
"elements": [
|
||||||
|
{
|
||||||
|
"bases": [],
|
||||||
|
"display_name": "clanguml::t00036::ns2::ns22::C",
|
||||||
|
"id": "2038956882066165590",
|
||||||
|
"is_abstract": false,
|
||||||
|
"is_nested": false,
|
||||||
|
"is_struct": true,
|
||||||
|
"is_template": false,
|
||||||
|
"is_union": false,
|
||||||
|
"members": [],
|
||||||
|
"methods": [],
|
||||||
|
"name": "C",
|
||||||
|
"namespace": "clanguml::t00036::ns2::ns22",
|
||||||
|
"source_location": {
|
||||||
|
"file": "/home/bartek/devel/clang-uml/tests/t00036/t00036.cc",
|
||||||
|
"line": 28
|
||||||
|
},
|
||||||
|
"template_parameters": [],
|
||||||
|
"type": "class"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "ns22",
|
||||||
|
"type": "namespace"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "ns2",
|
||||||
|
"type": "namespace"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"relationships": [
|
||||||
|
{
|
||||||
|
"access": "public",
|
||||||
|
"destination": "1832710427462319797",
|
||||||
|
"label": "a_int",
|
||||||
|
"source": "1964031933563607376",
|
||||||
|
"type": "aggregation"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"access": "public",
|
||||||
|
"destination": "571573305652194946",
|
||||||
|
"source": "1832710427462319797",
|
||||||
|
"type": "instantiation"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
)##";
|
||||||
|
|
||||||
|
auto j = generate_class_json(diagram, *model);
|
||||||
|
|
||||||
|
REQUIRE(j == nlohmann::json::parse(expected_json));
|
||||||
|
|
||||||
|
save_json(config.output_directory() + "/" + diagram->name + ".json", j);
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -156,6 +156,20 @@ std::string generate_class_puml(
|
|||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nlohmann::json generate_class_json(
|
||||||
|
std::shared_ptr<clanguml::config::diagram> config,
|
||||||
|
clanguml::class_diagram::model::diagram &model)
|
||||||
|
{
|
||||||
|
using namespace clanguml::class_diagram::generators::json;
|
||||||
|
|
||||||
|
std::stringstream ss;
|
||||||
|
|
||||||
|
ss << generator(
|
||||||
|
dynamic_cast<clanguml::config::class_diagram &>(*config), model);
|
||||||
|
|
||||||
|
return nlohmann::json::parse(ss.str());
|
||||||
|
}
|
||||||
|
|
||||||
std::string generate_package_puml(
|
std::string generate_package_puml(
|
||||||
std::shared_ptr<clanguml::config::diagram> config,
|
std::shared_ptr<clanguml::config::diagram> config,
|
||||||
clanguml::package_diagram::model::diagram &model)
|
clanguml::package_diagram::model::diagram &model)
|
||||||
@@ -198,6 +212,16 @@ void save_puml(const std::string &path, const std::string &puml)
|
|||||||
ofs.close();
|
ofs.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void save_json(const std::string &path, const nlohmann::json &j)
|
||||||
|
{
|
||||||
|
std::filesystem::path p{path};
|
||||||
|
std::filesystem::create_directory(p.parent_path());
|
||||||
|
std::ofstream ofs;
|
||||||
|
ofs.open(p, std::ofstream::out | std::ofstream::trunc);
|
||||||
|
ofs << std::setw(2) << j;
|
||||||
|
ofs.close();
|
||||||
|
}
|
||||||
|
|
||||||
using namespace clanguml::test::matchers;
|
using namespace clanguml::test::matchers;
|
||||||
|
|
||||||
///
|
///
|
||||||
|
|||||||
Reference in New Issue
Block a user