Added namespace deprecated attribute test case
This commit is contained in:
@@ -114,7 +114,11 @@ void generator::generate(const package &p, std::ostream &ostr) const
|
||||
{
|
||||
const auto uns = m_config.using_namespace;
|
||||
|
||||
ostr << "package [" << p.name() << "] as " << p.alias();
|
||||
ostr << "package [" << p.name() << "] ";
|
||||
ostr << "as " << p.alias();
|
||||
|
||||
if (p.is_deprecated())
|
||||
ostr << " <<deprecated>>";
|
||||
|
||||
if (!p.style().empty())
|
||||
ostr << " " << p.style();
|
||||
|
||||
@@ -47,4 +47,8 @@ bool operator==(const package &l, const package &r)
|
||||
{
|
||||
return l.full_name(false) == r.full_name(false);
|
||||
}
|
||||
|
||||
bool package::is_deprecated() const { return is_deprecated_; }
|
||||
|
||||
void package::set_deprecated(bool deprecated) { is_deprecated_ = deprecated; }
|
||||
}
|
||||
@@ -118,5 +118,11 @@ public:
|
||||
std::string full_name(bool relative) const override;
|
||||
|
||||
friend bool operator==(const package &l, const package &r);
|
||||
|
||||
bool is_deprecated() const;
|
||||
|
||||
void set_deprecated(bool deprecated);
|
||||
private:
|
||||
bool is_deprecated_{false};
|
||||
};
|
||||
}
|
||||
|
||||
@@ -106,6 +106,15 @@ void translation_unit_visitor::operator()(const cppast::cpp_entity &file)
|
||||
p->set_name(e.name());
|
||||
p->set_namespace(package_parent);
|
||||
|
||||
for (const auto &attr :
|
||||
ns_declaration.attributes()) {
|
||||
if (attr.kind() ==
|
||||
cppast::cpp_attribute_kind::deprecated) {
|
||||
p->set_deprecated(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ctx.diagram().add_package(
|
||||
package_parent, std::move(p));
|
||||
ctx.set_current_package(
|
||||
|
||||
15
tests/t30003/.clang-uml
Normal file
15
tests/t30003/.clang-uml
Normal file
@@ -0,0 +1,15 @@
|
||||
compilation_database_dir: ..
|
||||
output_directory: puml
|
||||
diagrams:
|
||||
t30003_package:
|
||||
type: package
|
||||
glob:
|
||||
- ../../tests/t30003/t30003.cc
|
||||
include:
|
||||
namespaces:
|
||||
- clanguml::t30003
|
||||
using_namespace:
|
||||
- clanguml::t30003
|
||||
plantuml:
|
||||
before:
|
||||
- "' t30003 test package diagram"
|
||||
32
tests/t30003/t30003.cc
Normal file
32
tests/t30003/t30003.cc
Normal file
@@ -0,0 +1,32 @@
|
||||
namespace clanguml {
|
||||
namespace t30003 {
|
||||
|
||||
namespace ns1 {
|
||||
namespace ns2_v1_0_0 {
|
||||
class A {
|
||||
};
|
||||
}
|
||||
|
||||
namespace [[deprecated]] ns2_v0_9_0 {
|
||||
class A {
|
||||
};
|
||||
}
|
||||
|
||||
namespace {
|
||||
class Anon final {
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
namespace [[deprecated]] ns3 {
|
||||
|
||||
namespace ns1::ns2 {
|
||||
class Anon : public t30003::ns1::ns2_v1_0_0::A {
|
||||
};
|
||||
}
|
||||
|
||||
class B : public ns1::ns2::Anon {
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
56
tests/t30003/test_case.h
Normal file
56
tests/t30003/test_case.h
Normal file
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* tests/t30003/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("t30003", "[test-case][package]")
|
||||
{
|
||||
auto [config, db] = load_config("t30003");
|
||||
|
||||
auto diagram = config.diagrams["t30003_package"];
|
||||
|
||||
REQUIRE(diagram->include.namespaces.size() == 1);
|
||||
REQUIRE_THAT(diagram->include.namespaces,
|
||||
VectorContains(std::string{"clanguml::t30003"}));
|
||||
|
||||
REQUIRE(diagram->should_include("clanguml::t30003::A"));
|
||||
REQUIRE(diagram->should_include("clanguml::t30003::C"));
|
||||
REQUIRE(!diagram->should_include("std::vector"));
|
||||
|
||||
REQUIRE(diagram->name == "t30003_package");
|
||||
|
||||
auto model = generate_package_diagram(db, diagram);
|
||||
|
||||
REQUIRE(model.name() == "t30003_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("ns1"));
|
||||
REQUIRE_THAT(puml, IsPackage("ns2"));
|
||||
REQUIRE_THAT(puml, IsPackage("ns3"));
|
||||
REQUIRE_THAT(puml, IsPackage("ns2_v1_0_0"));
|
||||
REQUIRE_THAT(puml, IsPackage("ns2_v0_9_0"));
|
||||
|
||||
REQUIRE_THAT(puml, IsDeprecated(_A("ns2_v0_9_0")));
|
||||
REQUIRE_THAT(puml, IsDeprecated(_A("ns3")));
|
||||
|
||||
save_puml(
|
||||
"./" + config.output_directory + "/" + diagram->name + ".puml", puml);
|
||||
}
|
||||
@@ -178,6 +178,7 @@ using namespace clanguml::test::matchers;
|
||||
//
|
||||
#include "t30001/test_case.h"
|
||||
#include "t30002/test_case.h"
|
||||
#include "t30003/test_case.h"
|
||||
|
||||
//
|
||||
// Other tests (e.g. configuration file)
|
||||
|
||||
@@ -421,6 +421,13 @@ ContainsMatcher IsPackage(std::string const &str,
|
||||
return ContainsMatcher(
|
||||
CasedString("package [" + str + "]", caseSensitivity));
|
||||
}
|
||||
|
||||
ContainsMatcher IsDeprecated(std::string const &str,
|
||||
CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes)
|
||||
{
|
||||
return ContainsMatcher(
|
||||
CasedString(str+" <<deprecated>> ", caseSensitivity));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user