Added support for 'together' option in class diagrams without rendered namespaces

This commit is contained in:
Bartek Kryza
2023-02-04 00:23:51 +01:00
parent b910e9b02f
commit d7d80ab41e
14 changed files with 318 additions and 57 deletions

19
tests/t00053/.clang-uml Normal file
View File

@@ -0,0 +1,19 @@
compilation_database_dir: ..
output_directory: puml
diagrams:
t00053_class:
type: class
glob:
- ../../tests/t00053/t00053.cc
include:
namespaces:
- clanguml::t00053
using_namespace:
- clanguml::t00053
layout:
a:
- together: [c,e,f]
A:
- together: [C,E,F]
h:
- together: [j]

38
tests/t00053/t00053.cc Normal file
View File

@@ -0,0 +1,38 @@
namespace clanguml {
namespace t00053 {
struct a {
};
struct b {
};
struct c {
};
struct d {
};
struct e {
};
struct f {
};
struct g {
};
struct A {
};
struct B {
};
struct C {
};
struct D {
};
struct E {
};
struct F {
};
struct G {
};
enum class h { hhh };
enum class i { iii };
enum class j { jjj };
}
}

55
tests/t00053/test_case.h Normal file
View File

@@ -0,0 +1,55 @@
/**
* tests/t00053/test_case.h
*
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
TEST_CASE("t00053", "[test-case][class]")
{
auto [config, db] = load_config("t00053");
auto diagram = config.diagrams["t00053_class"];
REQUIRE(diagram->name == "t00053_class");
auto model = generate_class_diagram(*db, diagram);
REQUIRE(model->name() == "t00053_class");
auto puml = generate_class_puml(diagram, *model);
AliasMatcher _A(puml);
REQUIRE_THAT(puml, StartsWith("@startuml"));
REQUIRE_THAT(puml, EndsWith("@enduml\n"));
// Check if all classes exist
REQUIRE_THAT(puml, IsClass(_A("a")));
REQUIRE_THAT(puml, IsClass(_A("b")));
REQUIRE_THAT(puml, IsClass(_A("c")));
REQUIRE_THAT(puml, IsClass(_A("d")));
REQUIRE_THAT(puml, IsClass(_A("e")));
REQUIRE_THAT(puml, IsClass(_A("f")));
REQUIRE_THAT(puml, IsClass(_A("g")));
REQUIRE_THAT(puml, IsClass(_A("A")));
REQUIRE_THAT(puml, IsClass(_A("B")));
REQUIRE_THAT(puml, IsClass(_A("C")));
REQUIRE_THAT(puml, IsClass(_A("D")));
REQUIRE_THAT(puml, IsClass(_A("E")));
REQUIRE_THAT(puml, IsClass(_A("F")));
REQUIRE_THAT(puml, IsClass(_A("G")));
save_puml(config.output_directory() + "/" + diagram->name + ".puml", puml);
}

View File

@@ -246,6 +246,7 @@ using namespace clanguml::test::matchers;
#include "t00050/test_case.h"
#include "t00051/test_case.h"
#include "t00052/test_case.h"
#include "t00053/test_case.h"
///
/// Sequence diagram tests

View File

@@ -153,6 +153,9 @@ test_cases:
- name: t00052
title: Test case for template methods rendering
description:
- name: t00053
title: Test case for `together` layout hint
description:
Sequence diagrams:
- name: t20001
title: Basic sequence diagram test case

View File

@@ -150,6 +150,8 @@ TEST_CASE("Test config includes", "[unit-test]")
TEST_CASE("Test config layout", "[unit-test]")
{
using namespace std::string_literals;
auto cfg = clanguml::config::load("./test_config_data/layout.yml");
CHECK(cfg.diagrams.size() == 2);
@@ -157,35 +159,78 @@ TEST_CASE("Test config layout", "[unit-test]")
[[maybe_unused]] auto &def = static_cast<clanguml::config::class_diagram &>(
*cfg.diagrams["class_main"]);
auto check_layout = [](const auto &diagram,
const clanguml::common::model::diagram_t type) {
CHECK(diagram.type() == type);
auto check_class_layout =
[](const clanguml::config::class_diagram &diagram,
const clanguml::common::model::diagram_t type) {
CHECK(diagram.type() == type);
CHECK(diagram.layout().at("ABCD").size() == 2);
CHECK(diagram.layout().at("ABCD")[0].hint ==
clanguml::config::hint_t::up);
CHECK(diagram.layout().at("ABCD")[0].entity == "ABCD_SUBCLASS");
CHECK(diagram.layout().at("ABCD")[1].hint ==
clanguml::config::hint_t::left);
CHECK(diagram.layout().at("ABCD")[1].entity == "ABCD_SIBLING");
const auto &ABCD = diagram.layout().at("ABCD");
CHECK(diagram.layout().at("ABCD_SIBLING").size() == 2);
CHECK(diagram.layout().at("ABCD_SIBLING")[0].hint ==
clanguml::config::hint_t::right);
CHECK(diagram.layout().at("ABCD_SIBLING")[0].entity ==
"ABCD_OTHER_SIBLING");
CHECK(diagram.layout().at("ABCD_SIBLING")[1].hint ==
clanguml::config::hint_t::down);
CHECK(diagram.layout().at("ABCD_SIBLING")[1].entity ==
"ABCD_SIBLING_SIBLING");
};
CHECK(ABCD.size() == 3);
check_layout(static_cast<clanguml::config::class_diagram &>(
*cfg.diagrams["class_main"]),
CHECK(ABCD[0].hint == clanguml::config::hint_t::up);
CHECK(std::get<std::string>(ABCD[0].entity) == "ABCD_SUBCLASS");
CHECK(ABCD[1].hint == clanguml::config::hint_t::left);
CHECK(std::get<std::string>(ABCD[1].entity) == "ABCD_SIBLING");
CHECK(ABCD[2].hint == clanguml::config::hint_t::together);
CHECK(std::get<std::vector<std::string>>(ABCD[2].entity) ==
std::vector{"A"s, "B"s, "C"s, "D"s});
CHECK(diagram.get_together_group("ABCD").value() == "ABCD");
CHECK(
diagram.get_together_group("clanguml::ABCD").value() == "ABCD");
CHECK(diagram.get_together_group("B").value() == "ABCD");
CHECK(diagram.get_together_group("clanguml::B").value() == "ABCD");
CHECK(!diagram.get_together_group("clanguml::E"));
CHECK(!diagram.get_together_group("E"));
const auto &ABCD_SIBLING = diagram.layout().at("ABCD_SIBLING");
CHECK(ABCD_SIBLING.size() == 2);
CHECK(ABCD_SIBLING[0].hint == clanguml::config::hint_t::right);
CHECK(std::get<std::string>(ABCD_SIBLING[0].entity) ==
"ABCD_OTHER_SIBLING");
CHECK(ABCD_SIBLING[1].hint == clanguml::config::hint_t::down);
CHECK(std::get<std::string>(ABCD_SIBLING[1].entity) ==
"ABCD_SIBLING_SIBLING");
};
auto check_package_layout =
[](const clanguml::config::package_diagram &diagram,
const clanguml::common::model::diagram_t type) {
CHECK(diagram.type() == type);
const auto &ABCD = diagram.layout().at("ABCD");
CHECK(ABCD.size() == 2);
CHECK(ABCD[0].hint == clanguml::config::hint_t::up);
CHECK(std::get<std::string>(ABCD[0].entity) == "ABCD_SUBCLASS");
CHECK(ABCD[1].hint == clanguml::config::hint_t::left);
CHECK(std::get<std::string>(ABCD[1].entity) == "ABCD_SIBLING");
const auto &ABCD_SIBLING = diagram.layout().at("ABCD_SIBLING");
CHECK(ABCD_SIBLING.size() == 2);
CHECK(ABCD_SIBLING[0].hint == clanguml::config::hint_t::right);
CHECK(std::get<std::string>(ABCD_SIBLING[0].entity) ==
"ABCD_OTHER_SIBLING");
CHECK(ABCD_SIBLING[1].hint == clanguml::config::hint_t::down);
CHECK(std::get<std::string>(ABCD_SIBLING[1].entity) ==
"ABCD_SIBLING_SIBLING");
};
check_class_layout(static_cast<clanguml::config::class_diagram &>(
*cfg.diagrams["class_main"]),
clanguml::common::model::diagram_t::kClass);
check_layout(static_cast<clanguml::config::package_diagram &>(
*cfg.diagrams["package_main"]),
check_package_layout(static_cast<clanguml::config::package_diagram &>(
*cfg.diagrams["package_main"]),
clanguml::common::model::diagram_t::kPackage);
}

View File

@@ -13,6 +13,7 @@ diagrams:
ABCD:
- up: ABCD_SUBCLASS
- left: ABCD_SIBLING
- together: [A, B, C, D]
ABCD_SIBLING:
- right: ABCD_OTHER_SIBLING
- down: ABCD_SIBLING_SIBLING