Enabled type_aliases config option for sequence diagrams (#224)

This commit is contained in:
Bartek Kryza
2024-01-11 11:26:41 +01:00
parent 79971d67e8
commit 97719e46fc
15 changed files with 195 additions and 13 deletions

14
tests/t20039/.clang-uml Normal file
View File

@@ -0,0 +1,14 @@
diagrams:
t20039_sequence:
type: sequence
glob:
- t20039.cc
include:
namespaces:
- clanguml::t20039
using_namespace: clanguml::t20039
type_aliases:
"std::vector<int>": int_vec_t
"std::map<int,int>": int_map_t
from:
- function: "clanguml::t20039::tmain()"

34
tests/t20039/t20039.cc Normal file
View File

@@ -0,0 +1,34 @@
#include <map>
#include <string>
#include <vector>
namespace clanguml {
namespace t20039 {
template <typename T> struct A {
std::vector<std::vector<T>> a(T p) { return {}; }
};
struct R {
A<int> a_int;
A<std::vector<int>> a_intvec;
A<std::map<int, int>> a_intmap;
void run()
{
a_int.a({});
a_intvec.a({});
a_intmap.a({});
}
};
int tmain()
{
R r;
r.run();
return 0;
}
}
}

63
tests/t20039/test_case.h Normal file
View File

@@ -0,0 +1,63 @@
/**
* tests/t20039/test_case.h
*
* Copyright (c) 2021-2024 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("t20039", "[test-case][sequence]")
{
auto [config, db] = load_config("t20039");
auto diagram = config.diagrams["t20039_sequence"];
REQUIRE(diagram->name == "t20039_sequence");
auto model = generate_sequence_diagram(*db, diagram);
REQUIRE(model->name() == "t20039_sequence");
{
auto src = generate_sequence_puml(diagram, *model);
AliasMatcher _A(src);
REQUIRE_THAT(src, StartsWith("@startuml"));
REQUIRE_THAT(src, EndsWith("@enduml\n"));
// Check if all calls exist
REQUIRE_THAT(src, HasCall(_A("tmain()"), _A("R"), "run()"));
REQUIRE_THAT(src, HasCall(_A("R"), _A("A<int>"), "a(int)"));
REQUIRE_THAT(src, HasCall(_A("R"), _A("A<int_vec_t>"), "a(int_vec_t)"));
REQUIRE_THAT(src, HasCall(_A("R"), _A("A<int_map_t>"), "a(int_map_t)"));
save_puml(config.output_directory(), diagram->name + ".puml", src);
}
{
auto j = generate_sequence_json(diagram, *model);
using namespace json;
save_json(config.output_directory(), diagram->name + ".json", j);
}
{
auto src = generate_sequence_mermaid(diagram, *model);
mermaid::AliasMatcher _A(src);
using mermaid::IsClass;
save_mermaid(config.output_directory(), diagram->name + ".mmd", src);
}
}

View File

@@ -458,6 +458,7 @@ using namespace clanguml::test::matchers;
#include "t20036/test_case.h"
#include "t20037/test_case.h"
#include "t20038/test_case.h"
#include "t20039/test_case.h"
///
/// Package diagram tests

View File

@@ -328,6 +328,9 @@ test_cases:
- name: t20038
title: Sequence diagram comment decorator test case
description:
- name: t20039
title: Test case for type aliases config option in sequence diagrams
description:
Package diagrams:
- name: t30001
title: Basic package diagram test case

View File

@@ -410,6 +410,37 @@ TEST_CASE("Test config full clang uml dump", "[unit-test]")
CHECK(cfg.diagrams.size() == 32);
}
TEST_CASE("Test config type aliases", "[unit-test]")
{
auto cfg = clanguml::config::load("./test_config_data/type_aliases.yml");
CHECK(cfg.diagrams.size() == 2);
auto &def = *cfg.diagrams["class_diagram"];
CHECK(
def.simplify_template_type(
"ns1::ns2::container<ns2::key_t,ns2::value_t>") == "custom_map_t");
CHECK(def.simplify_template_type(
"ns1::ns2::container<ns1::ns2::key_t,std::string>") ==
"string_map_t");
CHECK(
def.simplify_template_type("std::basic_string<char>") == "std::string");
CHECK(def.simplify_template_type("std::basic_string<char32_t>") ==
"unicode_t");
def = *cfg.diagrams["sequence_diagram"];
CHECK(
def.simplify_template_type(
"ns1::ns2::container<ns2::key_t,ns2::value_t>") == "custom_map_t");
CHECK(def.simplify_template_type(
"ns1::ns2::Object::iterator<std::weak_ptr<Object> "
"*,std::vector<std::weak_ptr<Object>,std::allocator<std::weak_"
"ptr<Object>>>>") == "ObjectPtrIt");
CHECK(
def.simplify_template_type("std::basic_string<char>") == "std::string");
CHECK(def.simplify_template_type("std::vector<std::basic_string<char>>") ==
"std::vector<std::string>");
}
///
/// Main test function
///

View File

@@ -0,0 +1,17 @@
type_aliases:
"ns1::ns2::container<ns2::key_t,ns2::value_t>": custom_map_t
diagrams:
class_diagram:
type: class
glob:
- test.cc
type_aliases:
"ns1::ns2::container<ns1::ns2::key_t,std::string>": string_map_t
"std::basic_string<char32_t>": unicode_t
sequence_diagram:
type: class
relative_to: .
glob:
- test.cc
type_aliases:
"ns1::ns2::Object::iterator<std::weak_ptr<Object> *,std::vector<std::weak_ptr<Object>,std::allocator<std::weak_ptr<Object>>>>": "ObjectPtrIt"