From 0168edeba269525ecf8001106328033923047885 Mon Sep 17 00:00:00 2001 From: Bartek Kryza Date: Fri, 30 Jul 2021 13:14:30 +0200 Subject: [PATCH] Changed decorator tag from clanguml to uml --- src/uml/decorators.cc | 14 ++++---- src/uml/decorators.h | 4 +-- tests/t00028/t00028.cc | 16 ++++----- tests/test_decorator_parser.cc | 66 +++++++++++++++++++++++++++++----- 4 files changed, 75 insertions(+), 25 deletions(-) diff --git a/src/uml/decorators.cc b/src/uml/decorators.cc index 404fe623..05bb4b37 100644 --- a/src/uml/decorators.cc +++ b/src/uml/decorators.cc @@ -151,19 +151,21 @@ std::shared_ptr aggregation::from_string(std::string_view c) return res; } -std::vector> parse(std::string documentation_block) +std::vector> parse( + std::string documentation_block, std::string clanguml_tag) { std::vector> res; - const std::string begin_tag{"@clanguml"}; + const std::string begin_tag{"@" + clanguml_tag}; const auto begin_tag_size = begin_tag.size(); - // First replace all \clanguml occurences with @clanguml - util::replace_all(documentation_block, "\\clanguml", "@clanguml"); + // First replace all \uml occurences with @uml + util::replace_all( + documentation_block, "\\" + clanguml_tag, "@" + clanguml_tag); documentation_block = util::trim(documentation_block); std::string_view block_view{documentation_block}; - auto pos = block_view.find("@clanguml{"); + auto pos = block_view.find("@" + clanguml_tag + "{"); while (pos < documentation_block.size()) { auto c_begin = pos + begin_tag_size; auto c_end = documentation_block.find("}", c_begin); @@ -177,7 +179,7 @@ std::vector> parse(std::string documentation_block) if (com) res.emplace_back(std::move(com)); - pos = block_view.find("@clanguml{", c_end); + pos = block_view.find("@" + clanguml_tag + "{", c_end); } return res; diff --git a/src/uml/decorators.h b/src/uml/decorators.h index 6dc37e95..1c2bf77c 100644 --- a/src/uml/decorators.h +++ b/src/uml/decorators.h @@ -24,7 +24,6 @@ namespace clanguml { namespace decorators { -// \clanguml{label:diagram1,diagram2[param] text} struct decorator_toks { std::string label; std::vector diagrams; @@ -80,7 +79,8 @@ struct aggregation : public decorator { static std::shared_ptr from_string(std::string_view c); }; -std::vector> parse(std::string documentation_block); +std::vector> parse( + std::string documentation_block, std::string clanguml_tag = "uml"); } // namespace decorators } // namespace clanguml diff --git a/tests/t00028/t00028.cc b/tests/t00028/t00028.cc index 03c415bc..3a0eb8f2 100644 --- a/tests/t00028/t00028.cc +++ b/tests/t00028/t00028.cc @@ -4,40 +4,40 @@ namespace clanguml { namespace t00028 { -/// \clanguml{note[top] A class note.} +/// \uml{note[top] A class note.} class A { }; -/// \clanguml{note[] B class note.} +/// \uml{note[] B class note.} class B { }; /// -/// @clanguml{note:t00028_class[bottom] C class note.} +/// @uml{note:t00028_class[bottom] C class note.} /// This is class C. class C { }; -/// \clanguml{note +/// \uml{note /// D /// class /// note.} class D { }; -/// \clanguml{note E template class note.} +/// \uml{note E template class note.} template class E { T param; }; -/// \clanguml{note:other_diagram[left] G class note.} +/// \uml{note:other_diagram[left] G class note.} class G { }; -/// @clanguml{note[ bottom ] F enum note.} +/// @uml{note[ bottom ] F enum note.} enum class F { one, two, three }; -/// \clanguml{note[right] R class note.} +/// \uml{note[right] R class note.} class R { A aaa; diff --git a/tests/test_decorator_parser.cc b/tests/test_decorator_parser.cc index 379e956d..203a0c2f 100644 --- a/tests/test_decorator_parser.cc +++ b/tests/test_decorator_parser.cc @@ -52,12 +52,12 @@ TEST_CASE("Test decorator parser on note", "[unit-test]") \param a int an int \param b float a float - \clanguml{note[left] This is a comment} - @clanguml{note[ top ] + \uml{note[left] This is a comment} + @uml{note[ top ] This is a comment } - \clanguml{note This is a comment} - \clanguml{note[] This is a comment} + \uml{note This is a comment} + \uml{note[] This is a comment} )"; using namespace clanguml::decorators; @@ -88,10 +88,58 @@ TEST_CASE("Test decorator parser on note", "[unit-test]") CHECK(n4->text == "This is a comment"); } +TEST_CASE("Test decorator parser on note with custom tag", "[unit-test]") +{ + std::string comment = R"( + \brief This is a comment. + + This is a longer comment. + + \ + + \param a int an int + \param b float a float + + \clanguml{note[left] This is a comment} + @clanguml{note[ top ] + + This is a comment } + \clanguml{note This is a comment} + \clanguml{note[] This is a comment} + )"; + + using namespace clanguml::decorators; + + auto decorators = parse(comment, "clanguml"); + + CHECK(decorators.size() == 4); + + auto n1 = std::dynamic_pointer_cast(decorators.at(0)); + auto n2 = std::dynamic_pointer_cast(decorators.at(1)); + auto n3 = std::dynamic_pointer_cast(decorators.at(2)); + auto n4 = std::dynamic_pointer_cast(decorators.at(3)); + + CHECK(n1); + CHECK(n1->position == "left"); + CHECK(n1->text == "This is a comment"); + + CHECK(n2); + CHECK(n2->position == "top"); + CHECK(n2->text == "This is a comment"); + + CHECK(n3); + CHECK(n3->position == "left"); + CHECK(n3->text == "This is a comment"); + + CHECK(n4); + CHECK(n4->position == "left"); + CHECK(n4->text == "This is a comment"); +} + TEST_CASE("Test decorator parser on style", "[unit-test]") { std::string comment = R"( - \clanguml{style[#green,dashed,thickness=4]} + \uml{style[#green,dashed,thickness=4]} )"; using namespace clanguml::decorators; @@ -109,7 +157,7 @@ TEST_CASE("Test decorator parser on style", "[unit-test]") TEST_CASE("Test decorator parser on aggregation", "[unit-test]") { std::string comment = R"( - \clanguml{aggregation[0..1:0..*]} + \uml{aggregation[0..1:0..*]} )"; using namespace clanguml::decorators; @@ -127,7 +175,7 @@ TEST_CASE("Test decorator parser on aggregation", "[unit-test]") TEST_CASE("Test decorator parser on skip", "[unit-test]") { std::string comment = R"( - \clanguml{skip} + \uml{skip} )"; using namespace clanguml::decorators; @@ -144,7 +192,7 @@ TEST_CASE("Test decorator parser on skip", "[unit-test]") TEST_CASE("Test decorator parser on skiprelationship", "[unit-test]") { std::string comment = R"( - \clanguml{skiprelationship} + \uml{skiprelationship} )"; using namespace clanguml::decorators; @@ -161,7 +209,7 @@ TEST_CASE("Test decorator parser on skiprelationship", "[unit-test]") TEST_CASE("Test decorator parser on diagram scope", "[unit-test]") { std::string comment = R"( - \clanguml{note:diagram1, diagram2, + \uml{note:diagram1, diagram2, diagram3[left] Note only for diagrams 1, 2 and 3.} )";