Added constexpr if sequence diagram test case
This commit is contained in:
14
tests/t20008/.clang-uml
Normal file
14
tests/t20008/.clang-uml
Normal file
@@ -0,0 +1,14 @@
|
||||
compilation_database_dir: ..
|
||||
output_directory: puml
|
||||
diagrams:
|
||||
t20008_sequence:
|
||||
type: sequence
|
||||
glob:
|
||||
- ../../tests/t20008/t20008.cc
|
||||
include:
|
||||
namespaces:
|
||||
- clanguml::t20008
|
||||
using_namespace:
|
||||
- clanguml::t20008
|
||||
start_from:
|
||||
- function: "clanguml::t20008::tmain()"
|
||||
43
tests/t20008/t20008.cc
Normal file
43
tests/t20008/t20008.cc
Normal file
@@ -0,0 +1,43 @@
|
||||
#include <type_traits>
|
||||
#include <string>
|
||||
|
||||
namespace clanguml {
|
||||
namespace t20008
|
||||
{
|
||||
|
||||
template <typename T> struct A {
|
||||
void a1(T arg) { }
|
||||
void a2(T arg) { }
|
||||
void a3(T arg) { }
|
||||
};
|
||||
|
||||
template <typename T> struct B {
|
||||
A<T> a;
|
||||
|
||||
void b(T arg) {
|
||||
if constexpr (std::is_integral_v<T>) {
|
||||
a.a1(arg);
|
||||
}
|
||||
else if constexpr(std::is_pointer_v<T>) {
|
||||
a.a2(arg);
|
||||
}
|
||||
else {
|
||||
a.a3(arg);
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
void tmain() {
|
||||
using namespace std::string_literals;
|
||||
|
||||
B<int> bint;
|
||||
B<const char*> bcharp;
|
||||
B<std::string> bstring;
|
||||
|
||||
bint.b(1);
|
||||
bcharp.b("1");
|
||||
bstring.b("1"s);
|
||||
}
|
||||
}
|
||||
}
|
||||
53
tests/t20008/test_case.h
Normal file
53
tests/t20008/test_case.h
Normal file
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* tests/t20008/test_case.h
|
||||
*
|
||||
* 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("t20008", "[test-case][sequence]")
|
||||
{
|
||||
auto [config, db] = load_config("t20008");
|
||||
|
||||
auto diagram = config.diagrams["t20008_sequence"];
|
||||
|
||||
REQUIRE(diagram->name == "t20008_sequence");
|
||||
|
||||
auto model = generate_sequence_diagram(*db, diagram);
|
||||
|
||||
REQUIRE(model->name() == "t20008_sequence");
|
||||
|
||||
auto puml = generate_sequence_puml(diagram, *model);
|
||||
AliasMatcher _A(puml);
|
||||
|
||||
REQUIRE_THAT(puml, StartsWith("@startuml"));
|
||||
REQUIRE_THAT(puml, EndsWith("@enduml\n"));
|
||||
|
||||
// Check if all calls exist
|
||||
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("B<int>"), "b"));
|
||||
REQUIRE_THAT(puml, HasCall(_A("B<int>"), _A("A<int>"), "a1"));
|
||||
REQUIRE_THAT(puml, !HasCall(_A("B<int>"), _A("A<int>"), "a2"));
|
||||
REQUIRE_THAT(puml, !HasCall(_A("B<int>"), _A("A<int>"), "a3"));
|
||||
|
||||
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("B<const char *>"), "b"));
|
||||
REQUIRE_THAT(
|
||||
puml, HasCall(_A("B<const char *>"), _A("A<const char *>"), "a2"));
|
||||
|
||||
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("B<std::string>"), "b"));
|
||||
REQUIRE_THAT(
|
||||
puml, HasCall(_A("B<std::string>"), _A("A<std::string>"), "a3"));
|
||||
|
||||
save_puml(
|
||||
"./" + config.output_directory() + "/" + diagram->name + ".puml", puml);
|
||||
}
|
||||
@@ -254,6 +254,7 @@ using namespace clanguml::test::matchers;
|
||||
#include "t20005/test_case.h"
|
||||
#include "t20006/test_case.h"
|
||||
#include "t20007/test_case.h"
|
||||
#include "t20008/test_case.h"
|
||||
|
||||
///
|
||||
/// Package diagram tests
|
||||
|
||||
@@ -79,26 +79,19 @@ template <typename T, typename... Ts> constexpr bool has_type() noexcept
|
||||
return (std::is_same_v<T, Ts> || ... || false);
|
||||
}
|
||||
|
||||
struct Public {
|
||||
};
|
||||
struct Public { };
|
||||
|
||||
struct Protected {
|
||||
};
|
||||
struct Protected { };
|
||||
|
||||
struct Private {
|
||||
};
|
||||
struct Private { };
|
||||
|
||||
struct Abstract {
|
||||
};
|
||||
struct Abstract { };
|
||||
|
||||
struct Static {
|
||||
};
|
||||
struct Static { };
|
||||
|
||||
struct Const {
|
||||
};
|
||||
struct Const { };
|
||||
|
||||
struct Default {
|
||||
};
|
||||
struct Default { };
|
||||
|
||||
struct HasCallWithResultMatcher : ContainsMatcher {
|
||||
HasCallWithResultMatcher(
|
||||
@@ -158,6 +151,8 @@ struct AliasMatcher {
|
||||
|
||||
util::replace_all(name, "(", "\\(");
|
||||
util::replace_all(name, ")", "\\)");
|
||||
util::replace_all(name, " ", "\\s");
|
||||
util::replace_all(name, "*", "\\*");
|
||||
|
||||
patterns.push_back(
|
||||
std::regex{"class\\s\"" + name + "\"\\sas\\s" + alias_regex});
|
||||
@@ -180,12 +175,11 @@ struct AliasMatcher {
|
||||
|
||||
for (const auto &line : puml) {
|
||||
for (const auto &pattern : patterns) {
|
||||
if (std::regex_search(line, base_match, pattern)) {
|
||||
if (base_match.size() == 2) {
|
||||
std::ssub_match base_sub_match = base_match[1];
|
||||
std::string alias = base_sub_match.str();
|
||||
return trim(alias);
|
||||
}
|
||||
if (std::regex_search(line, base_match, pattern) &&
|
||||
base_match.size() == 2) {
|
||||
std::ssub_match base_sub_match = base_match[1];
|
||||
std::string alias = base_sub_match.str();
|
||||
return trim(alias);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,6 +169,9 @@ test_cases:
|
||||
- name: t20007
|
||||
title: Class template variadic argument list sequence diagram
|
||||
description:
|
||||
- name: t20008
|
||||
title: Constexpr if sequence diagram test case
|
||||
description:
|
||||
Package diagrams:
|
||||
- name: t30001
|
||||
title: Basic package diagram test case
|
||||
|
||||
Reference in New Issue
Block a user