Fixed generation of test cases for diagram notes in mermaid class diagrams
This commit is contained in:
@@ -18,4 +18,9 @@ diagrams:
|
||||
- |
|
||||
note right of {{ alias("D") }}
|
||||
{{ comment("D").text }}
|
||||
end note
|
||||
end note
|
||||
mermaid:
|
||||
after:
|
||||
- '{% set e=element("A") %} note for {{ e.alias }} "{{ trim(e.comment.brief.0) }}"'
|
||||
- '{% set e=element("clanguml::t00002::B") %} note for {{ e.alias }} "{{ trim(e.comment.brief.0) }}"'
|
||||
- 'note for {{ alias("D") }} "{{ comment("D").text }}"'
|
||||
@@ -110,9 +110,11 @@ TEST_CASE("t00002", "[test-case][class]")
|
||||
auto mmd = generate_class_mermaid(diagram, *model);
|
||||
|
||||
mermaid::AliasMatcher _A(mmd);
|
||||
using mermaid::HasNote;
|
||||
using mermaid::IsAbstractClass;
|
||||
|
||||
REQUIRE_THAT(mmd, StartsWith("classDiagram"));
|
||||
REQUIRE_THAT(mmd, mermaid::IsAbstractClass(_A("A")));
|
||||
REQUIRE_THAT(mmd, IsAbstractClass(_A("A")));
|
||||
REQUIRE_THAT(mmd, IsClass(_A("B")));
|
||||
REQUIRE_THAT(mmd, IsClass(_A("C")));
|
||||
REQUIRE_THAT(mmd, IsClass(_A("D")));
|
||||
@@ -126,9 +128,8 @@ TEST_CASE("t00002", "[test-case][class]")
|
||||
REQUIRE_THAT(mmd, (mermaid::IsMethod<Public, Abstract>("foo_a")));
|
||||
REQUIRE_THAT(mmd, (mermaid::IsMethod<Public, Abstract>("foo_c")));
|
||||
|
||||
// REQUIRE_THAT(mmd, HasNote(_A("A"), "left", "This is class
|
||||
// A")); REQUIRE_THAT(mmd, HasNote(_A("B"), "top", "This is class
|
||||
// B"));
|
||||
REQUIRE_THAT(mmd, HasNote(_A("A"), "left", "This is class A"));
|
||||
REQUIRE_THAT(mmd, HasNote(_A("B"), "top", "This is class B"));
|
||||
|
||||
REQUIRE_THAT(mmd,
|
||||
mermaid::HasLink(_A("A"),
|
||||
|
||||
@@ -76,6 +76,7 @@ note.)";
|
||||
auto src = generate_class_mermaid(diagram, *model);
|
||||
|
||||
mermaid::AliasMatcher _A(src);
|
||||
using mermaid::HasNote;
|
||||
using mermaid::IsEnum;
|
||||
|
||||
REQUIRE_THAT(src, IsClass(_A("A")));
|
||||
@@ -85,10 +86,19 @@ note.)";
|
||||
REQUIRE_THAT(src, IsClass(_A("E<T>")));
|
||||
REQUIRE_THAT(src, IsEnum(_A("F")));
|
||||
REQUIRE_THAT(src, IsClass(_A("R")));
|
||||
// REQUIRE_THAT(src, HasNote(_A("A"), "top", "A class note."));
|
||||
// REQUIRE_THAT(src, HasNote(_A("B"), "left", "B class note."));
|
||||
// REQUIRE_THAT(src, HasNote(_A("C"), "bottom", "C class
|
||||
// note."));
|
||||
REQUIRE_THAT(src, HasNote(_A("A"), "top", "A class note."));
|
||||
REQUIRE_THAT(src, HasNote(_A("B"), "left", "B class note."));
|
||||
REQUIRE_THAT(src, HasNote(_A("C"), "bottom", "C class note."));
|
||||
const auto d_note = R"(
|
||||
D
|
||||
class
|
||||
note.)";
|
||||
REQUIRE_THAT(src, HasNote(_A("D"), "left", d_note));
|
||||
REQUIRE_THAT(
|
||||
src, HasNote(_A("E<T>"), "left", "E template class note."));
|
||||
REQUIRE_THAT(src, HasNote(_A("F"), "bottom", "F enum note."));
|
||||
REQUIRE_THAT(src, !HasNote(_A("G"), "left", "G class note."));
|
||||
REQUIRE_THAT(src, HasNote(_A("R"), "right", "R class note."));
|
||||
|
||||
save_mermaid(config.output_directory(), diagram->name + ".mmd", src);
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ diagrams:
|
||||
{% endfor %}
|
||||
|
||||
{% endif %}
|
||||
{# Render template paramete if any #}
|
||||
{# Render template parameters if any #}
|
||||
{% if existsIn(e, "comment") and existsIn(e.comment, "tparam") %}
|
||||
{% set c=e.comment %}
|
||||
|
||||
@@ -75,3 +75,29 @@ diagrams:
|
||||
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
mermaid:
|
||||
after:
|
||||
- |
|
||||
note for {{ alias("NoSuchClass") }} "{{ comment("NoSuchClass").formatted }}"
|
||||
- |
|
||||
note for {{ alias("A") }} "{{ comment("clanguml::t00050::A").formatted }}"
|
||||
- |
|
||||
note for {{ element("clanguml::t00050::A").alias }} {% set e=element("clanguml::t00050::A") %} "{{ e.comment.formatted }}"
|
||||
note for {{ alias("C") }} "{{ trim(comment("clanguml::t00050::C").text) }}"
|
||||
{% set cmt=comment("clanguml::t00050::G").paragraph %}
|
||||
note for {{ alias("G") }} "{{ trim(cmt.0) }}"
|
||||
note for {{ alias("G") }} "{{ trim(cmt.1) }}"
|
||||
note for {{ alias("G") }} "{{ trim(cmt.2) }}"
|
||||
- |
|
||||
{# Render brief comments and todos, if any were written for an element #}
|
||||
{% for e in diagram.elements %}
|
||||
{% if existsIn(e, "comment") and existsIn(e.comment, "brief") %}
|
||||
note for {{ e.alias }} {% set c=e.comment %} "{{ c.brief.0 }}"
|
||||
{% endif %}
|
||||
{% if existsIn(e, "comment") and existsIn(e.comment, "todo") %}
|
||||
{% set c=e.comment %}
|
||||
{% for t in c.todo %}
|
||||
note for {{ e.alias }} "**TODO** {{ t }}"
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
@@ -73,6 +73,7 @@ TEST_CASE("t00050", "[test-case][class]")
|
||||
auto src = generate_class_mermaid(diagram, *model);
|
||||
|
||||
mermaid::AliasMatcher _A(src);
|
||||
using mermaid::HasNote;
|
||||
using mermaid::IsEnum;
|
||||
|
||||
// Check if all classes exist
|
||||
@@ -82,6 +83,18 @@ TEST_CASE("t00050", "[test-case][class]")
|
||||
REQUIRE_THAT(src, IsClass(_A("utils::D")));
|
||||
REQUIRE_THAT(src, IsEnum(_A("E")));
|
||||
|
||||
REQUIRE_THAT(src, HasNote(_A("A"), "left"));
|
||||
REQUIRE_THAT(src, HasNote(_A("A"), "right"));
|
||||
REQUIRE_THAT(src, HasNote(_A("B"), "top"));
|
||||
REQUIRE_THAT(src, HasNote(_A("C"), "top"));
|
||||
REQUIRE_THAT(src, HasNote(_A("utils::D"), "top"));
|
||||
REQUIRE_THAT(src, !HasNote(_A("E"), "bottom"));
|
||||
REQUIRE_THAT(src, !HasNote(_A("NoComment"), "top"));
|
||||
REQUIRE_THAT(src, HasNote(_A("F<T,V,int N>"), "top"));
|
||||
REQUIRE_THAT(src, HasNote(_A("G"), "top"));
|
||||
REQUIRE_THAT(src, HasNote(_A("G"), "bottom"));
|
||||
REQUIRE_THAT(src, HasNote(_A("G"), "right"));
|
||||
|
||||
save_mermaid(config.output_directory(), diagram->name + ".mmd", src);
|
||||
}
|
||||
}
|
||||
@@ -686,6 +686,16 @@ ContainsMatcher HasNote(std::string const &cls, std::string const &position,
|
||||
fmt::format("note {} of {}", position, cls), caseSensitivity));
|
||||
}
|
||||
|
||||
namespace mermaid {
|
||||
ContainsMatcher HasNote(std::string const &cls,
|
||||
std::string const &position = "", std::string const ¬e = "",
|
||||
CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes)
|
||||
{
|
||||
return ContainsMatcher(
|
||||
CasedString(fmt::format("note for {}", cls), caseSensitivity));
|
||||
}
|
||||
}
|
||||
|
||||
ContainsMatcher HasMemberNote(std::string const &cls, std::string const &member,
|
||||
std::string const &position, std::string const ¬e = "",
|
||||
CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes)
|
||||
|
||||
Reference in New Issue
Block a user