Extended generation of method attributes (#142)

This commit is contained in:
Bartek Kryza
2023-05-29 23:19:28 +02:00
parent 75b900bf46
commit 097f7a11ed
13 changed files with 158 additions and 11 deletions

View File

@@ -12,7 +12,7 @@ public:
{
}
A(A &&) = default;
A(const A &) = default;
A(const A &) = delete;
virtual ~A() = default;
void basic_method() { }
@@ -20,6 +20,17 @@ public:
void const_method() const { }
auto auto_method() { return 1; }
A &operator++()
{
private_member++;
return *this;
}
A &operator=(A &&other) noexcept { return *this; }
A &operator=(A &other) noexcept { return *this; }
constexpr std::size_t size() const { return private_member; }
auto double_int(const int i) { return 2 * i; }
auto sum(const double a, const double b) { return a_ + b_ + c_; }

View File

@@ -44,6 +44,10 @@ TEST_CASE("t00003", "[test-case][class]")
REQUIRE_THAT(puml, !IsDependency(_A("A"), _A("A")));
REQUIRE_THAT(puml, (IsMethod<Public, Default>("A")));
REQUIRE_THAT(puml, (IsMethod<Public, Default>("A", "void", "A &&")));
REQUIRE_THAT(
puml, (IsMethod<Public, Deleted>("A", "void", "const A &")));
REQUIRE_THAT(puml, (IsMethod<Public, Default>("~A")));
REQUIRE_THAT(puml, (IsMethod<Public>("basic_method")));
@@ -55,6 +59,9 @@ TEST_CASE("t00003", "[test-case][class]")
(IsMethod<Public>("default_string", "std::string",
"int i, std::string s = \"abc\"")));
REQUIRE_THAT(
puml, (IsMethod<Public, Const, Constexpr>("size", "std::size_t")));
REQUIRE_THAT(puml, (IsMethod<Protected>("protected_method")));
REQUIRE_THAT(puml, (IsMethod<Private>("private_method")));
REQUIRE_THAT(puml, (IsField<Public>("public_member", "int")));

View File

@@ -45,7 +45,7 @@ TEST_CASE("t00051", "[test-case][class]")
"Function && f, Args &&... args")));
REQUIRE_THAT(puml,
(IsMethod<Public>("thread", "void",
"(lambda at ../../tests/t00051/t00051.cc:59:27) && ")));
"(lambda at ../../tests/t00051/t00051.cc:59:27) &&")));
REQUIRE_THAT(puml,
(IsMethod<Private>("start_thread3",
"B<(lambda at ../../tests/t00051/t00051.cc:43:18),(lambda at "

View File

@@ -68,12 +68,14 @@ TEST_CASE("t00064", "[test-case][class]")
REQUIRE_THAT(puml,
(IsMethod<Public>("getp", "value_type const*", "unsigned int i")));
REQUIRE_THAT(puml,
(IsMethod<Public>("find", "unsigned int", "value_type const& v")));
(IsMethod<Public, Constexpr>(
"find", "unsigned int", "value_type const& v")));
#else
REQUIRE_THAT(puml,
(IsMethod<Public>("getp", "const value_type *", "unsigned int i")));
REQUIRE_THAT(puml,
(IsMethod<Public>("find", "unsigned int", "const value_type & v")));
(IsMethod<Public, Constexpr>(
"find", "unsigned int", "const value_type & v")));
#endif
save_puml(

View File

@@ -103,8 +103,16 @@ struct Static { };
struct Const { };
struct Constexpr { };
struct Consteval { };
struct Noexcept { };
struct Default { };
struct Deleted { };
struct HasCallWithResultMatcher : ContainsMatcher {
HasCallWithResultMatcher(
CasedString const &comparator, CasedString const &resultComparator)
@@ -530,6 +538,12 @@ ContainsMatcher IsMethod(std::string const &name,
pattern += "(" + params + ")";
if constexpr (has_type<Constexpr, Ts...>())
pattern += " constexpr";
if constexpr (has_type<Consteval, Ts...>())
pattern += " consteval";
if constexpr (has_type<Const, Ts...>())
pattern += " const";
@@ -539,6 +553,9 @@ ContainsMatcher IsMethod(std::string const &name,
if constexpr (has_type<Default, Ts...>())
pattern += " = default";
if constexpr (has_type<Deleted, Ts...>())
pattern += " = deleted";
pattern += " : " + type;
return ContainsMatcher(CasedString(pattern, caseSensitivity));

View File

@@ -4,7 +4,7 @@ test_cases:
title: Basic class inheritance
description:
- name: t00003
title: Class field and methods
title: Class fields and methods
description:
- name: t00004
title: Nested classes and enums