Added initial class template handling

This commit is contained in:
Bartek Kryza
2021-03-06 12:12:35 +01:00
parent 5be5172bd3
commit e267d295f6
10 changed files with 180 additions and 12 deletions

12
tests/t00008/.clanguml Normal file
View File

@@ -0,0 +1,12 @@
compilation_database_dir: ..
output_directory: puml
diagrams:
t00008_class:
type: class
glob:
- ../../tests/t00008/t00008.cc
using_namespace:
- clanguml::t00008
include:
namespaces:
- clanguml::t00008

13
tests/t00008/t00008.cc Normal file
View File

@@ -0,0 +1,13 @@
#include <vector>
namespace clanguml {
namespace t00008 {
template <typename T, typename P = T> class A {
public:
T value;
T *pointer;
T &reference;
std::vector<P> values;
};
}
}

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

@@ -0,0 +1,55 @@
/**
* tests/t00008/test_case.cc
*
* Copyright (c) 2021 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("Test t00008", "[unit-test]")
{
spdlog::set_level(spdlog::level::debug);
auto [config, db] = load_config("t00008");
auto diagram = config.diagrams["t00008_class"];
REQUIRE(diagram->name == "t00008_class");
REQUIRE(diagram->include.namespaces.size() == 1);
REQUIRE_THAT(diagram->include.namespaces,
VectorContains(std::string{"clanguml::t00008"}));
REQUIRE(diagram->exclude.namespaces.size() == 0);
REQUIRE(diagram->should_include("clanguml::t00008::A"));
REQUIRE(diagram->should_include("clanguml::t00008::B"));
auto model = generate_class_diagram(db, diagram);
REQUIRE(model.name == "t00008_class");
auto puml = generate_class_puml(diagram, model);
REQUIRE_THAT(puml, StartsWith("@startuml"));
REQUIRE_THAT(puml, EndsWith("@enduml\n"));
REQUIRE_THAT(puml, IsClassTemplate("A", "T, P"));
REQUIRE_THAT(puml, IsField(Public("T value")));
REQUIRE_THAT(puml, IsField(Public("T * pointer")));
REQUIRE_THAT(puml, IsField(Public("T & reference")));
REQUIRE_THAT(puml, IsField(Public("std::vector<P> values")));
save_puml(
"./" + config.output_directory + "/" + diagram->name + ".puml", puml);
}

View File

@@ -100,6 +100,7 @@ using clanguml::test::matchers::IsAggregation;
using clanguml::test::matchers::IsAssociation;
using clanguml::test::matchers::IsBaseClass;
using clanguml::test::matchers::IsClass;
using clanguml::test::matchers::IsClassTemplate;
using clanguml::test::matchers::IsComposition;
using clanguml::test::matchers::IsEnum;
using clanguml::test::matchers::IsField;
@@ -116,3 +117,4 @@ using clanguml::test::matchers::Static;
#include "t00005/test_case.h"
#include "t00006/test_case.h"
#include "t00007/test_case.h"
#include "t00008/test_case.h"

View File

@@ -196,6 +196,14 @@ ContainsMatcher IsClass(std::string const &str,
return ContainsMatcher(CasedString("class " + str, caseSensitivity));
}
ContainsMatcher IsClassTemplate(std::string const &str,
std::string const &tmplt,
CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes)
{
return ContainsMatcher(
CasedString(fmt::format("class {}<{}>", str, tmplt), caseSensitivity));
}
ContainsMatcher IsEnum(std::string const &str,
CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes)
{