Added support for ternary conditional operator in sequence diagrams

This commit is contained in:
Bartek Kryza
2022-12-14 23:58:38 +01:00
parent 0d15d09de2
commit 1a82e46d7d
14 changed files with 232 additions and 0 deletions

17
tests/t20028/.clang-uml Normal file
View File

@@ -0,0 +1,17 @@
compilation_database_dir: ..
output_directory: puml
diagrams:
t20028_sequence:
type: sequence
glob:
- ../../tests/t20028/t20028.cc
include:
namespaces:
- clanguml::t20028
exclude:
namespaces:
- clanguml::t20028::detail
using_namespace:
- clanguml::t20028
start_from:
- function: "clanguml::t20028::tmain()"

31
tests/t20028/t20028.cc Normal file
View File

@@ -0,0 +1,31 @@
namespace clanguml {
namespace t20028 {
struct A {
int a() { return 0; }
int b() { return 1; }
int c() { return 2; }
int d() { return 3; }
};
namespace detail {
struct B {
int e() { return 4; }
};
} // namespace detail
int tmain()
{
A a;
detail::B b;
int result{};
result = b.e() ? b.e() : 12;
result += a.a() ? a.b() + a.c() : a.d();
return result;
}
}
}

46
tests/t20028/test_case.h Normal file
View File

@@ -0,0 +1,46 @@
/**
* tests/t20028/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("t20028", "[test-case][sequence]")
{
auto [config, db] = load_config("t20028");
auto diagram = config.diagrams["t20028_sequence"];
REQUIRE(diagram->name == "t20028_sequence");
auto model = generate_sequence_diagram(*db, diagram);
REQUIRE(model->name() == "t20028_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("A"), "a()"));
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("A"), "b()"));
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("A"), "c()"));
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("A"), "d()"));
REQUIRE_THAT(puml, !HasCall(_A("tmain()"), _A("B"), "e()"));
save_puml(
"./" + config.output_directory() + "/" + diagram->name + ".puml", puml);
}

View File

@@ -274,6 +274,7 @@ using namespace clanguml::test::matchers;
#include "t20025/test_case.h"
#include "t20026/test_case.h"
#include "t20027/test_case.h"
#include "t20028/test_case.h"
///
/// Package diagram tests

View File

@@ -229,6 +229,9 @@ test_cases:
- name: t20027
title: Filter call expressions based on access test case
description:
- name: t20028
title: Conditional (ternary) '?:' operator test case
description:
Package diagrams:
- name: t30001
title: Basic package diagram test case