From 6fed330f6751277e0da450477f22ffa7e47ac84d Mon Sep 17 00:00:00 2001 From: Bartek Kryza Date: Mon, 25 Apr 2022 23:52:39 +0200 Subject: [PATCH] Fixed plantuml config option inheritance --- src/common/model/enums.h | 3 +-- src/config/config.cc | 23 ------------------ src/config/option.h | 17 +++++++++----- tests/test_config.cc | 35 ++++++++++++++++++++++++++++ tests/test_config_data/inherited.yml | 12 ++++++++-- tests/test_config_data/simple.yml | 19 ++++++++++++++- 6 files changed, 75 insertions(+), 34 deletions(-) diff --git a/src/common/model/enums.h b/src/common/model/enums.h index 650ff2bf..7c2501c2 100644 --- a/src/common/model/enums.h +++ b/src/common/model/enums.h @@ -35,8 +35,7 @@ enum class relationship_t { kAssociation, kInstantiation, kFriendship, - kDependency, - kInclusion + kDependency }; enum class message_t { kCall, kReturn }; diff --git a/src/config/config.cc b/src/config/config.cc index caa189fb..ba1f2b30 100644 --- a/src/config/config.cc +++ b/src/config/config.cc @@ -105,22 +105,6 @@ common::model::diagram_t class_diagram::type() const return common::model::diagram_t::kClass; } -bool class_diagram::has_class(std::string clazz) -{ - for (const auto &c : classes()) { - for (const auto &ns : using_namespace()) { - std::string prefix{}; - if (!ns.empty()) { - prefix = ns + "::"; - } - if (prefix + c == clazz) - return true; - } - } - - return false; -} - common::model::diagram_t sequence_diagram::type() const { return common::model::diagram_t::kSequence; @@ -136,13 +120,6 @@ common::model::diagram_t include_diagram::type() const return common::model::diagram_t::kInclude; } -template <> -void append_value>( - std::vector &l, const std::vector &r) -{ - l.insert(l.end(), r.begin(), r.end()); -} - template <> void append_value(plantuml &l, const plantuml &r) { l.append(r); diff --git a/src/config/option.h b/src/config/option.h index 52ad9ffb..d0232472 100644 --- a/src/config/option.h +++ b/src/config/option.h @@ -17,6 +17,8 @@ */ #pragma once +#include + namespace clanguml { namespace config { @@ -29,6 +31,7 @@ template struct option { option_inherit_mode im = option_inherit_mode::kOverride) : name{name_} , value{} + , inheritance_mode{im} { } option(const std::string &name_, const T &initial_value, @@ -36,6 +39,7 @@ template struct option { : name{name_} , value{initial_value} , has_value{true} + , inheritance_mode{im} { } @@ -48,12 +52,13 @@ template struct option { void override(const option &o) { - if (!is_declared && o.is_declared) { - if (inheritance_mode == option_inherit_mode::kAppend) - append_value(value, o.value); - else - value = o.value; - + if (o.is_declared && inheritance_mode == option_inherit_mode::kAppend) { + append_value(value, o.value); + is_declared = true; + has_value = true; + } + else if (!is_declared && o.is_declared) { + value = o.value; is_declared = true; has_value = true; } diff --git a/tests/test_config.cc b/tests/test_config.cc index 58266156..d4316568 100644 --- a/tests/test_config.cc +++ b/tests/test_config.cc @@ -24,6 +24,10 @@ TEST_CASE("Test config simple", "[unit-test]") { + using clanguml::common::model::access_t; + using clanguml::common::model::relationship_t; + using clanguml::util::contains; + auto cfg = clanguml::config::load("./test_config_data/simple.yml"); CHECK(cfg.diagrams.size() == 1); @@ -39,6 +43,31 @@ TEST_CASE("Test config simple", "[unit-test]") "https://github.com/bkryza/clang-uml/blob/{{ git.branch }}/{{ " "element.source.file }}#L{{ element.source.line }}"); CHECK(diagram.generate_links().tooltip == "{{ element.comment }}"); + + CHECK(contains(diagram.include().access, access_t::kPublic)); + CHECK(contains(diagram.include().access, access_t::kProtected)); + CHECK(contains(diagram.include().access, access_t::kPrivate)); + + CHECK( + contains(diagram.include().relationships, relationship_t::kExtension)); + CHECK(contains( + diagram.include().relationships, relationship_t::kAggregation)); + CHECK(contains( + diagram.include().relationships, relationship_t::kAssociation)); + CHECK(contains( + diagram.include().relationships, relationship_t::kComposition)); + CHECK(contains( + diagram.include().relationships, relationship_t::kContainment)); + CHECK( + contains(diagram.include().relationships, relationship_t::kDependency)); + CHECK( + contains(diagram.include().relationships, relationship_t::kFriendship)); + CHECK(contains( + diagram.include().relationships, relationship_t::kInstantiation)); + CHECK( + contains(diagram.include().relationships, relationship_t::kOwnership)); + + CHECK(contains(diagram.exclude().relationships, relationship_t::kNone)); } TEST_CASE("Test config inherited", "[unit-test]") @@ -63,6 +92,12 @@ TEST_CASE("Test config inherited", "[unit-test]") CHECK(cus.include_relations_also_as_members()); CHECK(cus.generate_packages() == false); CHECK(cus.generate_links == false); + CHECK(cus.puml().before.size() == 2); + CHECK(cus.puml().before.at(0) == "title This is diagram A"); + CHECK(cus.puml().before.at(1) == "This is a common header"); + CHECK(cus.puml().after.size() == 2); + CHECK(cus.puml().after.at(0) == "note left of A: This is a note"); + CHECK(cus.puml().after.at(1) == "This is a common footnote"); } TEST_CASE("Test config includes", "[unit-test]") diff --git a/tests/test_config_data/inherited.yml b/tests/test_config_data/inherited.yml index 9caf9585..c205e7c5 100644 --- a/tests/test_config_data/inherited.yml +++ b/tests/test_config_data/inherited.yml @@ -10,7 +10,11 @@ include: glob: - src/**/*.cc - src/**/*.h - +plantuml: + before: + - This is a common header + after: + - This is a common footnote diagrams: class_default: type: class @@ -21,4 +25,8 @@ diagrams: include_relations_also_as_members: true glob: - src/main.cc - + plantuml: + before: + - title This is diagram A + after: + - "note left of A: This is a note" \ No newline at end of file diff --git a/tests/test_config_data/simple.yml b/tests/test_config_data/simple.yml index 8e6d10a8..d6a44955 100644 --- a/tests/test_config_data/simple.yml +++ b/tests/test_config_data/simple.yml @@ -16,4 +16,21 @@ diagrams: include: namespaces: - clanguml - - ABCD \ No newline at end of file + - ABCD + access: + - public + - protected + - private + relationships: + - inheritance + - composition + - aggregation + - containment + - ownership + - association + - instantiation + - friendship + - dependency + exclude: + relationships: + - none \ No newline at end of file