From 75d1daac310c92e43d8a897cdb7db4aad61e4a3c Mon Sep 17 00:00:00 2001 From: Bartek Kryza Date: Fri, 2 Jun 2023 21:39:25 +0200 Subject: [PATCH] Updated diagram filters test cases and docs --- CHANGELOG.md | 4 +++ docs/diagram_filters.md | 22 ++++++++++++ src/common/model/diagram_filter.cc | 2 +- tests/test_config_data/filters.yml | 14 +++++++- tests/test_filters.cc | 54 +++++++++++++++++++++++++++++- 5 files changed, 93 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e3fcbfe3..1394dcf8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG + * Added method type diagram filter (#145) + * Added default method grouping and sorting in class diagrams (#36) + * Improved generation of method attributes (e.g. constexpr, noexcept) (#142) + ### 0.3.6 * Added generation of packages in class and package diagrams from filesystem directories (#144) diff --git a/docs/diagram_filters.md b/docs/diagram_filters.md index 860888f4..c1e80dad 100644 --- a/docs/diagram_filters.md +++ b/docs/diagram_filters.md @@ -131,6 +131,28 @@ This filter allows to include or exclude all parents (base classes) of a given c This filter allows to include or exclude specializations and instantiations of a specific template from the diagram. +## `access` + +This filter allows to include or exclude class methods and members based on their access scope, allowed values are: + + * `public` + * `protected` + * `private` + +## `method_types` + +This filter allows to include or exclude various method types from the class diagram, allowed values are: + * constructor + * destructor + * assignment + * operator + * defaulted + * deleted + * static + +This filter is independent of the `access` filter, which controls which methods +are included based on access scope (e.g. `public`). + ## `dependants` and `dependencies` These filters allow to specify that only dependants or dependencies of a given class should be included in the diagram. diff --git a/src/common/model/diagram_filter.cc b/src/common/model/diagram_filter.cc index 7926ce03..2ff3801c 100644 --- a/src/common/model/diagram_filter.cc +++ b/src/common/model/diagram_filter.cc @@ -256,7 +256,7 @@ method_type_filter::method_type_filter( } tvl::value_t method_type_filter::match( - const diagram &d, const class_diagram::model::class_method &m) const + const diagram & /*d*/, const class_diagram::model::class_method &m) const { return tvl::any_of( method_types_.begin(), method_types_.end(), [&m](auto mt) { diff --git a/tests/test_config_data/filters.yml b/tests/test_config_data/filters.yml index 478892c3..1ebea071 100644 --- a/tests/test_config_data/filters.yml +++ b/tests/test_config_data/filters.yml @@ -17,4 +17,16 @@ diagrams: exclude: paths: - sequence_diagram - - util/error.h \ No newline at end of file + - util/error.h + method_type_include_test: + type: class + include: + method_types: + - constructor + - operator + method_type_exclude_test: + type: class + exclude: + method_types: + - deleted + - destructor \ No newline at end of file diff --git a/tests/test_filters.cc b/tests/test_filters.cc index 7caea613..4f1764ba 100644 --- a/tests/test_filters.cc +++ b/tests/test_filters.cc @@ -34,7 +34,6 @@ TEST_CASE("Test diagram paths filter", "[unit-test]") auto cfg = clanguml::config::load("./test_config_data/filters.yml"); - CHECK(cfg.diagrams.size() == 1); auto &config = *cfg.diagrams["include_test"]; clanguml::include_diagram::model::diagram diagram; @@ -52,3 +51,56 @@ TEST_CASE("Test diagram paths filter", "[unit-test]") CHECK_FALSE(filter.should_include( make_path("sequence_diagram/visitor/translation_unit_visitor.h"))); } + +TEST_CASE("Test method_types include filter", "[unit-test]") +{ + using clanguml::class_diagram::model::class_method; + using clanguml::common::model::access_t; + using clanguml::common::model::diagram_filter; + using clanguml::common::model::source_file; + + auto cfg = clanguml::config::load("./test_config_data/filters.yml"); + + auto &config = *cfg.diagrams["method_type_include_test"]; + clanguml::class_diagram::model::diagram diagram; + + diagram_filter filter(diagram, config); + + class_method cm{access_t::kPublic, "A", ""}; + cm.is_constructor(true); + + CHECK(filter.should_include(cm)); + + cm.is_constructor(false); + cm.is_destructor(true); + + CHECK(!filter.should_include(cm)); +} + +TEST_CASE("Test method_types exclude filter", "[unit-test]") +{ + using clanguml::class_diagram::model::class_method; + using clanguml::common::model::access_t; + using clanguml::common::model::diagram_filter; + using clanguml::common::model::source_file; + + auto cfg = clanguml::config::load("./test_config_data/filters.yml"); + + auto &config = *cfg.diagrams["method_type_exclude_test"]; + clanguml::class_diagram::model::diagram diagram; + + diagram_filter filter(diagram, config); + + class_method cm{access_t::kPublic, "A", ""}; + + CHECK(filter.should_include(cm)); + + cm.is_constructor(true); + + CHECK(filter.should_include(cm)); + + cm.is_constructor(false); + cm.is_destructor(true); + + CHECK(!filter.should_include(cm)); +} \ No newline at end of file