Refactored method and field type rendering
This commit is contained in:
@@ -50,8 +50,8 @@ TEST_CASE("t00002", "[test-case][class]")
|
||||
REQUIRE_THAT(puml, IsBaseClass(_A("A"), _A("C")));
|
||||
REQUIRE_THAT(puml, IsBaseClass(_A("B"), _A("D")));
|
||||
REQUIRE_THAT(puml, IsBaseClass(_A("C"), _A("D")));
|
||||
REQUIRE_THAT(puml, IsMethod(Abstract(Public("foo_a"))));
|
||||
REQUIRE_THAT(puml, IsMethod(Abstract(Public("foo_c"))));
|
||||
REQUIRE_THAT(puml, (IsMethod<Public, Abstract>("foo_a")));
|
||||
REQUIRE_THAT(puml, (IsMethod<Public, Abstract>("foo_c")));
|
||||
|
||||
REQUIRE_THAT(puml, IsAssociation(_A("D"), _A("A"), "as"));
|
||||
|
||||
|
||||
@@ -45,23 +45,23 @@ TEST_CASE("t00003", "[test-case][class]")
|
||||
|
||||
REQUIRE_THAT(puml, !IsDependency(_A("A"), _A("A")));
|
||||
|
||||
REQUIRE_THAT(puml, IsMethod(Default(Public("A"))));
|
||||
REQUIRE_THAT(puml, IsMethod(Default(Public("~A"))));
|
||||
REQUIRE_THAT(puml, (IsMethod<Public, Default>("A")));
|
||||
REQUIRE_THAT(puml, (IsMethod<Public, Default>("~A")));
|
||||
|
||||
REQUIRE_THAT(puml, IsMethod(Public("basic_method")));
|
||||
REQUIRE_THAT(puml, IsMethod(Static(Public("int static_method"))));
|
||||
REQUIRE_THAT(puml, IsMethod(Const(Public("const_method"))));
|
||||
REQUIRE_THAT(puml, IsMethod(Protected("protected_method")));
|
||||
REQUIRE_THAT(puml, IsMethod(Private("private_method")));
|
||||
REQUIRE_THAT(puml, IsField(Public("int public_member")));
|
||||
REQUIRE_THAT(puml, IsField(Protected("int protected_member")));
|
||||
REQUIRE_THAT(puml, IsField(Private("int private_member")));
|
||||
REQUIRE_THAT(puml, (IsMethod<Public>("basic_method")));
|
||||
REQUIRE_THAT(puml, (IsMethod<Public, Static>("static_method", "int")));
|
||||
REQUIRE_THAT(puml, (IsMethod<Public, Const>("const_method")));
|
||||
REQUIRE_THAT(puml, (IsMethod<Protected>("protected_method")));
|
||||
REQUIRE_THAT(puml, (IsMethod<Private>("private_method")));
|
||||
REQUIRE_THAT(puml, (IsField<Public>("public_member", "int")));
|
||||
REQUIRE_THAT(puml, (IsField<Protected>("protected_member", "int")));
|
||||
REQUIRE_THAT(puml, (IsField<Private>("private_member", "int")));
|
||||
REQUIRE_THAT(
|
||||
puml, IsField(Static(Public("unsigned long const auto_member"))));
|
||||
puml, (IsField<Public, Static>("auto_member", "unsigned long const")));
|
||||
|
||||
REQUIRE_THAT(puml, IsField(Private("int a")));
|
||||
REQUIRE_THAT(puml, IsField(Private("int b")));
|
||||
REQUIRE_THAT(puml, IsField(Private("int c")));
|
||||
REQUIRE_THAT(puml, (IsField<Private>("a", "int")));
|
||||
REQUIRE_THAT(puml, (IsField<Private>("b", "int")));
|
||||
REQUIRE_THAT(puml, (IsField<Private>("c", "int")));
|
||||
|
||||
save_puml(
|
||||
"./" + config.output_directory + "/" + diagram->name + ".puml", puml);
|
||||
|
||||
@@ -50,8 +50,8 @@ TEST_CASE("t00004", "[test-case][class]")
|
||||
REQUIRE_THAT(puml, IsInnerClass(_A("A"), _A("AA")));
|
||||
REQUIRE_THAT(puml, IsInnerClass(_A("AA"), _A("AAA")));
|
||||
REQUIRE_THAT(puml, IsInnerClass(_A("AA"), "Lights"));
|
||||
REQUIRE_THAT(puml, IsMethod(Const(Public("foo"))));
|
||||
REQUIRE_THAT(puml, IsMethod(Const(Public("foo2"))));
|
||||
REQUIRE_THAT(puml, (IsMethod<Public, Const>("foo")));
|
||||
REQUIRE_THAT(puml, (IsMethod<Public, Const>("foo2")));
|
||||
|
||||
save_puml(
|
||||
"./" + config.output_directory + "/" + diagram->name + ".puml", puml);
|
||||
|
||||
@@ -57,9 +57,9 @@ TEST_CASE("t00005", "[test-case][class]")
|
||||
REQUIRE_THAT(puml, IsClass(_A("K")));
|
||||
REQUIRE_THAT(puml, IsClass(_A("R")));
|
||||
|
||||
REQUIRE_THAT(puml, IsField(Public("int some_int")));
|
||||
REQUIRE_THAT(puml, IsField(Public("int* some_int_pointer")));
|
||||
REQUIRE_THAT(puml, IsField(Public("int** some_int_pointer_pointer")));
|
||||
REQUIRE_THAT(puml, (IsField<Public>("some_int", "int")));
|
||||
REQUIRE_THAT(puml, (IsField<Public>("some_int_pointer", "int*")));
|
||||
REQUIRE_THAT(puml, (IsField<Public>("some_int_pointer_pointer", "int**")));
|
||||
|
||||
REQUIRE_THAT(puml, IsComposition(_A("R"), _A("A"), "a"));
|
||||
REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("B"), "b"));
|
||||
|
||||
@@ -48,14 +48,14 @@ TEST_CASE("t00008", "[test-case][class]")
|
||||
REQUIRE_THAT(puml, IsClassTemplate("A", "T,P,CMP,int N"));
|
||||
REQUIRE_THAT(puml, IsClassTemplate("B", "T,C<>"));
|
||||
|
||||
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")));
|
||||
REQUIRE_THAT(puml, IsField(Public("std::array<int,N> ints")));
|
||||
REQUIRE_THAT(puml, (IsField<Public>("value", "T")));
|
||||
REQUIRE_THAT(puml, (IsField<Public>("pointer", "T*")));
|
||||
REQUIRE_THAT(puml, (IsField<Public>("reference", "T&")));
|
||||
REQUIRE_THAT(puml, (IsField<Public>("values", "std::vector<P>")));
|
||||
REQUIRE_THAT(puml, (IsField<Public>("ints", "std::array<int,N>")));
|
||||
// TODO: add option to resolve using declared types
|
||||
// REQUIRE_THAT(puml, IsField(Public("bool (*)(int, int) comparator")));
|
||||
REQUIRE_THAT(puml, IsField(Public("CMP comparator")));
|
||||
REQUIRE_THAT(puml, (IsField<Public>("comparator", "CMP")));
|
||||
|
||||
save_puml(
|
||||
"./" + config.output_directory + "/" + diagram->name + ".puml", puml);
|
||||
|
||||
@@ -45,10 +45,11 @@ TEST_CASE("t00009", "[test-case][class]")
|
||||
REQUIRE_THAT(puml, IsClassTemplate("A", "T"));
|
||||
REQUIRE_THAT(puml, IsClass(_A("B")));
|
||||
|
||||
REQUIRE_THAT(puml, IsField(Public("T value")));
|
||||
REQUIRE_THAT(puml, IsField(Public("A<int> aint")));
|
||||
REQUIRE_THAT(puml, IsField(Public("A<std::string>* astring")));
|
||||
REQUIRE_THAT(puml, IsField(Public("A<std::vector<std::string>>& avector")));
|
||||
REQUIRE_THAT(puml, (IsField<Public>("value", "T")));
|
||||
REQUIRE_THAT(puml, (IsField<Public>("aint", "A<int>")));
|
||||
REQUIRE_THAT(puml, (IsField<Public>("astring", "A<std::string>*")));
|
||||
REQUIRE_THAT(
|
||||
puml, (IsField<Public>("avector", "A<std::vector<std::string>>&")));
|
||||
|
||||
REQUIRE_THAT(puml, IsInstantiation(_A("A<T>"), _A("A<int>")));
|
||||
REQUIRE_THAT(puml, IsInstantiation(_A("A<T>"), _A("A<std::string>")));
|
||||
|
||||
@@ -45,8 +45,8 @@ TEST_CASE("t00010", "[test-case][class]")
|
||||
REQUIRE_THAT(puml, IsClassTemplate("A", "T,P"));
|
||||
REQUIRE_THAT(puml, IsClassTemplate("B", "T"));
|
||||
|
||||
REQUIRE_THAT(puml, IsField(Public("A<T,std::string> astring")));
|
||||
REQUIRE_THAT(puml, IsField(Public("B<int> aintstring")));
|
||||
REQUIRE_THAT(puml, (IsField<Public>("astring", "A<T,std::string>")));
|
||||
REQUIRE_THAT(puml, (IsField<Public>("aintstring", "B<int>")));
|
||||
|
||||
REQUIRE_THAT(puml, IsInstantiation(_A("A<T,P>"), _A("A<T,std::string>")));
|
||||
REQUIRE_THAT(puml, IsInstantiation(_A("B<T>"), _A("B<int>")));
|
||||
|
||||
@@ -100,29 +100,7 @@ void save_puml(const std::string &path, const std::string &puml)
|
||||
ofs.close();
|
||||
}
|
||||
|
||||
using clanguml::test::matchers::Abstract;
|
||||
using clanguml::test::matchers::AliasMatcher;
|
||||
using clanguml::test::matchers::Const;
|
||||
using clanguml::test::matchers::Default;
|
||||
using clanguml::test::matchers::HasCall;
|
||||
using clanguml::test::matchers::HasCallWithResponse;
|
||||
using clanguml::test::matchers::IsAbstractClass;
|
||||
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::IsDependency;
|
||||
using clanguml::test::matchers::IsEnum;
|
||||
using clanguml::test::matchers::IsField;
|
||||
using clanguml::test::matchers::IsFriend;
|
||||
using clanguml::test::matchers::IsInnerClass;
|
||||
using clanguml::test::matchers::IsInstantiation;
|
||||
using clanguml::test::matchers::Private;
|
||||
using clanguml::test::matchers::Protected;
|
||||
using clanguml::test::matchers::Public;
|
||||
using clanguml::test::matchers::Static;
|
||||
using namespace clanguml::test::matchers;
|
||||
|
||||
//
|
||||
// Class diagram tests
|
||||
|
||||
@@ -74,81 +74,30 @@ using Catch::CaseSensitive;
|
||||
using Catch::Matchers::StdString::CasedString;
|
||||
using Catch::Matchers::StdString::ContainsMatcher;
|
||||
|
||||
template <typename T, typename... Ts> constexpr bool has_type() noexcept
|
||||
{
|
||||
return (std::is_same_v<T, Ts> || ... || false);
|
||||
}
|
||||
|
||||
struct Public {
|
||||
Public(std::string const &method)
|
||||
: m_method{method}
|
||||
{
|
||||
}
|
||||
|
||||
operator std::string() const { return "+" + m_method; }
|
||||
|
||||
std::string m_method;
|
||||
};
|
||||
|
||||
struct Protected {
|
||||
Protected(std::string const &method)
|
||||
: m_method{method}
|
||||
{
|
||||
}
|
||||
|
||||
operator std::string() const { return "#" + m_method; }
|
||||
|
||||
std::string m_method;
|
||||
};
|
||||
|
||||
struct Private {
|
||||
Private(std::string const &method)
|
||||
: m_method{method}
|
||||
{
|
||||
}
|
||||
|
||||
operator std::string() const { return "-" + m_method; }
|
||||
|
||||
std::string m_method;
|
||||
};
|
||||
|
||||
struct Abstract {
|
||||
Abstract(std::string const &method)
|
||||
: m_method{method}
|
||||
{
|
||||
}
|
||||
|
||||
operator std::string() const { return "{abstract} " + m_method; }
|
||||
|
||||
std::string m_method;
|
||||
};
|
||||
|
||||
struct Static {
|
||||
Static(std::string const &method)
|
||||
: m_method{method}
|
||||
{
|
||||
}
|
||||
|
||||
operator std::string() const { return "{static} " + m_method; }
|
||||
|
||||
std::string m_method;
|
||||
};
|
||||
|
||||
struct Const {
|
||||
Const(std::string const &method)
|
||||
: m_method{method}
|
||||
{
|
||||
}
|
||||
|
||||
operator std::string() const { return m_method; }
|
||||
|
||||
std::string m_method;
|
||||
};
|
||||
|
||||
struct Default {
|
||||
Default(std::string const &method)
|
||||
: m_method{method}
|
||||
{
|
||||
}
|
||||
|
||||
operator std::string() const { return m_method; }
|
||||
|
||||
std::string m_method;
|
||||
};
|
||||
|
||||
struct HasCallWithResultMatcher : ContainsMatcher {
|
||||
@@ -313,16 +262,60 @@ ContainsMatcher IsDependency(std::string const &from, std::string const &to,
|
||||
CasedString(fmt::format("{} ..> {}", from, to), caseSensitivity));
|
||||
}
|
||||
|
||||
template <typename... Ts>
|
||||
ContainsMatcher IsMethod(std::string const &name,
|
||||
std::string const &type = "void",
|
||||
CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes)
|
||||
{
|
||||
return ContainsMatcher(CasedString(name + "()", caseSensitivity));
|
||||
std::string pattern;
|
||||
if constexpr (has_type<Static, Ts...>())
|
||||
pattern += "{static} ";
|
||||
|
||||
if constexpr (has_type<Abstract, Ts...>())
|
||||
pattern += "{abstract} ";
|
||||
|
||||
if constexpr (has_type<Public, Ts...>())
|
||||
pattern = "+";
|
||||
else if constexpr (has_type<Protected, Ts...>())
|
||||
pattern = "#";
|
||||
else
|
||||
pattern = "-";
|
||||
|
||||
pattern += name;
|
||||
|
||||
pattern += "()";
|
||||
|
||||
if constexpr (has_type<Const, Ts...>())
|
||||
pattern += " const";
|
||||
|
||||
if constexpr (has_type<Abstract, Ts...>())
|
||||
pattern += " = 0";
|
||||
|
||||
pattern += " : " + type;
|
||||
|
||||
return ContainsMatcher(CasedString(pattern, caseSensitivity));
|
||||
}
|
||||
|
||||
template <typename... Ts>
|
||||
ContainsMatcher IsField(std::string const &name,
|
||||
std::string const &type = "void",
|
||||
CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes)
|
||||
{
|
||||
return ContainsMatcher(CasedString(name, caseSensitivity));
|
||||
std::string pattern;
|
||||
if constexpr (has_type<Static, Ts...>())
|
||||
pattern += "{static} ";
|
||||
|
||||
if constexpr (has_type<Public, Ts...>())
|
||||
pattern = "+";
|
||||
else if constexpr (has_type<Protected, Ts...>())
|
||||
pattern = "#";
|
||||
else
|
||||
pattern = "-";
|
||||
|
||||
pattern += name;
|
||||
|
||||
return ContainsMatcher(
|
||||
CasedString(pattern + " : " + type, caseSensitivity));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user