From f4d4633ecefa1cbf07c3c271646e2d12c4a8a43d Mon Sep 17 00:00:00 2001 From: Bartek Kryza Date: Sun, 10 Apr 2022 13:33:16 +0200 Subject: [PATCH] Added basic include diagram test case --- tests/t40001/.clang-uml | 11 ++++++++++- tests/t40001/include/lib1/lib1.h | 7 +++++++ tests/t40001/src/t40001.cc | 2 +- tests/t40001/test_case.h | 8 ++++++++ tests/test_cases.cc | 4 ++++ tests/test_cases.h | 28 +++++++++++++++++++++++++--- tests/test_util.cc | 19 +++++++++++++++++++ 7 files changed, 74 insertions(+), 5 deletions(-) create mode 100644 tests/t40001/include/lib1/lib1.h diff --git a/tests/t40001/.clang-uml b/tests/t40001/.clang-uml index 2ccf4457..6d55f301 100644 --- a/tests/t40001/.clang-uml +++ b/tests/t40001/.clang-uml @@ -3,8 +3,17 @@ output_directory: puml diagrams: t40001_include: type: include + # Provide the files to parse in order to look + # for #include directives glob: - - ../../tests/t40001/t40001.cc + - ../../tests/t40001/**/*.cc + - ../../tests/t40001/**/*.h + # Render the paths relative to this directory + relative_to: ../../tests/t40001 + include: + # Include only headers belonging to these paths + paths: + - ../../tests/t40001 plantuml: before: - "' t40001 test include diagram" \ No newline at end of file diff --git a/tests/t40001/include/lib1/lib1.h b/tests/t40001/include/lib1/lib1.h new file mode 100644 index 00000000..8d6d7d9b --- /dev/null +++ b/tests/t40001/include/lib1/lib1.h @@ -0,0 +1,7 @@ +#pragma once + +namespace clanguml::t40001::lib1 { + +int foo2() { return 0; } + +} \ No newline at end of file diff --git a/tests/t40001/src/t40001.cc b/tests/t40001/src/t40001.cc index 9c227217..d03a527c 100644 --- a/tests/t40001/src/t40001.cc +++ b/tests/t40001/src/t40001.cc @@ -1,7 +1,7 @@ #include #include -#include "include/t40001_include1.h" +#include "../include/t40001_include1.h" namespace clanguml { namespace t40001 { diff --git a/tests/t40001/test_case.h b/tests/t40001/test_case.h index 64fcaa7e..e2bf65ae 100644 --- a/tests/t40001/test_case.h +++ b/tests/t40001/test_case.h @@ -35,6 +35,14 @@ TEST_CASE("t40001", "[test-case][package]") REQUIRE_THAT(puml, StartsWith("@startuml")); REQUIRE_THAT(puml, EndsWith("@enduml\n")); + REQUIRE_THAT(puml, IsFolder("lib1")); + REQUIRE_THAT(puml, IsFile("lib1.h")); + REQUIRE_THAT(puml, IsFile("t40001.cc")); + REQUIRE_THAT(puml, IsFile("t40001_include1.h")); + + REQUIRE_THAT(puml, IsAssociation(_A("t40001.cc"), _A("t40001_include1.h"))); + REQUIRE_THAT(puml, IsAssociation(_A("t40001_include1.h"), _A("lib1.h"))); + save_puml( "./" + config.output_directory() + "/" + diagram->name + ".puml", puml); } diff --git a/tests/test_cases.cc b/tests/test_cases.cc index a782978c..422c806b 100644 --- a/tests/test_cases.cc +++ b/tests/test_cases.cc @@ -155,6 +155,8 @@ std::string generate_package_puml( std::stringstream ss; + assert(config.get() != nullptr); + ss << generator( dynamic_cast(*config), model); @@ -169,6 +171,8 @@ std::string generate_include_puml( std::stringstream ss; + assert(config.get() != nullptr); + ss << generator( dynamic_cast(*config), model); diff --git a/tests/test_cases.h b/tests/test_cases.h index 6d9a4a70..835fbb92 100644 --- a/tests/test_cases.h +++ b/tests/test_cases.h @@ -185,6 +185,10 @@ struct AliasMatcher { std::regex{"package\\s\"" + name + "\"\\sas\\s" + alias_regex}); patterns.push_back( std::regex{"package\\s\\[" + name + "\\]\\sas\\s" + alias_regex}); + patterns.push_back( + std::regex{"file\\s\"?" + name + "\"?\\sas\\s" + alias_regex}); + patterns.push_back( + std::regex{"folder\\s\"?" + name + "\"?\\sas\\s" + alias_regex}); std::smatch base_match; @@ -260,10 +264,16 @@ ContainsMatcher IsAssociation(std::string const &from, std::string const &to, if (!multiplicity_dest.empty()) format_string += " \"" + multiplicity_dest + "\""; - format_string += " {} : {}"; + format_string += " {}"; - return ContainsMatcher(CasedString( - fmt::format(format_string, from, to, label), caseSensitivity)); + if (!label.empty()) { + format_string += " : {}"; + return ContainsMatcher(CasedString( + fmt::format(format_string, from, to, label), caseSensitivity)); + } + else + return ContainsMatcher( + CasedString(fmt::format(format_string, from, to), caseSensitivity)); } ContainsMatcher IsComposition(std::string const &from, std::string const &to, @@ -444,6 +454,18 @@ ContainsMatcher IsPackage(std::string const &str, CasedString("package [" + str + "]", caseSensitivity)); } +ContainsMatcher IsFolder(std::string const &str, + CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes) +{ + return ContainsMatcher(CasedString("folder " + str, caseSensitivity)); +} + +ContainsMatcher IsFile(std::string const &str, + CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes) +{ + return ContainsMatcher(CasedString("file " + str, caseSensitivity)); +} + ContainsMatcher IsDeprecated(std::string const &str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes) { diff --git a/tests/test_util.cc b/tests/test_util.cc index 6e9be6fd..d89ea994 100644 --- a/tests/test_util.cc +++ b/tests/test_util.cc @@ -20,6 +20,8 @@ #include "util/util.h" #include +#include + #include "catch.h" TEST_CASE("Test split", "[unit-test]") @@ -47,6 +49,23 @@ TEST_CASE("Test abbreviate", "[unit-test]") CHECK(abbreviate("abcdefg", 5) == "ab..."); } +TEST_CASE("Test starts_with", "[unit-test]") +{ + using clanguml::util::starts_with; + using std::filesystem::path; + + CHECK(starts_with(path{"/a/b/c/d"}, path{"/"})); + CHECK(!starts_with(path{"/a/b/c/d"}, path{"/a/b/c/d/e"})); + CHECK(starts_with(path{"/a/b/c/d/e"}, path{"/a/b/c/d"})); + CHECK(starts_with(path{"/a/b/c/d/e"}, path{"/a/b/c/d/"})); + CHECK(!starts_with(path{"/e/f/c/d/file.h"}, path{"/a/b"})); + CHECK(!starts_with(path{"/e/f/c/d/file.h"}, path{"/a/b/"})); + CHECK(starts_with(path{"/a/b/c/d/file.h"}, path{"/a/b/c"})); + CHECK(starts_with(path{"/a/b/c/file.h"}, path{"/a/b/c/file.h"})); + CHECK(starts_with(path{"c/file.h"}, path{"c"})); + CHECK(starts_with(path{"c/file.h"}, path{"c/"})); +} + TEST_CASE("Test replace_all", "[unit-test]") { using namespace clanguml::util;