Added test case for relationships to std types
This commit is contained in:
@@ -253,6 +253,9 @@ void generator::generate(const class_ &c, nlohmann::json &parent) const
|
||||
object["display_name"] =
|
||||
common::generators::json::render_name(c.full_name_no_ns());
|
||||
|
||||
object["display_name"] =
|
||||
config().simplify_template_type(object["display_name"]);
|
||||
|
||||
for (auto &tp : object["template_parameters"]) {
|
||||
if (tp.contains("type") && tp.at("type").is_string()) {
|
||||
tp["type"] = config().using_namespace().relative(tp.at("type"));
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
namespace clanguml::class_diagram::generators::mermaid {
|
||||
|
||||
using clanguml::common::eid_t;
|
||||
using clanguml::common::generators::mermaid::escape_name;
|
||||
using clanguml::common::generators::mermaid::indent;
|
||||
using clanguml::common::generators::mermaid::render_name;
|
||||
|
||||
@@ -50,8 +51,8 @@ void generator::generate_alias(
|
||||
|
||||
auto class_label = config().simplify_template_type(render_name(full_name));
|
||||
|
||||
ostr << indent(1) << "class " << c.alias() << "[\"" << class_label
|
||||
<< "\"]\n";
|
||||
ostr << indent(1) << "class " << c.alias() << "[\""
|
||||
<< escape_name(class_label) << "\"]\n";
|
||||
|
||||
// Register the added alias
|
||||
m_generated_aliases.emplace(c.alias());
|
||||
@@ -257,7 +258,7 @@ void generator::generate_method(
|
||||
ostr << fmt::format("[{}] ", fmt::join(method_mods, ","));
|
||||
}
|
||||
|
||||
ostr << render_name(type);
|
||||
ostr << escape_name(render_name(type));
|
||||
|
||||
if (m.is_pure_virtual())
|
||||
ostr << "*";
|
||||
@@ -276,8 +277,8 @@ void generator::generate_member(
|
||||
|
||||
ostr << indent(2) << mermaid_common::to_mermaid(m.access()) << m.name()
|
||||
<< " : "
|
||||
<< render_name(
|
||||
uns.relative(config().simplify_template_type(m.type())));
|
||||
<< escape_name(uns.relative(
|
||||
config().simplify_template_type(render_name(m.type()))));
|
||||
}
|
||||
|
||||
void generator::generate(const concept_ &c, std::ostream &ostr) const
|
||||
@@ -294,7 +295,7 @@ void generator::generate(const concept_ &c, std::ostream &ostr) const
|
||||
parameters.reserve(c.requires_parameters().size());
|
||||
for (const auto &p : c.requires_parameters()) {
|
||||
parameters.emplace_back(
|
||||
render_name(p.to_string(config().using_namespace())));
|
||||
escape_name(p.to_string(config().using_namespace())));
|
||||
}
|
||||
|
||||
ostr << indent(2)
|
||||
@@ -302,7 +303,7 @@ void generator::generate(const concept_ &c, std::ostream &ostr) const
|
||||
|
||||
for (const auto &req : c.requires_statements()) {
|
||||
ostr << indent(2)
|
||||
<< fmt::format("\"{}\"\n", render_name(req, false));
|
||||
<< fmt::format("\"{}\"\n", escape_name(req, false));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +78,14 @@ std::string indent(const unsigned level)
|
||||
return std::string(level * kIndentWidth, ' '); // NOLINT
|
||||
}
|
||||
|
||||
std::string render_name(std::string name, bool round_brackets)
|
||||
std::string render_name(std::string name)
|
||||
{
|
||||
util::replace_all(name, "##", "::");
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
std::string escape_name(std::string name, bool round_brackets)
|
||||
{
|
||||
util::replace_all(name, "<", "<");
|
||||
util::replace_all(name, ">", ">");
|
||||
@@ -86,7 +93,6 @@ std::string render_name(std::string name, bool round_brackets)
|
||||
util::replace_all(name, "(", "(");
|
||||
util::replace_all(name, ")", ")");
|
||||
}
|
||||
util::replace_all(name, "##", "::");
|
||||
util::replace_all(name, "{", "{");
|
||||
util::replace_all(name, "}", "}");
|
||||
|
||||
|
||||
@@ -44,7 +44,8 @@ std::string to_mermaid(message_t r);
|
||||
|
||||
std::string indent(unsigned level);
|
||||
|
||||
std::string render_name(std::string name, bool round_brackets = true);
|
||||
std::string render_name(std::string name);
|
||||
std::string escape_name(std::string name, bool round_brackets = true);
|
||||
|
||||
/**
|
||||
* @brief Base class for diagram generators
|
||||
|
||||
25
tests/t00081/.clang-uml
Normal file
25
tests/t00081/.clang-uml
Normal file
@@ -0,0 +1,25 @@
|
||||
diagrams:
|
||||
t00081_class:
|
||||
type: class
|
||||
glob:
|
||||
- t00081.cc
|
||||
filter_mode: advanced
|
||||
include_system_headers: true
|
||||
include:
|
||||
allof:
|
||||
namespaces:
|
||||
- clanguml::t00081
|
||||
- std
|
||||
context:
|
||||
- match:
|
||||
radius: 2
|
||||
pattern: clanguml::t00081::A
|
||||
exclude:
|
||||
anyof:
|
||||
access:
|
||||
- private
|
||||
- public
|
||||
- protected
|
||||
relationships:
|
||||
- dependency
|
||||
using_namespace: clanguml::t00081
|
||||
18
tests/t00081/t00081.cc
Normal file
18
tests/t00081/t00081.cc
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace clanguml {
|
||||
namespace t00081_detail {
|
||||
struct C { };
|
||||
} // namespace t00081_detail
|
||||
namespace t00081 {
|
||||
struct A {
|
||||
std::vector<std::string> as;
|
||||
std::string s;
|
||||
std::map<std::string, std::string> ms;
|
||||
|
||||
t00081_detail::C *c;
|
||||
};
|
||||
} // namespace t00081
|
||||
} // namespace clanguml
|
||||
35
tests/t00081/test_case.h
Normal file
35
tests/t00081/test_case.h
Normal file
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* tests/t00081/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("t00081")
|
||||
{
|
||||
using namespace clanguml::test;
|
||||
using namespace std::string_literals;
|
||||
|
||||
auto [config, db, diagram, model] =
|
||||
CHECK_CLASS_MODEL("t00081", "t00081_class");
|
||||
|
||||
CHECK_CLASS_DIAGRAM(*config, diagram, *model, [](const auto &src) {
|
||||
REQUIRE(IsClass(src, "A"));
|
||||
REQUIRE(!IsClass(src, "C"));
|
||||
|
||||
REQUIRE(IsClass(src, "std::string"));
|
||||
REQUIRE(IsClass(src, "std::vector<std::string>"));
|
||||
REQUIRE(IsClass(src, "std::map<std::string,std::string>"));
|
||||
});
|
||||
}
|
||||
@@ -554,6 +554,7 @@ void CHECK_INCLUDE_DIAGRAM(const clanguml::config::config &config,
|
||||
#include "t00078/test_case.h"
|
||||
#include "t00079/test_case.h"
|
||||
#include "t00080/test_case.h"
|
||||
#include "t00081/test_case.h"
|
||||
|
||||
///
|
||||
/// Sequence diagram tests
|
||||
|
||||
@@ -237,6 +237,9 @@ test_cases:
|
||||
- name: t00080
|
||||
title: Test case for including elements from system headers
|
||||
description:
|
||||
- name: t00081
|
||||
title: Test case for class members relationships to std types
|
||||
description:
|
||||
Sequence diagrams:
|
||||
- name: t20001
|
||||
title: Basic sequence diagram test case
|
||||
|
||||
Reference in New Issue
Block a user