diff --git a/tests/t20008/.clang-uml b/tests/t20008/.clang-uml new file mode 100644 index 00000000..f266305c --- /dev/null +++ b/tests/t20008/.clang-uml @@ -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()" \ No newline at end of file diff --git a/tests/t20008/t20008.cc b/tests/t20008/t20008.cc new file mode 100644 index 00000000..3305ade0 --- /dev/null +++ b/tests/t20008/t20008.cc @@ -0,0 +1,43 @@ +#include +#include + +namespace clanguml { +namespace t20008 +{ + +template struct A { + void a1(T arg) { } + void a2(T arg) { } + void a3(T arg) { } +}; + +template struct B { + A a; + + void b(T arg) { + if constexpr (std::is_integral_v) { + a.a1(arg); + } + else if constexpr(std::is_pointer_v) { + a.a2(arg); + } + else { + a.a3(arg); + } + + } +}; + +void tmain() { + using namespace std::string_literals; + + B bint; + B bcharp; + B bstring; + + bint.b(1); + bcharp.b("1"); + bstring.b("1"s); +} +} +} \ No newline at end of file diff --git a/tests/t20008/test_case.h b/tests/t20008/test_case.h new file mode 100644 index 00000000..221485e2 --- /dev/null +++ b/tests/t20008/test_case.h @@ -0,0 +1,53 @@ +/** + * tests/t20008/test_case.h + * + * Copyright (c) 2021-2022 Bartek Kryza + * + * 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"), "b")); + REQUIRE_THAT(puml, HasCall(_A("B"), _A("A"), "a1")); + REQUIRE_THAT(puml, !HasCall(_A("B"), _A("A"), "a2")); + REQUIRE_THAT(puml, !HasCall(_A("B"), _A("A"), "a3")); + + REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("B"), "b")); + REQUIRE_THAT( + puml, HasCall(_A("B"), _A("A"), "a2")); + + REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("B"), "b")); + REQUIRE_THAT( + puml, HasCall(_A("B"), _A("A"), "a3")); + + save_puml( + "./" + config.output_directory() + "/" + diagram->name + ".puml", puml); +} \ No newline at end of file diff --git a/tests/test_cases.cc b/tests/test_cases.cc index 51a822cf..74e7fe9a 100644 --- a/tests/test_cases.cc +++ b/tests/test_cases.cc @@ -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 diff --git a/tests/test_cases.h b/tests/test_cases.h index 90302891..caf6a7fa 100644 --- a/tests/test_cases.h +++ b/tests/test_cases.h @@ -79,26 +79,19 @@ template constexpr bool has_type() noexcept return (std::is_same_v || ... || 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); } } } diff --git a/tests/test_cases.yaml b/tests/test_cases.yaml index 115abd8a..38b74d48 100644 --- a/tests/test_cases.yaml +++ b/tests/test_cases.yaml @@ -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