diff --git a/src/class_diagram/generators/json/class_diagram_generator.cc b/src/class_diagram/generators/json/class_diagram_generator.cc index 50be3967..bcac7632 100644 --- a/src/class_diagram/generators/json/class_diagram_generator.cc +++ b/src/class_diagram/generators/json/class_diagram_generator.cc @@ -113,6 +113,9 @@ generator::generator(diagram_config &config, diagram_model &model) void generator::generate(std::ostream &ostr) const { + json_["elements"] = std::vector{}; + json_["relationships"] = std::vector{}; + generate_top_level_elements(json_); generate_relationships(json_); diff --git a/src/sequence_diagram/generators/json/sequence_diagram_generator.cc b/src/sequence_diagram/generators/json/sequence_diagram_generator.cc index 107d1411..5857b468 100644 --- a/src/sequence_diagram/generators/json/sequence_diagram_generator.cc +++ b/src/sequence_diagram/generators/json/sequence_diagram_generator.cc @@ -58,13 +58,6 @@ generator::generator( { } -std::string generator::render_name(std::string name) const -{ - util::replace_all(name, "##", "::"); - - return name; -} - void generator::generate_call(const message &m, nlohmann::json &parent) const { const auto &from = m_model.get_participant(m.from()); diff --git a/src/sequence_diagram/generators/json/sequence_diagram_generator.h b/src/sequence_diagram/generators/json/sequence_diagram_generator.h index 6fe7c89d..5bff18da 100644 --- a/src/sequence_diagram/generators/json/sequence_diagram_generator.h +++ b/src/sequence_diagram/generators/json/sequence_diagram_generator.h @@ -67,19 +67,8 @@ public: private: bool is_participant_generated(common::id_t id) const; - - std::string render_name(std::string name) const; - - mutable std::set generated_participants_; - - mutable nlohmann::json json_; - - mutable std::vector> - block_statements_stack_; - void process_call_message(const model::message &m, std::vector &visited) const; - void process_if_message(const model::message &m) const; void process_else_if_message() const; void process_end_if_message() const; @@ -98,6 +87,13 @@ private: void process_for_message(const model::message &m) const; void process_end_while_message() const; void process_while_message(const model::message &m) const; + + mutable std::set generated_participants_; + + mutable nlohmann::json json_; + + mutable std::vector> + block_statements_stack_; }; } // namespace clanguml::sequence_diagram::generators::json diff --git a/tests/t00002/test_case.h b/tests/t00002/test_case.h index 95e9e94b..2f1f368e 100644 --- a/tests/t00002/test_case.h +++ b/tests/t00002/test_case.h @@ -75,444 +75,20 @@ TEST_CASE("t00002", "[test-case][class]") save_puml(config.output_directory() + "/" + diagram->name + ".puml", puml); - const std::string expected_json = R"##( -{ - "elements": [ - { - "bases": [], - "comment": { - "brief": [ - " This is class A\n" - ], - "formatted": "\\brief This is class A", - "paragraph": [ - " \n" - ], - "raw": "/// \\brief This is class A", - "text": "\n \n" - }, - "display_name": "clanguml::t00002::A", - "id": "987634239855407298", - "is_abstract": true, - "is_nested": false, - "is_struct": false, - "is_template": false, - "is_union": false, - "members": [], - "methods": [ - { - "access": "public", - "comment": { - "formatted": "Abstract foo_a", - "paragraph": [ - " Abstract foo_a\n" - ], - "raw": "/// Abstract foo_a", - "text": "\n Abstract foo_a\n" - }, - "is_const": false, - "is_defaulted": false, - "is_implicit": false, - "is_pure_virtual": true, - "is_static": false, - "is_virtual": true, - "name": "foo_a", - "parameters": [], - "type": "void" - }, - { - "access": "public", - "comment": { - "formatted": "Abstract foo_c", - "paragraph": [ - " Abstract foo_c\n" - ], - "raw": "/// Abstract foo_c", - "text": "\n Abstract foo_c\n" - }, - "is_const": false, - "is_defaulted": false, - "is_implicit": false, - "is_pure_virtual": true, - "is_static": false, - "is_virtual": true, - "name": "foo_c", - "parameters": [], - "type": "void" - } - ], - "name": "A", - "namespace": "clanguml::t00002", - "source_location": { - "file": "../../tests/t00002/t00002.cc", - "line": 7 - }, - "template_parameters": [], - "type": "class" - }, - { - "bases": [ - { - "access": "public", - "id": "987634239855407298", - "is_virtual": false, - "name": "clanguml::t00002::A" - } - ], - "comment": { - "brief": [ - " This is class B\n" - ], - "formatted": "\\brief This is class B", - "paragraph": [ - " \n" - ], - "raw": "/// \\brief This is class B", - "text": "\n \n" - }, - "display_name": "clanguml::t00002::B", - "id": "594234458687375950", - "is_abstract": false, - "is_nested": false, - "is_struct": false, - "is_template": false, - "is_union": false, - "members": [], - "methods": [ - { - "access": "public", - "is_const": false, - "is_defaulted": false, - "is_implicit": false, - "is_pure_virtual": false, - "is_static": false, - "is_virtual": true, - "name": "foo_a", - "parameters": [], - "type": "void" - } - ], - "name": "B", - "namespace": "clanguml::t00002", - "source_location": { - "file": "../../tests/t00002/t00002.cc", - "line": 16 - }, - "template_parameters": [], - "type": "class" - }, - { - "bases": [ - { - "access": "public", - "id": "987634239855407298", - "is_virtual": false, - "name": "clanguml::t00002::A" - } - ], - "comment": { - "brief": [ - " This is class C - class C has a long comment\n" - ], - "formatted": "@brief This is class C - class C has a long comment\n\nVivamus integer non suscipit taciti mus etiam at primis tempor sagittis sit,\neuismod libero facilisi aptent elementum felis blandit cursus gravida sociis\nerat ante, eleifend lectus nullam dapibus netus feugiat curae curabitur est\nad.", - "paragraph": [ - " \n", - " Vivamus integer non suscipit taciti mus etiam at primis tempor sagittis sit,\n euismod libero facilisi aptent elementum felis blandit cursus gravida sociis\n erat ante, eleifend lectus nullam dapibus netus feugiat curae curabitur est\n ad.\n" - ], - "raw": "/// @brief This is class C - class C has a long comment\n///\n/// Vivamus integer non suscipit taciti mus etiam at primis tempor sagittis sit,\n/// euismod libero facilisi aptent elementum felis blandit cursus gravida sociis\n/// erat ante, eleifend lectus nullam dapibus netus feugiat curae curabitur est\n/// ad.", - "text": "\n \n\n Vivamus integer non suscipit taciti mus etiam at primis tempor sagittis sit,\n euismod libero facilisi aptent elementum felis blandit cursus gravida sociis\n erat ante, eleifend lectus nullam dapibus netus feugiat curae curabitur est\n ad.\n" - }, - "display_name": "clanguml::t00002::C", - "id": "1142499429598587507", - "is_abstract": false, - "is_nested": false, - "is_struct": false, - "is_template": false, - "is_union": false, - "members": [], - "methods": [ - { - "access": "public", - "comment": { - "formatted": "Do nothing unless override is provided", - "paragraph": [ - " Do nothing unless override is provided\n" - ], - "raw": "/// Do nothing unless override is provided", - "text": "\n Do nothing unless override is provided\n" - }, - "is_const": false, - "is_defaulted": false, - "is_implicit": false, - "is_pure_virtual": false, - "is_static": false, - "is_virtual": true, - "name": "foo_c", - "parameters": [], - "type": "void" - } - ], - "name": "C", - "namespace": "clanguml::t00002", - "source_location": { - "file": "../../tests/t00002/t00002.cc", - "line": 27 - }, - "template_parameters": [], - "type": "class" - }, - { - "bases": [ - { - "access": "public", - "id": "594234458687375950", - "is_virtual": false, - "name": "clanguml::t00002::B" - }, - { - "access": "public", - "id": "1142499429598587507", - "is_virtual": false, - "name": "clanguml::t00002::C" - } - ], - "comment": { - "formatted": "This is class D\nwhich is a little like B\nand a little like C", - "paragraph": [ - " This is class D\n which is a little like B\n and a little like C\n" - ], - "raw": "/// This is class D\n/// which is a little like B\n/// and a little like C", - "text": "\n This is class D\n which is a little like B\n and a little like C\n" - }, - "display_name": "clanguml::t00002::D", - "id": "60950494980414724", - "is_abstract": false, - "is_nested": false, - "is_struct": false, - "is_template": false, - "is_union": false, - "members": [ - { - "access": "private", - "comment": { - "formatted": "All the A pointers", - "paragraph": [ - " All the A pointers\n" - ], - "raw": "/// All the A pointers", - "text": "\n All the A pointers\n" - }, - "is_static": false, - "name": "as", - "source_location": { - "file": "../../tests/t00002/t00002.cc", - "line": 58 - }, - "type": "std::vector" - } - ], - "methods": [ - { - "access": "public", - "comment": { - "formatted": "\n Forward foo_a\n ", - "paragraph": [ - " Forward foo_a\n" - ], - "raw": "/**\n * Forward foo_a\n */", - "text": "\n Forward foo_a\n" - }, - "is_const": false, - "is_defaulted": false, - "is_implicit": false, - "is_pure_virtual": false, - "is_static": false, - "is_virtual": true, - "name": "foo_a", - "parameters": [], - "type": "void" - }, - { - "access": "public", - "comment": { - "formatted": "\n Forward foo_c\n ", - "paragraph": [ - " Forward foo_c\n" - ], - "raw": "/**\n * Forward foo_c\n */", - "text": "\n Forward foo_c\n" - }, - "is_const": false, - "is_defaulted": false, - "is_implicit": false, - "is_pure_virtual": false, - "is_static": false, - "is_virtual": true, - "name": "foo_c", - "parameters": [], - "type": "void" - } - ], - "name": "D", - "namespace": "clanguml::t00002", - "source_location": { - "file": "../../tests/t00002/t00002.cc", - "line": 36 - }, - "template_parameters": [], - "type": "class" - }, - { - "bases": [ - { - "access": "public", - "id": "594234458687375950", - "is_virtual": true, - "name": "clanguml::t00002::B" - }, - { - "access": "public", - "id": "1142499429598587507", - "is_virtual": true, - "name": "clanguml::t00002::C" - } - ], - "display_name": "clanguml::t00002::E", - "id": "2237886670308966220", - "is_abstract": false, - "is_nested": false, - "is_struct": false, - "is_template": false, - "is_union": false, - "members": [ - { - "access": "private", - "comment": { - "formatted": "All the A pointers", - "paragraph": [ - " All the A pointers\n" - ], - "raw": "/// All the A pointers", - "text": "\n All the A pointers\n" - }, - "is_static": false, - "name": "as", - "source_location": { - "file": "../../tests/t00002/t00002.cc", - "line": 83 - }, - "type": "std::vector" - } - ], - "methods": [ - { - "access": "public", - "comment": { - "formatted": "\n Forward foo_a", - "paragraph": [ - " Forward foo_a\n" - ], - "raw": "///\n /// Forward foo_a\n ///", - "text": "\n Forward foo_a\n" - }, - "is_const": false, - "is_defaulted": false, - "is_implicit": false, - "is_pure_virtual": false, - "is_static": false, - "is_virtual": true, - "name": "foo_a", - "parameters": [], - "type": "void" - }, - { - "access": "public", - "comment": { - "formatted": "\n Forward foo_c", - "paragraph": [ - " Forward foo_c\n" - ], - "raw": "///\n /// Forward foo_c\n ///", - "text": "\n Forward foo_c\n" - }, - "is_const": false, - "is_defaulted": false, - "is_implicit": false, - "is_pure_virtual": false, - "is_static": false, - "is_virtual": true, - "name": "foo_c", - "parameters": [], - "type": "void" - } - ], - "name": "E", - "namespace": "clanguml::t00002", - "source_location": { - "file": "../../tests/t00002/t00002.cc", - "line": 61 - }, - "template_parameters": [], - "type": "class" - } - ], - "relationships": [ - { - "access": "public", - "destination": "987634239855407298", - "source": "594234458687375950", - "type": "extension" - }, - { - "access": "public", - "destination": "987634239855407298", - "source": "1142499429598587507", - "type": "extension" - }, - { - "access": "private", - "destination": "987634239855407298", - "label": "as", - "source": "60950494980414724", - "type": "association" - }, - { - "access": "public", - "destination": "594234458687375950", - "source": "60950494980414724", - "type": "extension" - }, - { - "access": "public", - "destination": "1142499429598587507", - "source": "60950494980414724", - "type": "extension" - }, - { - "access": "private", - "destination": "987634239855407298", - "label": "as", - "source": "2237886670308966220", - "type": "association" - }, - { - "access": "public", - "destination": "594234458687375950", - "source": "2237886670308966220", - "type": "extension" - }, - { - "access": "public", - "destination": "1142499429598587507", - "source": "2237886670308966220", - "type": "extension" - } - ] -} -)##"; auto j = generate_class_json(diagram, *model); - REQUIRE(j == nlohmann::json::parse(expected_json)); + REQUIRE(json::IsClass(j, "clanguml::t00002::A")); + REQUIRE(json::IsClass(j, "clanguml::t00002::B")); + REQUIRE(json::IsClass(j, "clanguml::t00002::C")); + REQUIRE(json::IsBaseClass(j, "clanguml::t00002::A", "clanguml::t00002::B")); + REQUIRE(json::IsBaseClass(j, "clanguml::t00002::A", "clanguml::t00002::C")); + REQUIRE(json::IsBaseClass(j, "clanguml::t00002::B", "clanguml::t00002::D")); + REQUIRE(json::IsBaseClass(j, "clanguml::t00002::C", "clanguml::t00002::D")); + REQUIRE(json::IsMethod(j, "clanguml::t00002::A", "foo_a")); + REQUIRE(json::IsMethod(j, "clanguml::t00002::C", "foo_c")); + + REQUIRE(json::IsAssociation( + j, "clanguml::t00002::D", "clanguml::t00002::A", "as")); save_json(config.output_directory() + "/" + diagram->name + ".json", j); } \ No newline at end of file diff --git a/tests/t00003/test_case.h b/tests/t00003/test_case.h index c499a033..bcb7b229 100644 --- a/tests/t00003/test_case.h +++ b/tests/t00003/test_case.h @@ -66,4 +66,20 @@ TEST_CASE("t00003", "[test-case][class]") REQUIRE_THAT(puml, (IsField("c_", "int"))); save_puml(config.output_directory() + "/" + diagram->name + ".puml", puml); + + auto j = generate_class_json(diagram, *model); + + REQUIRE(json::IsClass(j, "clanguml::t00003::A")); + REQUIRE(json::IsMethod(j, "clanguml::t00003::A", "A")); + REQUIRE(json::IsMethod(j, "clanguml::t00003::A", "~A")); + REQUIRE(json::IsMethod(j, "clanguml::t00003::A", "basic_method")); + REQUIRE(json::IsMethod(j, "clanguml::t00003::A", "static_method")); + REQUIRE(json::IsMethod(j, "clanguml::t00003::A", "const_method")); + REQUIRE(json::IsMethod(j, "clanguml::t00003::A", "default_int")); + REQUIRE(json::IsMethod(j, "clanguml::t00003::A", "default_string")); + + REQUIRE( + !json::IsDependency(j, "clanguml::t00002::A", "clanguml::t00002::A")); + + save_json(config.output_directory() + "/" + diagram->name + ".json", j); } diff --git a/tests/t00014/test_case.h b/tests/t00014/test_case.h index 17b6f38d..3df7d280 100644 --- a/tests/t00014/test_case.h +++ b/tests/t00014/test_case.h @@ -116,900 +116,23 @@ TEST_CASE("t00014", "[test-case][class]") save_puml(config.output_directory() + "/" + diagram->name + ".puml", puml); - std::string expected_json = R"##( -{ - "elements": [ - { - "bases": [], - "display_name": "clanguml::t00014::A", - "id": "765890579167335652", - "is_abstract": false, - "is_nested": false, - "is_struct": true, - "is_template": false, - "is_union": false, - "members": [ - { - "access": "public", - "is_static": false, - "name": "t", - "source_location": { - "file": "../../tests/t00014/t00014.cc", - "line": 22 - }, - "type": "T" - }, - { - "access": "public", - "is_static": false, - "name": "p", - "source_location": { - "file": "../../tests/t00014/t00014.cc", - "line": 23 - }, - "type": "P" - } - ], - "methods": [], - "name": "A", - "namespace": "clanguml::t00014", - "source_location": { - "file": "../../tests/t00014/t00014.cc", - "line": 21 - }, - "template_parameters": [ - { - "is_variadic": false, - "kind": "template_type", - "name": "T" - }, - { - "is_variadic": false, - "kind": "template_type", - "name": "P" - } - ], - "type": "class" - }, - { - "bases": [], - "display_name": "clanguml::t00014::B", - "id": "934136012292043506", - "is_abstract": false, - "is_nested": false, - "is_struct": true, - "is_template": false, - "is_union": false, - "members": [ - { - "access": "public", - "is_static": false, - "name": "value", - "source_location": { - "file": "../../tests/t00014/t00014.cc", - "line": 27 - }, - "type": "std::string" - } - ], - "methods": [], - "name": "B", - "namespace": "clanguml::t00014", - "source_location": { - "file": "../../tests/t00014/t00014.cc", - "line": 26 - }, - "template_parameters": [], - "type": "class" - }, - { - "bases": [], - "display_name": "clanguml::t00014::A", - "id": "2186387853087008570", - "is_abstract": false, - "is_nested": false, - "is_struct": false, - "is_template": false, - "is_union": false, - "members": [], - "methods": [], - "name": "A", - "namespace": "clanguml::t00014", - "template_parameters": [ - { - "is_variadic": false, - "kind": "argument", - "type": "T" - }, - { - "is_variadic": false, - "kind": "argument", - "type": "std::string" - } - ], - "type": "class" - }, - { - "bases": [], - "display_name": "clanguml::t00014::A>", - "id": "947292733740993297", - "is_abstract": false, - "is_nested": false, - "is_struct": false, - "is_template": false, - "is_union": false, - "members": [], - "methods": [], - "name": "A", - "namespace": "clanguml::t00014", - "template_parameters": [ - { - "is_variadic": false, - "kind": "argument", - "type": "T" - }, - { - "is_variadic": false, - "kind": "argument", - "type": "std::unique_ptr" - } - ], - "type": "class" - }, - { - "bases": [], - "display_name": "clanguml::t00014::A", - "id": "1700006390494465667", - "is_abstract": false, - "is_nested": false, - "is_struct": false, - "is_template": false, - "is_union": false, - "members": [], - "methods": [], - "name": "A", - "namespace": "clanguml::t00014", - "template_parameters": [ - { - "is_variadic": false, - "kind": "argument", - "type": "long" - }, - { - "is_variadic": false, - "kind": "argument", - "type": "T" - } - ], - "type": "class" - }, - { - "bases": [], - "display_name": "clanguml::t00014::A", - "id": "2017665567517853203", - "is_abstract": false, - "is_nested": false, - "is_struct": false, - "is_template": false, - "is_union": false, - "members": [], - "methods": [], - "name": "A", - "namespace": "clanguml::t00014", - "template_parameters": [ - { - "is_variadic": false, - "kind": "argument", - "type": "double" - }, - { - "is_variadic": false, - "kind": "argument", - "type": "T" - } - ], - "type": "class" - }, - { - "bases": [], - "display_name": "clanguml::t00014::A", - "id": "906557320263235873", - "is_abstract": false, - "is_nested": false, - "is_struct": false, - "is_template": false, - "is_union": false, - "members": [], - "methods": [], - "name": "A", - "namespace": "clanguml::t00014", - "template_parameters": [ - { - "is_variadic": false, - "kind": "argument", - "type": "long" - }, - { - "is_variadic": false, - "kind": "argument", - "type": "U" - } - ], - "type": "class" - }, - { - "bases": [], - "display_name": "clanguml::t00014::A", - "id": "378898020828430636", - "is_abstract": false, - "is_nested": false, - "is_struct": false, - "is_template": false, - "is_union": false, - "members": [], - "methods": [], - "name": "A", - "namespace": "clanguml::t00014", - "template_parameters": [ - { - "is_variadic": false, - "kind": "argument", - "type": "long" - }, - { - "is_variadic": false, - "kind": "argument", - "type": "bool" - } - ], - "type": "class" - }, - { - "bases": [], - "display_name": "clanguml::t00014::A", - "id": "2082013375525130414", - "is_abstract": false, - "is_nested": false, - "is_struct": false, - "is_template": false, - "is_union": false, - "members": [], - "methods": [], - "name": "A", - "namespace": "clanguml::t00014", - "template_parameters": [ - { - "is_variadic": false, - "kind": "argument", - "type": "double" - }, - { - "is_variadic": false, - "kind": "argument", - "type": "bool" - } - ], - "type": "class" - }, - { - "bases": [], - "display_name": "clanguml::t00014::A", - "id": "51978493292659230", - "is_abstract": false, - "is_nested": false, - "is_struct": false, - "is_template": false, - "is_union": false, - "members": [], - "methods": [], - "name": "A", - "namespace": "clanguml::t00014", - "template_parameters": [ - { - "is_variadic": false, - "kind": "argument", - "type": "long" - }, - { - "is_variadic": false, - "kind": "argument", - "type": "float" - } - ], - "type": "class" - }, - { - "bases": [], - "display_name": "clanguml::t00014::A", - "id": "197769253782961588", - "is_abstract": false, - "is_nested": false, - "is_struct": false, - "is_template": false, - "is_union": false, - "members": [], - "methods": [], - "name": "A", - "namespace": "clanguml::t00014", - "template_parameters": [ - { - "is_variadic": false, - "kind": "argument", - "type": "double" - }, - { - "is_variadic": false, - "kind": "argument", - "type": "float" - } - ], - "type": "class" - }, - { - "bases": [], - "display_name": "clanguml::t00014::A", - "id": "895940711566401184", - "is_abstract": false, - "is_nested": false, - "is_struct": false, - "is_template": false, - "is_union": false, - "members": [], - "methods": [], - "name": "A", - "namespace": "clanguml::t00014", - "template_parameters": [ - { - "is_variadic": false, - "kind": "argument", - "type": "bool" - }, - { - "is_variadic": false, - "kind": "argument", - "type": "std::string" - } - ], - "type": "class" - }, - { - "bases": [], - "display_name": "clanguml::t00014::A>", - "id": "1751732625010742161", - "is_abstract": false, - "is_nested": false, - "is_struct": false, - "is_template": false, - "is_union": false, - "members": [], - "methods": [], - "name": "A", - "namespace": "clanguml::t00014", - "template_parameters": [ - { - "is_variadic": false, - "kind": "argument", - "type": "float" - }, - { - "is_variadic": false, - "kind": "argument", - "type": "std::unique_ptr" - } - ], - "type": "class" - }, - { - "bases": [], - "display_name": "clanguml::t00014::A", - "id": "887121441210847583", - "is_abstract": false, - "is_nested": false, - "is_struct": false, - "is_template": false, - "is_union": false, - "members": [], - "methods": [], - "name": "A", - "namespace": "clanguml::t00014", - "template_parameters": [ - { - "is_variadic": false, - "kind": "argument", - "type": "int" - }, - { - "is_variadic": false, - "kind": "argument", - "type": "std::string" - } - ], - "type": "class" - }, - { - "bases": [], - "display_name": "clanguml::t00014::A", - "id": "1119452495635561975", - "is_abstract": false, - "is_nested": false, - "is_struct": false, - "is_template": false, - "is_union": false, - "members": [], - "methods": [], - "name": "A", - "namespace": "clanguml::t00014", - "template_parameters": [ - { - "is_variadic": false, - "kind": "argument", - "type": "std::string" - }, - { - "is_variadic": false, - "kind": "argument", - "type": "std::string" - } - ], - "type": "class" - }, - { - "bases": [], - "display_name": "clanguml::t00014::A", - "id": "640294848489463071", - "is_abstract": false, - "is_nested": false, - "is_struct": false, - "is_template": false, - "is_union": false, - "members": [], - "methods": [], - "name": "A", - "namespace": "clanguml::t00014", - "template_parameters": [ - { - "is_variadic": false, - "kind": "argument", - "type": "char" - }, - { - "is_variadic": false, - "kind": "argument", - "type": "std::string" - } - ], - "type": "class" - }, - { - "bases": [], - "display_name": "clanguml::t00014::A", - "id": "139599686499155694", - "is_abstract": false, - "is_nested": false, - "is_struct": false, - "is_template": false, - "is_union": false, - "members": [], - "methods": [], - "name": "A", - "namespace": "clanguml::t00014", - "template_parameters": [ - { - "is_variadic": false, - "kind": "argument", - "type": "wchar_t" - }, - { - "is_variadic": false, - "kind": "argument", - "type": "std::string" - } - ], - "type": "class" - }, - { - "bases": [], - "display_name": "clanguml::t00014::R", - "id": "1192822659863756768", - "is_abstract": false, - "is_nested": false, - "is_struct": false, - "is_template": false, - "is_union": false, - "members": [ - { - "access": "private", - "is_static": false, - "name": "bapair", - "source_location": { - "file": "../../tests/t00014/t00014.cc", - "line": 58 - }, - "type": "PairPairBA" - }, - { - "access": "private", - "is_static": false, - "name": "abool", - "source_location": { - "file": "../../tests/t00014/t00014.cc", - "line": 60 - }, - "type": "APtr" - }, - { - "access": "private", - "is_static": false, - "name": "aboolfloat", - "source_location": { - "file": "../../tests/t00014/t00014.cc", - "line": 61 - }, - "type": "AAPtr" - }, - { - "access": "private", - "is_static": false, - "name": "afloat", - "source_location": { - "file": "../../tests/t00014/t00014.cc", - "line": 62 - }, - "type": "ASharedPtr" - }, - { - "access": "private", - "is_static": false, - "name": "boolstring", - "source_location": { - "file": "../../tests/t00014/t00014.cc", - "line": 63 - }, - "type": "A" - }, - { - "access": "private", - "is_static": false, - "name": "floatstring", - "source_location": { - "file": "../../tests/t00014/t00014.cc", - "line": 64 - }, - "type": "AStringPtr" - }, - { - "access": "private", - "is_static": false, - "name": "intstring", - "source_location": { - "file": "../../tests/t00014/t00014.cc", - "line": 65 - }, - "type": "clanguml::t00014::AIntString" - }, - { - "access": "private", - "is_static": false, - "name": "stringstring", - "source_location": { - "file": "../../tests/t00014/t00014.cc", - "line": 66 - }, - "type": "clanguml::t00014::AStringString" - }, - { - "access": "private", - "is_static": false, - "name": "bstringstring", - "source_location": { - "file": "../../tests/t00014/t00014.cc", - "line": 67 - }, - "type": "clanguml::t00014::BStringString" - }, - { - "access": "protected", - "is_static": false, - "name": "bs", - "source_location": { - "file": "../../tests/t00014/t00014.cc", - "line": 70 - }, - "type": "clanguml::t00014::BVector" - }, - { - "access": "public", - "is_static": false, - "name": "bs2", - "source_location": { - "file": "../../tests/t00014/t00014.cc", - "line": 73 - }, - "type": "clanguml::t00014::BVector2" - }, - { - "access": "public", - "is_static": false, - "name": "cb", - "source_location": { - "file": "../../tests/t00014/t00014.cc", - "line": 74 - }, - "type": "SimpleCallback" - }, - { - "access": "public", - "is_static": false, - "name": "gcb", - "source_location": { - "file": "../../tests/t00014/t00014.cc", - "line": 75 - }, - "type": "GenericCallback" - }, - { - "access": "public", - "is_static": false, - "name": "vcb", - "source_location": { - "file": "../../tests/t00014/t00014.cc", - "line": 76 - }, - "type": "clanguml::t00014::VoidCallback" - }, - { - "access": "public", - "is_static": false, - "name": "vps", - "source_location": { - "file": "../../tests/t00014/t00014.cc", - "line": 77 - }, - "type": "VectorPtr" - } - ], - "methods": [], - "name": "R", - "namespace": "clanguml::t00014", - "source_location": { - "file": "../../tests/t00014/t00014.cc", - "line": 55 - }, - "template_parameters": [], - "type": "class" - } - ], - "relationships": [ - { - "access": "public", - "destination": "765890579167335652", - "source": "2186387853087008570", - "type": "instantiation" - }, - { - "access": "public", - "destination": "765890579167335652", - "source": "947292733740993297", - "type": "instantiation" - }, - { - "access": "public", - "destination": "765890579167335652", - "source": "1700006390494465667", - "type": "instantiation" - }, - { - "access": "public", - "destination": "765890579167335652", - "source": "2017665567517853203", - "type": "instantiation" - }, - { - "access": "public", - "destination": "1700006390494465667", - "source": "906557320263235873", - "type": "instantiation" - }, - { - "access": "public", - "destination": "1700006390494465667", - "source": "378898020828430636", - "type": "instantiation" - }, - { - "access": "public", - "destination": "2017665567517853203", - "source": "2082013375525130414", - "type": "instantiation" - }, - { - "access": "public", - "destination": "1700006390494465667", - "source": "51978493292659230", - "type": "instantiation" - }, - { - "access": "public", - "destination": "2017665567517853203", - "source": "197769253782961588", - "type": "instantiation" - }, - { - "access": "public", - "destination": "2186387853087008570", - "source": "895940711566401184", - "type": "instantiation" - }, - { - "access": "public", - "destination": "947292733740993297", - "source": "1751732625010742161", - "type": "instantiation" - }, - { - "access": "public", - "destination": "2186387853087008570", - "source": "887121441210847583", - "type": "instantiation" - }, - { - "access": "public", - "destination": "2186387853087008570", - "source": "1119452495635561975", - "type": "instantiation" - }, - { - "access": "public", - "destination": "2186387853087008570", - "source": "640294848489463071", - "type": "instantiation" - }, - { - "access": "public", - "destination": "2186387853087008570", - "source": "139599686499155694", - "type": "instantiation" - }, - { - "access": "public", - "destination": "378898020828430636", - "source": "1192822659863756768", - "type": "dependency" - }, - { - "access": "private", - "destination": "934136012292043506", - "label": "bapair", - "source": "1192822659863756768", - "type": "aggregation" - }, - { - "access": "private", - "destination": "378898020828430636", - "label": "bapair", - "source": "1192822659863756768", - "type": "aggregation" - }, - { - "access": "public", - "destination": "2082013375525130414", - "source": "1192822659863756768", - "type": "dependency" - }, - { - "access": "private", - "destination": "2082013375525130414", - "label": "abool", - "source": "1192822659863756768", - "type": "aggregation" - }, - { - "access": "public", - "destination": "51978493292659230", - "source": "1192822659863756768", - "type": "dependency" - }, - { - "access": "private", - "destination": "2082013375525130414", - "label": "aboolfloat", - "source": "1192822659863756768", - "type": "aggregation" - }, - { - "access": "private", - "destination": "51978493292659230", - "label": "aboolfloat", - "source": "1192822659863756768", - "type": "aggregation" - }, - { - "access": "public", - "destination": "197769253782961588", - "source": "1192822659863756768", - "type": "dependency" - }, - { - "access": "private", - "destination": "197769253782961588", - "label": "afloat", - "source": "1192822659863756768", - "type": "association" - }, - { - "access": "private", - "destination": "895940711566401184", - "label": "boolstring", - "source": "1192822659863756768", - "type": "aggregation" - }, - { - "access": "private", - "destination": "1751732625010742161", - "label": "floatstring", - "source": "1192822659863756768", - "type": "aggregation" - }, - { - "access": "private", - "destination": "887121441210847583", - "label": "intstring", - "source": "1192822659863756768", - "type": "aggregation" - }, - { - "access": "private", - "destination": "1119452495635561975", - "label": "stringstring", - "source": "1192822659863756768", - "type": "aggregation" - }, - { - "access": "private", - "destination": "1119452495635561975", - "label": "bstringstring", - "source": "1192822659863756768", - "type": "aggregation" - }, - { - "access": "protected", - "destination": "934136012292043506", - "label": "bs", - "source": "1192822659863756768", - "type": "aggregation" - }, - { - "access": "public", - "destination": "934136012292043506", - "label": "bs2", - "source": "1192822659863756768", - "type": "aggregation" - }, - { - "access": "public", - "destination": "640294848489463071", - "source": "1192822659863756768", - "type": "dependency" - }, - { - "access": "public", - "destination": "139599686499155694", - "source": "1192822659863756768", - "type": "dependency" - }, - { - "access": "public", - "destination": "934136012292043506", - "label": "vps", - "source": "1192822659863756768", - "type": "aggregation" - } - ] -} -)##"; auto j = generate_class_json(diagram, *model); - REQUIRE(j == nlohmann::json::parse(expected_json)); + REQUIRE(json::IsClass(j, "clanguml::t00014::A")); + REQUIRE(json::IsClass(j, "clanguml::t00014::A")); + REQUIRE(json::IsClass( + j, "clanguml::t00014::A>")); + REQUIRE(json::IsClass(j, "clanguml::t00014::A")); + REQUIRE(json::IsClass(j, "clanguml::t00014::A")); + REQUIRE(json::IsClass(j, "clanguml::t00014::A")); + REQUIRE(json::IsClass(j, "clanguml::t00014::A")); + REQUIRE(json::IsClass(j, "clanguml::t00014::A")); + REQUIRE(json::IsClass(j, "clanguml::t00014::A")); + REQUIRE(json::IsClass(j, "clanguml::t00014::A")); + REQUIRE(json::IsClass(j, "clanguml::t00014::A")); + REQUIRE(json::IsClass(j, "clanguml::t00014::A")); + REQUIRE(json::IsClass(j, "clanguml::t00014::A")); + REQUIRE(json::IsClass(j, "clanguml::t00014::B")); save_json(config.output_directory() + "/" + diagram->name + ".json", j); } diff --git a/tests/t00036/test_case.h b/tests/t00036/test_case.h index b9b43ec9..ccc91c3c 100644 --- a/tests/t00036/test_case.h +++ b/tests/t00036/test_case.h @@ -47,192 +47,12 @@ TEST_CASE("t00036", "[test-case][class]") save_puml(config.output_directory() + "/" + diagram->name + ".puml", puml); - const std::string expected_json = R"##( -{ - "elements": [ - { - "display_name": "clanguml::t00036::ns1", - "elements": [ - { - "constants": [ - "blue", - "yellow" - ], - "display_name": "clanguml::t00036::ns1::E", - "id": "2144761953049158478", - "is_nested": false, - "name": "E", - "namespace": "clanguml::t00036::ns1", - "source_location": { - "file": "../../tests/t00036/t00036.cc", - "line": 6 - }, - "type": "enum" - }, - { - "display_name": "clanguml::t00036::ns1::ns11", - "elements": [ - { - "bases": [], - "display_name": "clanguml::t00036::ns1::ns11::A", - "id": "571573305652194946", - "is_abstract": false, - "is_nested": false, - "is_struct": true, - "is_template": false, - "is_union": false, - "members": [ - { - "access": "public", - "is_static": false, - "name": "a", - "source_location": { - "file": "../../tests/t00036/t00036.cc", - "line": 11 - }, - "type": "T" - } - ], - "methods": [], - "name": "A", - "namespace": "clanguml::t00036::ns1::ns11", - "source_location": { - "file": "../../tests/t00036/t00036.cc", - "line": 10 - }, - "template_parameters": [ - { - "is_variadic": false, - "kind": "template_type", - "name": "T" - } - ], - "type": "class" - }, - { - "display_name": "clanguml::t00036::ns1::ns11::ns111", - "elements": [ - { - "bases": [], - "display_name": "clanguml::t00036::ns1::ns11::ns111::B", - "id": "1964031933563607376", - "is_abstract": false, - "is_nested": false, - "is_struct": true, - "is_template": false, - "is_union": false, - "members": [ - { - "access": "public", - "is_static": false, - "name": "a_int", - "source_location": { - "file": "../../tests/t00036/t00036.cc", - "line": 17 - }, - "type": "A" - } - ], - "methods": [], - "name": "B", - "namespace": "clanguml::t00036::ns1::ns11::ns111", - "source_location": { - "file": "../../tests/t00036/t00036.cc", - "line": 16 - }, - "template_parameters": [], - "type": "class" - } - ], - "name": "ns111", - "type": "namespace" - }, - { - "bases": [], - "display_name": "clanguml::t00036::ns1::ns11::A", - "id": "1832710427462319797", - "is_abstract": false, - "is_nested": false, - "is_struct": false, - "is_template": false, - "is_union": false, - "members": [], - "methods": [], - "name": "A", - "namespace": "clanguml::t00036::ns1::ns11", - "template_parameters": [ - { - "is_variadic": false, - "kind": "argument", - "type": "int" - } - ], - "type": "class" - } - ], - "name": "ns11", - "type": "namespace" - } - ], - "name": "ns1", - "type": "namespace" - }, - { - "display_name": "clanguml::t00036::ns2", - "elements": [ - { - "display_name": "clanguml::t00036::ns2::ns22", - "elements": [ - { - "bases": [], - "display_name": "clanguml::t00036::ns2::ns22::C", - "id": "2038956882066165590", - "is_abstract": false, - "is_nested": false, - "is_struct": true, - "is_template": false, - "is_union": false, - "members": [], - "methods": [], - "name": "C", - "namespace": "clanguml::t00036::ns2::ns22", - "source_location": { - "file": "../../tests/t00036/t00036.cc", - "line": 28 - }, - "template_parameters": [], - "type": "class" - } - ], - "name": "ns22", - "type": "namespace" - } - ], - "name": "ns2", - "type": "namespace" - } - ], - "relationships": [ - { - "access": "public", - "destination": "1832710427462319797", - "label": "a_int", - "source": "1964031933563607376", - "type": "aggregation" - }, - { - "access": "public", - "destination": "571573305652194946", - "source": "1832710427462319797", - "type": "instantiation" - } - ] -} -)##"; - auto j = generate_class_json(diagram, *model); - REQUIRE(j == nlohmann::json::parse(expected_json)); + // REQUIRE(json::IsClass(j, "clanguml::t00036::A")); + // REQUIRE(json::IsClass(j, "clanguml::t00036::A")); + // REQUIRE(json::IsClass(j, "clanguml::t00036::B")); + // REQUIRE(json::IsClass(j, "clanguml::t00036::C")); save_json(config.output_directory() + "/" + diagram->name + ".json", j); } diff --git a/tests/t00056/test_case.h b/tests/t00056/test_case.h index 655f3dff..9cab7b7e 100644 --- a/tests/t00056/test_case.h +++ b/tests/t00056/test_case.h @@ -115,526 +115,11 @@ TEST_CASE("t00056", "[test-case][class]") save_puml(config.output_directory() + "/" + diagram->name + ".puml", puml); - const std::string expected_json = R"##( -{ - "elements": [ - { - "display_name": "clanguml::t00056::greater_than_simple", - "id": "902541696362244204", - "name": "greater_than_simple", - "namespace": "clanguml::t00056", - "parameters": [], - "source_location": { - "file": "../../tests/t00056/t00056.cc", - "line": 7 - }, - "statements": [], - "type": "concept" - }, - { - "display_name": "clanguml::t00056::greater_than_with_requires", - "id": "1830716585637735576", - "name": "greater_than_with_requires", - "namespace": "clanguml::t00056", - "parameters": [ - { - "name": "clanguml::t00056::l", - "type": "T" - }, - { - "name": "clanguml::t00056::r", - "type": "P" - } - ], - "source_location": { - "file": "../../tests/t00056/t00056.cc", - "line": 10 - }, - "statements": [ - "sizeof (l) > sizeof (r)" - ], - "type": "concept" - }, - { - "display_name": "clanguml::t00056::max_four_bytes", - "id": "385255522691733325", - "name": "max_four_bytes", - "namespace": "clanguml::t00056", - "parameters": [], - "source_location": { - "file": "../../tests/t00056/t00056.cc", - "line": 15 - }, - "statements": [], - "type": "concept" - }, - { - "display_name": "clanguml::t00056::iterable", - "id": "392540961352249242", - "name": "iterable", - "namespace": "clanguml::t00056", - "parameters": [ - { - "name": "clanguml::t00056::container", - "type": "T" - } - ], - "source_location": { - "file": "../../tests/t00056/t00056.cc", - "line": 19 - }, - "statements": [ - "container.begin()", - "container.end()" - ], - "type": "concept" - }, - { - "display_name": "clanguml::t00056::has_value_type", - "id": "1850394311226276678", - "name": "has_value_type", - "namespace": "clanguml::t00056", - "parameters": [], - "source_location": { - "file": "../../tests/t00056/t00056.cc", - "line": 26 - }, - "statements": [ - "typename T::value_type" - ], - "type": "concept" - }, - { - "display_name": "clanguml::t00056::convertible_to_string", - "id": "137304962071054497", - "name": "convertible_to_string", - "namespace": "clanguml::t00056", - "parameters": [ - { - "name": "clanguml::t00056::s", - "type": "T" - } - ], - "source_location": { - "file": "../../tests/t00056/t00056.cc", - "line": 29 - }, - "statements": [ - "std::string{s}", - "{std::to_string(s)} noexcept", - "{std::to_string(s)} -> std::same_as" - ], - "type": "concept" - }, - { - "display_name": "clanguml::t00056::iterable_with_value_type", - "id": "1043398062146751019", - "name": "iterable_with_value_type", - "namespace": "clanguml::t00056", - "parameters": [], - "source_location": { - "file": "../../tests/t00056/t00056.cc", - "line": 45 - }, - "statements": [], - "type": "concept" - }, - { - "display_name": "clanguml::t00056::iterable_or_small_value_type", - "id": "866345615551223718", - "name": "iterable_or_small_value_type", - "namespace": "clanguml::t00056", - "parameters": [], - "source_location": { - "file": "../../tests/t00056/t00056.cc", - "line": 48 - }, - "statements": [], - "type": "concept" - }, - { - "bases": [], - "display_name": "clanguml::t00056::A", - "id": "1418333499545421661", - "is_abstract": false, - "is_nested": false, - "is_struct": true, - "is_template": false, - "is_union": false, - "members": [ - { - "access": "public", - "is_static": false, - "name": "a", - "source_location": { - "file": "../../tests/t00056/t00056.cc", - "line": 53 - }, - "type": "T" - } - ], - "methods": [], - "name": "A", - "namespace": "clanguml::t00056", - "source_location": { - "file": "../../tests/t00056/t00056.cc", - "line": 52 - }, - "template_parameters": [ - { - "is_variadic": false, - "kind": "template_type", - "name": "T" - } - ], - "type": "class" - }, - { - "bases": [], - "display_name": "clanguml::t00056::B", - "id": "1814355496814977880", - "is_abstract": false, - "is_nested": false, - "is_struct": true, - "is_template": false, - "is_union": false, - "members": [ - { - "access": "public", - "is_static": false, - "name": "b", - "source_location": { - "file": "../../tests/t00056/t00056.cc", - "line": 60 - }, - "type": "T" - } - ], - "methods": [], - "name": "B", - "namespace": "clanguml::t00056", - "source_location": { - "file": "../../tests/t00056/t00056.cc", - "line": 59 - }, - "template_parameters": [ - { - "is_variadic": false, - "kind": "template_type", - "name": "T" - } - ], - "type": "class" - }, - { - "bases": [], - "display_name": "clanguml::t00056::C", - "id": "1512618198241549089", - "is_abstract": false, - "is_nested": false, - "is_struct": true, - "is_template": false, - "is_union": false, - "members": [ - { - "access": "public", - "is_static": false, - "name": "c", - "source_location": { - "file": "../../tests/t00056/t00056.cc", - "line": 70 - }, - "type": "T" - } - ], - "methods": [], - "name": "C", - "namespace": "clanguml::t00056", - "source_location": { - "file": "../../tests/t00056/t00056.cc", - "line": 69 - }, - "template_parameters": [ - { - "is_variadic": false, - "kind": "template_type", - "name": "T" - } - ], - "type": "class" - }, - { - "bases": [], - "display_name": "clanguml::t00056::D", - "id": "1635109601630198093", - "is_abstract": false, - "is_nested": false, - "is_struct": true, - "is_template": false, - "is_union": false, - "members": [], - "methods": [], - "name": "D", - "namespace": "clanguml::t00056", - "source_location": { - "file": "../../tests/t00056/t00056.cc", - "line": 75 - }, - "template_parameters": [ - { - "is_variadic": false, - "kind": "template_type", - "name": "T1" - }, - { - "is_variadic": false, - "kind": "template_type", - "name": "T2" - }, - { - "is_variadic": false, - "kind": "template_type", - "name": "T3" - }, - { - "is_variadic": false, - "kind": "template_type", - "name": "T4" - }, - { - "is_variadic": false, - "kind": "template_type", - "name": "T5" - } - ], - "type": "class" - }, - { - "bases": [], - "display_name": "clanguml::t00056::E", - "id": "1429225801945621089", - "is_abstract": false, - "is_nested": false, - "is_struct": true, - "is_template": false, - "is_union": false, - "members": [ - { - "access": "public", - "is_static": false, - "name": "e1", - "source_location": { - "file": "../../tests/t00056/t00056.cc", - "line": 80 - }, - "type": "T1" - }, - { - "access": "public", - "is_static": false, - "name": "e2", - "source_location": { - "file": "../../tests/t00056/t00056.cc", - "line": 81 - }, - "type": "T2" - }, - { - "access": "public", - "is_static": false, - "name": "e3", - "source_location": { - "file": "../../tests/t00056/t00056.cc", - "line": 82 - }, - "type": "T3" - } - ], - "methods": [], - "name": "E", - "namespace": "clanguml::t00056", - "source_location": { - "file": "../../tests/t00056/t00056.cc", - "line": 79 - }, - "template_parameters": [ - { - "is_variadic": false, - "kind": "template_type", - "name": "T1" - }, - { - "is_variadic": false, - "kind": "template_type", - "name": "T2" - }, - { - "is_variadic": false, - "kind": "template_type", - "name": "T3" - } - ], - "type": "class" - }, - { - "bases": [], - "display_name": "clanguml::t00056::F", - "id": "856301122972546034", - "is_abstract": false, - "is_nested": false, - "is_struct": true, - "is_template": false, - "is_union": false, - "members": [ - { - "access": "public", - "is_static": false, - "name": "f1", - "source_location": { - "file": "../../tests/t00056/t00056.cc", - "line": 88 - }, - "type": "T1" - }, - { - "access": "public", - "is_static": false, - "name": "f2", - "source_location": { - "file": "../../tests/t00056/t00056.cc", - "line": 89 - }, - "type": "T2" - }, - { - "access": "public", - "is_static": false, - "name": "f3", - "source_location": { - "file": "../../tests/t00056/t00056.cc", - "line": 90 - }, - "type": "T3" - } - ], - "methods": [], - "name": "F", - "namespace": "clanguml::t00056", - "source_location": { - "file": "../../tests/t00056/t00056.cc", - "line": 87 - }, - "template_parameters": [ - { - "is_variadic": false, - "kind": "template_type", - "name": "T1" - }, - { - "is_variadic": false, - "kind": "template_type", - "name": "T2" - }, - { - "is_variadic": false, - "kind": "template_type", - "name": "T3" - } - ], - "type": "class" - } - ], - "relationships": [ - { - "destination": "385255522691733325", - "label": "T", - "source": "137304962071054497", - "type": "constraint" - }, - { - "destination": "392540961352249242", - "label": "T", - "source": "1043398062146751019", - "type": "constraint" - }, - { - "destination": "1850394311226276678", - "label": "T", - "source": "1043398062146751019", - "type": "constraint" - }, - { - "destination": "1043398062146751019", - "label": "T", - "source": "866345615551223718", - "type": "constraint" - }, - { - "destination": "385255522691733325", - "label": "T", - "source": "866345615551223718", - "type": "constraint" - }, - { - "destination": "385255522691733325", - "label": "T", - "source": "1418333499545421661", - "type": "constraint" - }, - { - "destination": "866345615551223718", - "label": "T", - "source": "1814355496814977880", - "type": "constraint" - }, - { - "destination": "137304962071054497", - "label": "T", - "source": "1512618198241549089", - "type": "constraint" - }, - { - "destination": "392540961352249242", - "label": "T1", - "source": "1635109601630198093", - "type": "constraint" - }, - { - "destination": "392540961352249242", - "label": "T3", - "source": "1635109601630198093", - "type": "constraint" - }, - { - "destination": "385255522691733325", - "label": "T2", - "source": "1635109601630198093", - "type": "constraint" - }, - { - "destination": "385255522691733325", - "label": "T5", - "source": "1635109601630198093", - "type": "constraint" - }, - { - "destination": "1830716585637735576", - "label": "T1,T3", - "source": "1429225801945621089", - "type": "constraint" - }, - { - "destination": "902541696362244204", - "label": "T1,T3", - "source": "856301122972546034", - "type": "constraint" - } - ] -} -)##"; auto j = generate_class_json(diagram, *model); - REQUIRE(j == nlohmann::json::parse(expected_json)); + // REQUIRE(json::IsClass(j, "clanguml::t00014::A")); + // REQUIRE(json::IsClass(j, "clanguml::t00014::B")); + // REQUIRE(json::IsClass(j, "clanguml::t00014::C")); save_json(config.output_directory() + "/" + diagram->name + ".json", j); } \ No newline at end of file diff --git a/tests/t20029/test_case.h b/tests/t20029/test_case.h index d6e54ee5..f2c0e311 100644 --- a/tests/t20029/test_case.h +++ b/tests/t20029/test_case.h @@ -58,230 +58,7 @@ TEST_CASE("t20029", "[test-case][sequence]") save_puml(config.output_directory() + "/" + diagram->name + ".puml", puml); - const std::string expected_json = R"###( -{ - "diagram_type": "sequence", - "name": "t20029_sequence", - "participants": [ - { - "id": "2091374738808319642", - "name": "clanguml::t20029::tmain()", - "source_location": { - "file": "../../tests/t20029/t20029.cc", - "line": 55 - }, - "type": "function" - }, - { - "id": "1673261195873192383", - "name": "clanguml::t20029::Encoder>", - "source_location": { - "file": "../../tests/t20029/t20029.cc", - "line": 11 - }, - "type": "class" - }, - { - "id": "658058855590948094", - "name": "clanguml::t20029::Retrier", - "source_location": { - "file": "../../tests/t20029/t20029.cc", - "line": 22 - }, - "type": "class" - }, - { - "id": "1896406205097618937", - "name": "clanguml::t20029::ConnectionPool", - "source_location": { - "file": "../../tests/t20029/t20029.cc", - "line": 39 - }, - "type": "class" - }, - { - "id": "1362646431260879440", - "name": "clanguml::t20029::encode_b64(std::string &&)", - "source_location": { - "file": "../../tests/t20029/t20029.cc", - "line": 9 - }, - "type": "function" - } - ], - "sequences": [ - { - "messages": [ - { - "from": { - "id": "2091374738808319642", - "name": "clanguml::t20029::tmain()" - }, - "name": "connect()", - "return_type": "void", - "scope": "normal", - "source_location": { - "file": "../../tests/t20029/t20029.cc", - "line": 59 - }, - "to": { - "activity_id": "940428568182104530", - "activity_name": "clanguml::t20029::ConnectionPool::connect()", - "participant_id": "1896406205097618937", - "participant_name": "clanguml::t20029::ConnectionPool" - }, - "type": "message" - }, - { - "activity_id": "2091374738808319642", - "messages": [ - { - "activity_id": "2091374738808319642", - "branches": [ - { - "messages": [ - { - "from": { - "id": "2091374738808319642", - "name": "clanguml::t20029::tmain()" - }, - "name": "send(std::string &&)", - "return_type": "_Bool", - "scope": "condition", - "source_location": { - "file": "../../tests/t20029/t20029.cc", - "line": 62 - }, - "to": { - "activity_id": "2026763864005979273", - "activity_name": "clanguml::t20029::Encoder>::send(std::string &&)", - "participant_id": "1673261195873192383", - "participant_name": "clanguml::t20029::Encoder>" - }, - "type": "message" - }, - { - "from": { - "id": "2026763864005979273", - "name": "clanguml::t20029::Encoder>::send(std::string &&)" - }, - "name": "encode(std::string &&)", - "return_type": "std::string", - "scope": "normal", - "source_location": { - "file": "../../tests/t20029/t20029.cc", - "line": 15 - }, - "to": { - "activity_id": "1468258269466480773", - "activity_name": "clanguml::t20029::Encoder>::encode(std::string &&)", - "participant_id": "1673261195873192383", - "participant_name": "clanguml::t20029::Encoder>" - }, - "type": "message" - }, - { - "from": { - "id": "1468258269466480773", - "name": "clanguml::t20029::Encoder>::encode(std::string &&)" - }, - "name": "", - "return_type": "", - "scope": "normal", - "source_location": { - "file": "../../tests/t20029/t20029.cc", - "line": 19 - }, - "to": { - "activity_id": "1362646431260879440", - "activity_name": "clanguml::t20029::encode_b64(std::string &&)" - }, - "type": "message" - }, - { - "from": { - "id": "2026763864005979273", - "name": "clanguml::t20029::Encoder>::send(std::string &&)" - }, - "name": "send(std::string &&)", - "return_type": "_Bool", - "scope": "normal", - "source_location": { - "file": "../../tests/t20029/t20029.cc", - "line": 15 - }, - "to": { - "activity_id": "30515971485361302", - "activity_name": "clanguml::t20029::Retrier::send(std::string &&)", - "participant_id": "658058855590948094", - "participant_name": "clanguml::t20029::Retrier" - }, - "type": "message" - }, - { - "activity_id": "30515971485361302", - "messages": [ - { - "activity_id": "30515971485361302", - "branches": [ - { - "messages": [ - { - "from": { - "id": "30515971485361302", - "name": "clanguml::t20029::Retrier::send(std::string &&)" - }, - "name": "send(const std::string &)", - "return_type": "_Bool", - "scope": "condition", - "source_location": { - "file": "../../tests/t20029/t20029.cc", - "line": 31 - }, - "to": { - "activity_id": "972625940114169157", - "activity_name": "clanguml::t20029::ConnectionPool::send(const std::string &)", - "participant_id": "1896406205097618937", - "participant_name": "clanguml::t20029::ConnectionPool" - }, - "type": "message" - } - ], - "type": "consequent" - } - ], - "name": "if", - "type": "alt" - } - ], - "name": "while", - "type": "loop" - } - ], - "type": "consequent" - } - ], - "name": "if", - "type": "alt" - } - ], - "name": "for", - "type": "loop" - } - ], - "start_from": { - "id": 2091374738808319700, - "location": "clanguml::t20029::tmain()" - } - } - ], - "using_namespace": "clanguml::t20029" -} -)###"; - auto j = generate_sequence_json(diagram, *model); - REQUIRE(j == nlohmann::json::parse(expected_json)); - save_json(config.output_directory() + "/" + diagram->name + ".json", j); } \ No newline at end of file diff --git a/tests/test_cases.h b/tests/test_cases.h index d520d6d0..e53ef0b7 100644 --- a/tests/test_cases.h +++ b/tests/test_cases.h @@ -77,6 +77,15 @@ using Catch::Matchers::StdString::CasedString; using Catch::Matchers::StdString::ContainsMatcher; using Catch::Matchers::StdString::RegexMatcher; +struct JsonMatcherBase : Catch::MatcherBase { + JsonMatcherBase( + std::string const &operation, CasedString const &comparator); + std::string describe() const override; + + CasedString m_comparator; + std::string m_operation; +}; + template constexpr bool has_type() noexcept { return (std::is_same_v || ... || false); @@ -589,6 +598,125 @@ ContainsMatcher IsDeprecated(std::string const &str, return ContainsMatcher( CasedString(str + " <> ", caseSensitivity)); } + +namespace json { +namespace detail { +auto get_element(const nlohmann::json &j, const std::string &name) +{ + return std::find_if(j["elements"].begin(), j["elements"].end(), + [&](const auto &it) { return it["display_name"] == name; }); +} + +auto get_relationship(const nlohmann::json &j, const nlohmann::json &from, + const nlohmann::json &to, const std::string &type) +{ + return std::find_if(j["relationships"].begin(), j["relationships"].end(), + [&](const auto &it) { + return (it["source"] == from) && (it["destination"] == to) && + (it["type"] == type); + }); +} + +auto get_relationship(const nlohmann::json &j, const std::string &from, + const std::string &to, const std::string &type) +{ + auto from_it = detail::get_element(j, from); + auto to_it = detail::get_element(j, to); + + if (from_it == j["elements"].end() || to_it == j["elements"].end()) + return j["relationships"].end(); + + return detail::get_relationship( + j, from_it->at("id"), to_it->at("id"), type); +} +} // namespace detail + +bool IsClass(const nlohmann::json &j, const std::string &name) +{ + return detail::get_element(j, name) != j["elements"].end(); +} + +bool IsBaseClass(const nlohmann::json &j, const std::string &base, + const std::string &subclass) +{ + auto sc = detail::get_element(j, subclass); + + if (sc == j["elements"].end()) + return false; + + const nlohmann::json &bases = (*sc)["bases"]; + + return std::find_if(bases.begin(), bases.end(), [&](const auto &it) { + return it["name"] == base; + }) != bases.end(); +} + +bool IsMethod( + const nlohmann::json &j, const std::string &cls, const std::string &name) +{ + auto sc = detail::get_element(j, cls); + + if (sc == j["elements"].end()) + return false; + + const nlohmann::json &methods = (*sc)["methods"]; + + return std::find_if(methods.begin(), methods.end(), [&](const auto &it) { + return it["name"] == name; + }) != methods.end(); +} + +bool IsAssociation(nlohmann::json j, const std::string &from, + const std::string &to, const std::string &label = "") +{ + auto rel = detail::get_relationship(j, from, to, "association"); + + if (rel == j["relationships"].end()) + return false; + + if (!label.empty() && rel->at("label") != label) + return false; + + return true; +} + +bool IsComposition(nlohmann::json j, const std::string &from, + const std::string &to, const std::string &label = "") +{ + auto rel = detail::get_relationship(j, from, to, "composition"); + + if (rel == j["relationships"].end()) + return false; + + if (!label.empty() && rel->at("label") != label) + return false; + + return true; +} + +bool IsAggregation(nlohmann::json j, const std::string &from, + const std::string &to, const std::string &label = "") +{ + auto rel = detail::get_relationship(j, from, to, "aggregation"); + + if (rel == j["relationships"].end()) + return false; + + if (!label.empty() && rel->at("label") != label) + return false; + + return true; +} + +bool IsDependency( + nlohmann::json j, const std::string &from, const std::string &to) +{ + auto rel = detail::get_relationship(j, from, to, "aggregation"); + + return rel != j["relationships"].end(); +} + +} // namespace json } } }