diff --git a/tests/t20047/.clang-uml b/tests/t20047/.clang-uml new file mode 100644 index 00000000..3cb8298f --- /dev/null +++ b/tests/t20047/.clang-uml @@ -0,0 +1,13 @@ +add_compile_flags: + - -fparse-all-comments +diagrams: + t20047_sequence: + type: sequence + glob: + - t20047.cc + include: + namespaces: + - clanguml::t20047 + using_namespace: clanguml::t20047 + from: + - function: "clanguml::t20047::tmain()" \ No newline at end of file diff --git a/tests/t20047/t20047.cc b/tests/t20047/t20047.cc new file mode 100644 index 00000000..4444c54d --- /dev/null +++ b/tests/t20047/t20047.cc @@ -0,0 +1,42 @@ +#include + +namespace clanguml { +namespace t20047 { + +int a1(int x) { return x + 1; } + +int a2(int x) { return x + 2; } + +int a3(int x) { return x + 3; } + +int a4(int x) { return x + 4; } + +int a5(int x) { return x + 5; } + +int a6(int x) { return x + 6; } + +int run(int (*f)(int), int arg) { return f(arg); } + +int tmain() +{ + auto res = + // \uml{call clanguml::t20047::a1(int)} + run(a1, 0); + + res = a3( + // \uml{call clanguml::t20047::a2(int)} + run(a2, 0)); + + // \uml{call clanguml::t20047::a4(int)} + res = [](auto &&x) { return a4(x); }(0); + + // \uml{call clanguml::t20047::a5(int)} + res = std::async(a5, 10).get(); + + // \uml{call clanguml::t20047::a6(int)} + res = [](auto &&x) { return std::async(run, a6, x).get(); }(1); + + return res; +} +} +} \ No newline at end of file diff --git a/tests/t20047/test_case.h b/tests/t20047/test_case.h new file mode 100644 index 00000000..3643c2db --- /dev/null +++ b/tests/t20047/test_case.h @@ -0,0 +1,65 @@ +/** + * tests/t20047/test_case.h + * + * Copyright (c) 2021-2024 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("t20047", "[test-case][sequence]") +{ + auto [config, db] = load_config("t20047"); + + auto diagram = config.diagrams["t20047_sequence"]; + + REQUIRE(diagram->name == "t20047_sequence"); + + auto model = generate_sequence_diagram(*db, diagram); + + REQUIRE(model->name() == "t20047_sequence"); + + { + auto src = generate_sequence_puml(diagram, *model); + AliasMatcher _A(src); + + REQUIRE_THAT(src, StartsWith("@startuml")); + REQUIRE_THAT(src, EndsWith("@enduml\n")); + + // Check if all calls exist + REQUIRE_THAT(src, HasCall(_A("tmain()"), _A("a1(int)"), "")); + REQUIRE_THAT(src, HasCall(_A("tmain()"), _A("a2(int)"), "")); + REQUIRE_THAT(src, HasCall(_A("tmain()"), _A("a3(int)"), "")); + REQUIRE_THAT(src, HasCall(_A("tmain()"), _A("a4(int)"), "")); + REQUIRE_THAT(src, HasCall(_A("tmain()"), _A("a5(int)"), "")); + REQUIRE_THAT(src, HasCall(_A("tmain()"), _A("a6(int)"), "")); + + save_puml(config.output_directory(), diagram->name + ".puml", src); + } + + { + auto j = generate_sequence_json(diagram, *model); + + using namespace json; + + save_json(config.output_directory(), diagram->name + ".json", j); + } + + { + auto src = generate_sequence_mermaid(diagram, *model); + + mermaid::AliasMatcher _A(src); + using mermaid::IsClass; + + save_mermaid(config.output_directory(), diagram->name + ".mmd", src); + } +} \ No newline at end of file diff --git a/tests/test_cases.cc b/tests/test_cases.cc index 3253c6ae..cb715570 100644 --- a/tests/test_cases.cc +++ b/tests/test_cases.cc @@ -473,6 +473,7 @@ using namespace clanguml::test::matchers; #include "t20044/test_case.h" #include "t20045/test_case.h" #include "t20046/test_case.h" +#include "t20047/test_case.h" /// /// Package diagram tests diff --git a/tests/test_cases.yaml b/tests/test_cases.yaml index a2675040..a9f7954e 100644 --- a/tests/test_cases.yaml +++ b/tests/test_cases.yaml @@ -361,6 +361,9 @@ test_cases: - name: t20046 title: Test case for call expressions in nested lambdas description: + - name: t20047 + title: Test case for 'call' comment directive + description: Package diagrams: - name: t30001 title: Basic package diagram test case