Added package diagram layout hints generation test case

This commit is contained in:
Bartek Kryza
2022-02-14 23:50:04 +01:00
parent db56949da3
commit 96c6851e52
5 changed files with 114 additions and 0 deletions

19
tests/t30007/.clang-uml Normal file
View File

@@ -0,0 +1,19 @@
compilation_database_dir: ..
output_directory: puml
diagrams:
t30007_package:
type: package
glob:
- ../../tests/t30007/t30007.cc
include:
namespaces:
- clanguml::t30007
using_namespace:
- clanguml::t30007
layout:
C:
- up: 'A::AA'
- left: B
plantuml:
before:
- "' t30007 test package diagram"

33
tests/t30007/t30007.cc Normal file
View File

@@ -0,0 +1,33 @@
namespace clanguml {
namespace t30007 {
namespace B {
struct BB {
};
}
/// \uml{note[top] Compare layout with t30006.}
namespace A {
namespace AA {
struct A1 {
B::BB *b;
};
}
}
namespace C {
struct CC {
};
}
/// \uml{note[bottom] Bottom A note.}
namespace A {
namespace AA {
struct A2 {
C::CC *c;
};
}
}
}
}

53
tests/t30007/test_case.h Normal file
View File

@@ -0,0 +1,53 @@
/**
* tests/t30007/test_case.cc
*
* Copyright (c) 2021-2022 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("t30007", "[test-case][package]")
{
auto [config, db] = load_config("t30007");
auto diagram = config.diagrams["t30007_package"];
REQUIRE(diagram->should_include("clanguml::t30007::A"));
REQUIRE(diagram->should_include("clanguml::t30007::C"));
REQUIRE(!diagram->should_include("std::vector"));
REQUIRE(diagram->name == "t30007_package");
auto model = generate_package_diagram(db, diagram);
REQUIRE(model.name() == "t30007_package");
auto puml = generate_package_puml(diagram, model);
AliasMatcher _A(puml);
REQUIRE_THAT(puml, StartsWith("@startuml"));
REQUIRE_THAT(puml, EndsWith("@enduml\n"));
REQUIRE_THAT(puml, IsPackage("A"));
REQUIRE_THAT(puml, IsPackage("B"));
REQUIRE_THAT(puml, IsPackage("C"));
REQUIRE_THAT(puml, IsDependency(_A("AA"), _A("B")));
REQUIRE_THAT(puml, IsDependency(_A("AA"), _A("C")));
REQUIRE_THAT(puml, IsLayoutHint(_A("C"), "up", _A("AA")));
REQUIRE_THAT(puml, IsLayoutHint(_A("C"), "left", _A("B")));
save_puml(
"./" + config.output_directory() + "/" + diagram->name + ".puml", puml);
}

View File

@@ -182,6 +182,7 @@ using namespace clanguml::test::matchers;
#include "t30004/test_case.h"
#include "t30005/test_case.h"
#include "t30006/test_case.h"
#include "t30007/test_case.h"
//
// Other tests (e.g. configuration file)

View File

@@ -351,6 +351,14 @@ ContainsMatcher IsDependency(std::string const &from, std::string const &to,
CasedString(fmt::format("{} ..> {}", from, to), caseSensitivity));
}
ContainsMatcher IsLayoutHint(std::string const &from, std::string const &hint,
std::string const &to,
CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes)
{
return ContainsMatcher(CasedString(
fmt::format("{} -[hidden]{}- {}", from, hint, to), caseSensitivity));
}
ContainsMatcher HasNote(std::string const &cls, std::string const &position,
std::string const &note,
CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes)