Added test cases for JSON class generators

This commit is contained in:
Bartek Kryza
2023-03-22 01:00:04 +01:00
parent c59fbfa565
commit 491fb2b443
51 changed files with 377 additions and 29 deletions

View File

@@ -61,6 +61,7 @@ void to_json(nlohmann::json &j, const template_parameter &c)
if (c.default_value()) if (c.default_value())
j["default"] = c.default_value().value(); j["default"] = c.default_value().value();
j["is_variadic"] = c.is_variadic(); j["is_variadic"] = c.is_variadic();
j["template_parameters"] = c.template_params();
} }
void to_json(nlohmann::json &j, const relationship &c) void to_json(nlohmann::json &j, const relationship &c)

View File

@@ -91,7 +91,7 @@ TEST_CASE("t00002", "[test-case][class]")
REQUIRE(IsBaseClass(j, "C", "D")); REQUIRE(IsBaseClass(j, "C", "D"));
REQUIRE(IsMethod(j, "A", "foo_a")); REQUIRE(IsMethod(j, "A", "foo_a"));
REQUIRE(IsMethod(j, "C", "foo_c")); REQUIRE(IsMethod(j, "C", "foo_c"));
REQUIRE(IsMember(j, "E", "as", "std::vector<A *>")); REQUIRE(IsField(j, "E", "as", "std::vector<A *>"));
REQUIRE(IsAssociation(j, "D", "A", "as")); REQUIRE(IsAssociation(j, "D", "A", "as"));
save_json(config.output_directory() + "/" + diagram->name + ".json", j); save_json(config.output_directory() + "/" + diagram->name + ".json", j);

View File

@@ -61,7 +61,15 @@ TEST_CASE("t00009", "[test-case][class]")
using namespace json; using namespace json;
REQUIRE(IsClass(j, "A<T>")); REQUIRE(IsClassTemplate(j, "A<T>"));
REQUIRE(IsClass(j, "A<int>"));
REQUIRE(IsClass(j, "A<std::string>"));
REQUIRE(IsClass(j, "A<std::vector<std::string>>"));
REQUIRE(IsField(j, "A<T>", "value", "T"));
REQUIRE(IsField(j, "B", "aint", "A<int>"));
REQUIRE(IsField(j, "B", "astring", "A<std::string> *"));
REQUIRE(IsField(j, "B", "avector", "A<std::vector<std::string>> &"));
save_json(config.output_directory() + "/" + diagram->name + ".json", j); save_json(config.output_directory() + "/" + diagram->name + ".json", j);
} }

View File

@@ -56,6 +56,14 @@ TEST_CASE("t00010", "[test-case][class]")
using namespace json; using namespace json;
REQUIRE(IsClassTemplate(j, "A<T,P>"));
REQUIRE(IsClassTemplate(j, "B<T>"));
REQUIRE(IsClass(j, "B<int>"));
REQUIRE(IsClass(j, "A<T,std::string>"));
REQUIRE(IsClass(j, "B<int>"));
REQUIRE(IsField(j, "C", "aintstring", "B<int>"));
save_json(config.output_directory() + "/" + diagram->name + ".json", j); save_json(config.output_directory() + "/" + diagram->name + ".json", j);
} }
} }

View File

@@ -51,6 +51,11 @@ TEST_CASE("t00011", "[test-case][class]")
using namespace json; using namespace json;
REQUIRE(IsClass(j, "A"));
REQUIRE(IsClass(j, "B"));
REQUIRE(IsClassTemplate(j, "D<T>"));
REQUIRE(IsFriend(j, "A", "B"));
save_json(config.output_directory() + "/" + diagram->name + ".json", j); save_json(config.output_directory() + "/" + diagram->name + ".json", j);
} }
} }

View File

@@ -54,6 +54,14 @@ TEST_CASE("t00012", "[test-case][class]")
using namespace json; using namespace json;
REQUIRE(IsClassTemplate(j, "A<T,Ts...>"));
REQUIRE(IsClassTemplate(j, "B<int... Is>"));
REQUIRE(IsClass(j, "A<int,std::string,float>"));
REQUIRE(IsClass(j, "A<int,std::string,bool>"));
REQUIRE(IsClass(j,
"C<std::map<int,std::vector<std::vector<std::vector<std::string>>>>"
",3,3,3>"));
save_json(config.output_directory() + "/" + diagram->name + ".json", j); save_json(config.output_directory() + "/" + diagram->name + ".json", j);
} }
} }

View File

@@ -73,6 +73,19 @@ TEST_CASE("t00013", "[test-case][class]")
using namespace json; using namespace json;
REQUIRE(IsClass(j, "A"));
REQUIRE(IsClass(j, "B"));
REQUIRE(IsClass(j, "C"));
REQUIRE(IsClass(j, "D"));
REQUIRE(IsInstantiation(j, "E<T>", "E<int>"));
REQUIRE(IsDependency(j, "R", "A"));
REQUIRE(IsDependency(j, "R", "B"));
REQUIRE(IsDependency(j, "R", "C"));
REQUIRE(IsDependency(j, "R", "D"));
REQUIRE(IsDependency(j, "D", "R"));
REQUIRE(IsDependency(j, "R", "E<int>"));
REQUIRE(IsInstantiation(j, "G<T,Args...>", "G<int,float,std::string>"));
save_json(config.output_directory() + "/" + diagram->name + ".json", j); save_json(config.output_directory() + "/" + diagram->name + ".json", j);
} }
} }

View File

@@ -49,6 +49,12 @@ TEST_CASE("t00015", "[test-case][class]")
using namespace json; using namespace json;
REQUIRE(IsClass(j, "ns1::A"));
REQUIRE(IsClass(j, "ns1::ns2_v0_9_0::A"));
REQUIRE(IsClass(j, "ns1::Anon"));
REQUIRE(IsClass(j, "ns3::ns1::ns2::Anon"));
REQUIRE(IsClass(j, "ns3::B"));
save_json(config.output_directory() + "/" + diagram->name + ".json", j); save_json(config.output_directory() + "/" + diagram->name + ".json", j);
} }
} }

View File

@@ -58,6 +58,12 @@ TEST_CASE("t00016", "[test-case][class]")
using namespace json; using namespace json;
REQUIRE(IsClassTemplate(j, "is_numeric<>"));
REQUIRE(IsClass(j, "is_numeric<int>"));
REQUIRE(IsClass(j, "is_numeric<bool>"));
REQUIRE(IsClass(j, "is_numeric<char>"));
REQUIRE(IsClass(j, "is_numeric<float>"));
save_json(config.output_directory() + "/" + diagram->name + ".json", j); save_json(config.output_directory() + "/" + diagram->name + ".json", j);
} }
} }

View File

@@ -76,6 +76,19 @@ TEST_CASE("t00017", "[test-case][class]")
using namespace json; using namespace json;
REQUIRE(IsClass(j, "A"));
REQUIRE(IsClass(j, "B"));
REQUIRE(IsClass(j, "C"));
REQUIRE(IsClass(j, "D"));
REQUIRE(IsClass(j, "E"));
REQUIRE(IsClass(j, "F"));
REQUIRE(IsClass(j, "G"));
REQUIRE(IsClass(j, "H"));
REQUIRE(IsClass(j, "I"));
REQUIRE(IsClass(j, "J"));
REQUIRE(IsClass(j, "K"));
REQUIRE(IsClass(j, "R"));
save_json(config.output_directory() + "/" + diagram->name + ".json", j); save_json(config.output_directory() + "/" + diagram->name + ".json", j);
} }
} }

View File

@@ -50,6 +50,10 @@ TEST_CASE("t00018", "[test-case][class]")
using namespace json; using namespace json;
REQUIRE(IsClass(j, "widget"));
REQUIRE(IsClass(j, "impl::widget"));
REQUIRE(IsDependency(j, "impl::widget", "widget"));
save_json(config.output_directory() + "/" + diagram->name + ".json", j); save_json(config.output_directory() + "/" + diagram->name + ".json", j);
} }
} }

View File

@@ -65,6 +65,11 @@ TEST_CASE("t00019", "[test-case][class]")
using namespace json; using namespace json;
REQUIRE(IsClass(j, "Base"));
REQUIRE(IsClassTemplate(j, "Layer1<LowerLayer>"));
REQUIRE(IsClassTemplate(j, "Layer2<LowerLayer>"));
REQUIRE(IsClassTemplate(j, "Layer3<LowerLayer>"));
save_json(config.output_directory() + "/" + diagram->name + ".json", j); save_json(config.output_directory() + "/" + diagram->name + ".json", j);
} }
} }

View File

@@ -53,6 +53,12 @@ TEST_CASE("t00020", "[test-case][class]")
using namespace json; using namespace json;
REQUIRE(IsClass(j, "ProductA1"));
REQUIRE(IsClass(j, "ProductA2"));
REQUIRE(IsClass(j, "ProductB1"));
REQUIRE(IsClass(j, "ProductB2"));
REQUIRE(IsAbstractClass(j, "AbstractFactory"));
save_json(config.output_directory() + "/" + diagram->name + ".json", j); save_json(config.output_directory() + "/" + diagram->name + ".json", j);
} }
} }

View File

@@ -51,6 +51,10 @@ TEST_CASE("t00021", "[test-case][class]")
using namespace json; using namespace json;
REQUIRE(IsClass(j, "Visitor1"));
REQUIRE(IsClass(j, "Visitor2"));
REQUIRE(IsAbstractClass(j, "Item"));
save_json(config.output_directory() + "/" + diagram->name + ".json", j); save_json(config.output_directory() + "/" + diagram->name + ".json", j);
} }
} }

View File

@@ -47,6 +47,10 @@ TEST_CASE("t00022", "[test-case][class]")
using namespace json; using namespace json;
REQUIRE(IsClass(j, "A1"));
REQUIRE(IsClass(j, "A2"));
REQUIRE(IsAbstractClass(j, "A"));
save_json(config.output_directory() + "/" + diagram->name + ".json", j); save_json(config.output_directory() + "/" + diagram->name + ".json", j);
} }
} }

View File

@@ -47,6 +47,10 @@ TEST_CASE("t00023", "[test-case][class]")
using namespace json; using namespace json;
REQUIRE(IsClass(j, "StrategyA"));
REQUIRE(IsClass(j, "StrategyB"));
REQUIRE(IsAbstractClass(j, "Strategy"));
save_json(config.output_directory() + "/" + diagram->name + ".json", j); save_json(config.output_directory() + "/" + diagram->name + ".json", j);
} }
} }

View File

@@ -51,6 +51,13 @@ TEST_CASE("t00024", "[test-case][class]")
using namespace json; using namespace json;
REQUIRE(IsClass(j, "Target1"));
REQUIRE(IsClass(j, "Target2"));
REQUIRE(IsAbstractClass(j, "Target"));
REQUIRE(IsBaseClass(j, "Target", "Target1"));
REQUIRE(IsBaseClass(j, "Target", "Target2"));
REQUIRE(IsBaseClass(j, "Target", "Proxy"));
save_json(config.output_directory() + "/" + diagram->name + ".json", j); save_json(config.output_directory() + "/" + diagram->name + ".json", j);
} }
} }

View File

@@ -61,6 +61,12 @@ TEST_CASE("t00025", "[test-case][class]")
using namespace json; using namespace json;
REQUIRE(IsClass(j, "Target1"));
REQUIRE(IsClass(j, "Target2"));
REQUIRE(IsClassTemplate(j, "Proxy<T>"));
REQUIRE(IsDependency(j, "Proxy<clanguml::t00025::Target1>", "Target1"));
REQUIRE(IsDependency(j, "Proxy<clanguml::t00025::Target2>", "Target2"));
save_json(config.output_directory() + "/" + diagram->name + ".json", j); save_json(config.output_directory() + "/" + diagram->name + ".json", j);
} }
} }

View File

@@ -52,6 +52,10 @@ TEST_CASE("t00026", "[test-case][class]")
using namespace json; using namespace json;
REQUIRE(IsClassTemplate(j, "Memento<T>"));
REQUIRE(IsClassTemplate(j, "Originator<T>"));
REQUIRE(IsInstantiation(j, "Originator<T>", "Originator<std::string>"));
save_json(config.output_directory() + "/" + diagram->name + ".json", j); save_json(config.output_directory() + "/" + diagram->name + ".json", j);
} }
} }

View File

@@ -65,6 +65,17 @@ TEST_CASE("t00027", "[test-case][class]")
using namespace json; using namespace json;
REQUIRE(IsAbstractClass(j, "Shape"));
REQUIRE(IsAbstractClass(j, "ShapeDecorator"));
REQUIRE(IsClassTemplate(j, "Line<T<>...>"));
REQUIRE(IsInstantiation(
j, "Line<T<>...>", "Line<clanguml::t00027::Color>"));
REQUIRE(IsInstantiation(j, "Line<T<>...>",
"Line<clanguml::t00027::Color,clanguml::t00027::Weight>"));
REQUIRE(IsAggregation(
j, "Window", "Text<clanguml::t00027::Color>", "description"));
save_json(config.output_directory() + "/" + diagram->name + ".json", j); save_json(config.output_directory() + "/" + diagram->name + ".json", j);
} }
} }

View File

@@ -62,6 +62,8 @@ TEST_CASE("t00029", "[test-case][class]")
using namespace json; using namespace json;
REQUIRE(IsAggregation(j, "R", "G1", "g1"));
save_json(config.output_directory() + "/" + diagram->name + ".json", j); save_json(config.output_directory() + "/" + diagram->name + ".json", j);
} }
} }

View File

@@ -57,6 +57,8 @@ TEST_CASE("t00030", "[test-case][class]")
using namespace json; using namespace json;
REQUIRE(IsAggregation(j, "R", "C", "ccc"));
save_json(config.output_directory() + "/" + diagram->name + ".json", j); save_json(config.output_directory() + "/" + diagram->name + ".json", j);
} }
} }

View File

@@ -62,6 +62,9 @@ TEST_CASE("t00031", "[test-case][class]")
using namespace json; using namespace json;
REQUIRE(IsClass(j, "A"));
REQUIRE(IsClassTemplate(j, "C<T>"));
save_json(config.output_directory() + "/" + diagram->name + ".json", j); save_json(config.output_directory() + "/" + diagram->name + ".json", j);
} }
} }

View File

@@ -62,6 +62,10 @@ TEST_CASE("t00032", "[test-case][class]")
using namespace json; using namespace json;
REQUIRE(IsBaseClass(j, "A",
"Overload<clanguml::t00032::TBase,int,clanguml::t00032::A,clanguml:"
":t00032::B,clanguml::t00032::C>"));
save_json(config.output_directory() + "/" + diagram->name + ".json", j); save_json(config.output_directory() + "/" + diagram->name + ".json", j);
} }
} }

View File

@@ -63,6 +63,14 @@ TEST_CASE("t00033", "[test-case][class]")
using namespace json; using namespace json;
REQUIRE(IsClass(j,
"A<clanguml::t00033::B<std::unique_ptr<clanguml::t00033::C<"
"clanguml::t00033::D>>>>"));
REQUIRE(IsDependency(j,
"A<clanguml::t00033::B<std::unique_ptr<clanguml::t00033::C<"
"clanguml::t00033::D>>>>",
"B<std::unique_ptr<clanguml::t00033::C<clanguml::t00033::D>>>"));
save_json(config.output_directory() + "/" + diagram->name + ".json", j); save_json(config.output_directory() + "/" + diagram->name + ".json", j);
} }
} }

View File

@@ -55,6 +55,9 @@ TEST_CASE("t00034", "[test-case][class]")
using namespace json; using namespace json;
REQUIRE(IsClass(j, "A"));
REQUIRE(IsClassTemplate(j, "lift_void<T>"));
save_json(config.output_directory() + "/" + diagram->name + ".json", j); save_json(config.output_directory() + "/" + diagram->name + ".json", j);
} }
} }

View File

@@ -55,6 +55,12 @@ TEST_CASE("t00035", "[test-case][class]")
using namespace json; using namespace json;
REQUIRE(IsClass(j, "Top"));
REQUIRE(IsClass(j, "Bottom"));
REQUIRE(IsClass(j, "Center"));
REQUIRE(IsClass(j, "Left"));
REQUIRE(IsClass(j, "Right"));
save_json(config.output_directory() + "/" + diagram->name + ".json", j); save_json(config.output_directory() + "/" + diagram->name + ".json", j);
} }
} }

View File

@@ -53,6 +53,12 @@ TEST_CASE("t00037", "[test-case][class]")
using namespace json; using namespace json;
REQUIRE(IsClass(j, "ST"));
REQUIRE(IsClass(j, "A"));
REQUIRE(IsClass(j, "ST::(units)"));
REQUIRE(IsClass(j, "ST::(dimensions)"));
REQUIRE(IsAggregation(j, "ST", "ST::(dimensions)", "dimensions"));
save_json(config.output_directory() + "/" + diagram->name + ".json", j); save_json(config.output_directory() + "/" + diagram->name + ".json", j);
} }
} }

View File

@@ -104,6 +104,10 @@ TEST_CASE("t00038", "[test-case][class]")
using namespace json; using namespace json;
REQUIRE(IsClass(j, "A"));
REQUIRE(IsClass(j, "B"));
REQUIRE(IsClass(j, "C"));
save_json(config.output_directory() + "/" + diagram->name + ".json", j); save_json(config.output_directory() + "/" + diagram->name + ".json", j);
} }
} }

View File

@@ -71,6 +71,19 @@ TEST_CASE("t00039", "[test-case][class]")
using namespace json; using namespace json;
REQUIRE(IsClass(j, "A"));
REQUIRE(IsClass(j, "AA"));
REQUIRE(IsClass(j, "AAA"));
REQUIRE(IsBaseClass(j, "C", "CD"));
REQUIRE(IsBaseClass(j, "D", "CD"));
REQUIRE(IsBaseClass(j, "E", "DE"));
REQUIRE(IsBaseClass(j, "D", "DE"));
REQUIRE(IsBaseClass(j, "C", "CDE"));
REQUIRE(IsBaseClass(j, "D", "CDE"));
REQUIRE(IsBaseClass(j, "E", "CDE"));
REQUIRE(IsClassTemplate(j, "ns3::F<T>"));
save_json(config.output_directory() + "/" + diagram->name + ".json", j); save_json(config.output_directory() + "/" + diagram->name + ".json", j);
} }
} }

View File

@@ -53,6 +53,10 @@ TEST_CASE("t00040", "[test-case][class]")
using namespace json; using namespace json;
REQUIRE(IsClass(j, "A"));
REQUIRE(IsClass(j, "AA"));
REQUIRE(IsClass(j, "AAA"));
save_json(config.output_directory() + "/" + diagram->name + ".json", j); save_json(config.output_directory() + "/" + diagram->name + ".json", j);
} }
} }

View File

@@ -72,6 +72,16 @@ TEST_CASE("t00041", "[test-case][class]")
using namespace json; using namespace json;
REQUIRE(!IsClass(j, "A"));
REQUIRE(!IsClass(j, "AA"));
REQUIRE(!IsClass(j, "AAA"));
REQUIRE(IsClass(j, "D"));
REQUIRE(IsClass(j, "E"));
REQUIRE(IsClass(j, "F"));
REQUIRE(IsClass(j, "R"));
REQUIRE(IsAssociation(j, "D", "RR", "rr"));
save_json(config.output_directory() + "/" + diagram->name + ".json", j); save_json(config.output_directory() + "/" + diagram->name + ".json", j);
} }
} }

View File

@@ -48,6 +48,9 @@ TEST_CASE("t00042", "[test-case][class]")
using namespace json; using namespace json;
REQUIRE(IsClassTemplate(j, "A<T>"));
REQUIRE(IsClassTemplate(j, "B<T,K>"));
save_json(config.output_directory() + "/" + diagram->name + ".json", j); save_json(config.output_directory() + "/" + diagram->name + ".json", j);
} }
} }

View File

@@ -71,6 +71,20 @@ TEST_CASE("t00043", "[test-case][class]")
using namespace json; using namespace json;
REQUIRE(IsClass(j, "dependants::A"));
REQUIRE(IsClass(j, "dependants::B"));
REQUIRE(IsClass(j, "dependants::C"));
REQUIRE(IsClass(j, "dependants::D"));
REQUIRE(IsClass(j, "dependants::BB"));
REQUIRE(IsClass(j, "dependants::E"));
REQUIRE(IsDependency(j, "dependants::B", "dependants::A"));
REQUIRE(IsClass(j, "dependencies::G"));
REQUIRE(IsClass(j, "dependencies::GG"));
REQUIRE(IsClass(j, "dependencies::H"));
REQUIRE(IsDependency(j, "dependencies::J", "dependencies::I"));
REQUIRE(IsDependency(j, "dependencies::H", "dependencies::G"));
save_json(config.output_directory() + "/" + diagram->name + ".json", j); save_json(config.output_directory() + "/" + diagram->name + ".json", j);
} }
} }

View File

@@ -75,6 +75,17 @@ TEST_CASE("t00045", "[test-case][class]")
using namespace json; using namespace json;
REQUIRE(IsClass(j, "A"));
REQUIRE(IsClass(j, "ns1::A"));
REQUIRE(IsClass(j, "ns1::ns2::A"));
REQUIRE(IsClass(j, "ns1::ns2::B"));
REQUIRE(IsClass(j, "ns1::ns2::C"));
REQUIRE(IsClass(j, "ns1::ns2::D"));
REQUIRE(IsClass(j, "ns1::ns2::E"));
REQUIRE(IsClass(j, "ns1::ns2::R"));
REQUIRE(IsBaseClass(j, "ns1::ns2::A", "ns1::ns2::B"));
save_json(config.output_directory() + "/" + diagram->name + ".json", j); save_json(config.output_directory() + "/" + diagram->name + ".json", j);
} }
} }

View File

@@ -51,6 +51,11 @@ TEST_CASE("t00046", "[test-case][class]")
using namespace json; using namespace json;
REQUIRE(get_element(j, "A").value()["type"] == "class");
REQUIRE(get_element(j, "AA").value()["type"] == "class");
REQUIRE(get_element(j, "ns1::A").value()["type"] == "class");
REQUIRE(get_element(j, "ns1::ns2::D").value()["type"] == "class");
save_json(config.output_directory() + "/" + diagram->name + ".json", j); save_json(config.output_directory() + "/" + diagram->name + ".json", j);
} }
} }

View File

@@ -50,6 +50,11 @@ TEST_CASE("t00047", "[test-case][class]")
using namespace json; using namespace json;
REQUIRE(IsClassTemplate(j, "conditional_t<Ts...>"));
REQUIRE(IsClass(j, "conditional_t<Else>"));
REQUIRE(IsClass(j, "conditional_t<std::true_type,Result,Tail...>"));
REQUIRE(IsClass(j, "conditional_t<std::false_type,Result,Tail...>"));
save_json(config.output_directory() + "/" + diagram->name + ".json", j); save_json(config.output_directory() + "/" + diagram->name + ".json", j);
} }
} }

View File

@@ -56,6 +56,13 @@ TEST_CASE("t00048", "[test-case][class]")
using namespace json; using namespace json;
REQUIRE(IsClass(j, "A"));
REQUIRE(IsClass(j, "B"));
REQUIRE(IsClass(j, "ATemplate<T>"));
REQUIRE(IsClass(j, "BTemplate<T>"));
REQUIRE(IsBaseClass(j, "Base", "A"));
REQUIRE(IsBaseClass(j, "Base", "B"));
save_json(config.output_directory() + "/" + diagram->name + ".json", j); save_json(config.output_directory() + "/" + diagram->name + ".json", j);
} }
} }

View File

@@ -64,6 +64,10 @@ TEST_CASE("t00049", "[test-case][class]")
using namespace json; using namespace json;
REQUIRE(IsClass(j, "R"));
REQUIRE(IsClassTemplate(j, "A<T>"));
REQUIRE(IsInstantiation(j, "A<T>", "A<string_vector>"));
save_json(config.output_directory() + "/" + diagram->name + ".json", j); save_json(config.output_directory() + "/" + diagram->name + ".json", j);
} }
} }

View File

@@ -61,6 +61,12 @@ TEST_CASE("t00050", "[test-case][class]")
using namespace json; using namespace json;
REQUIRE(IsClass(j, "A"));
REQUIRE(IsClass(j, "B"));
REQUIRE(IsClass(j, "C"));
REQUIRE(IsClass(j, "utils::D"));
REQUIRE(IsEnum(j, "E"));
save_json(config.output_directory() + "/" + diagram->name + ".json", j); save_json(config.output_directory() + "/" + diagram->name + ".json", j);
} }
} }

View File

@@ -84,6 +84,10 @@ TEST_CASE("t00051", "[test-case][class]")
using namespace json; using namespace json;
REQUIRE(IsClass(j, "A"));
REQUIRE(IsInnerClass(j, "A", "A::custom_thread1"));
REQUIRE(IsInnerClass(j, "A", "A::custom_thread2"));
save_json(config.output_directory() + "/" + diagram->name + ".json", j); save_json(config.output_directory() + "/" + diagram->name + ".json", j);
} }
} }

View File

@@ -56,6 +56,9 @@ TEST_CASE("t00052", "[test-case][class]")
using namespace json; using namespace json;
REQUIRE(IsClass(j, "A"));
REQUIRE(IsClassTemplate(j, "B<T>"));
save_json(config.output_directory() + "/" + diagram->name + ".json", j); save_json(config.output_directory() + "/" + diagram->name + ".json", j);
} }
} }

View File

@@ -61,6 +61,22 @@ TEST_CASE("t00053", "[test-case][class]")
using namespace json; using namespace json;
REQUIRE(IsClass(j, "a"));
REQUIRE(IsClass(j, "b"));
REQUIRE(IsClass(j, "c"));
REQUIRE(IsClass(j, "d"));
REQUIRE(IsClass(j, "e"));
REQUIRE(IsClass(j, "f"));
REQUIRE(IsClass(j, "g"));
REQUIRE(IsClass(j, "A"));
REQUIRE(IsClass(j, "B"));
REQUIRE(IsClass(j, "C"));
REQUIRE(IsClass(j, "D"));
REQUIRE(IsClass(j, "E"));
REQUIRE(IsClass(j, "F"));
REQUIRE(IsClass(j, "G"));
save_json(config.output_directory() + "/" + diagram->name + ".json", j); save_json(config.output_directory() + "/" + diagram->name + ".json", j);
} }
} }

View File

@@ -65,6 +65,26 @@ TEST_CASE("t00054", "[test-case][class]")
using namespace json; using namespace json;
REQUIRE(IsClass(j, "a"));
REQUIRE(IsClass(j, "b"));
REQUIRE(IsClass(j, "detail::c"));
REQUIRE(IsClass(j, "detail::d"));
REQUIRE(IsClass(j, "detail::e"));
REQUIRE(IsClass(j, "f"));
REQUIRE(IsClass(j, "g"));
REQUIRE(IsClass(j, "A"));
REQUIRE(IsClass(j, "B"));
REQUIRE(IsClass(j, "detail2::C"));
REQUIRE(IsClass(j, "detail2::detail3::D"));
REQUIRE(IsClass(j, "detail2::detail3::E"));
REQUIRE(IsClass(j, "detail2::F"));
REQUIRE(IsClass(j, "G"));
REQUIRE(IsEnum(j, "detail4::i"));
REQUIRE(IsEnum(j, "detail4::h"));
REQUIRE(IsEnum(j, "detail4::j"));
save_json(config.output_directory() + "/" + diagram->name + ".json", j); save_json(config.output_directory() + "/" + diagram->name + ".json", j);
} }
} }

View File

@@ -66,6 +66,17 @@ TEST_CASE("t00055", "[test-case][class]")
using namespace json; using namespace json;
REQUIRE(IsClass(j, "A"));
REQUIRE(IsClass(j, "B"));
REQUIRE(IsClass(j, "C"));
REQUIRE(IsClass(j, "D"));
REQUIRE(IsClass(j, "E"));
REQUIRE(IsClass(j, "F"));
REQUIRE(IsClass(j, "G"));
REQUIRE(IsClass(j, "H"));
REQUIRE(IsClass(j, "I"));
REQUIRE(IsClass(j, "J"));
save_json(config.output_directory() + "/" + diagram->name + ".json", j); save_json(config.output_directory() + "/" + diagram->name + ".json", j);
} }
} }

View File

@@ -123,6 +123,15 @@ TEST_CASE("t00056", "[test-case][class]")
using namespace json; using namespace json;
REQUIRE(IsConcept(j, "greater_than_simple<T,L>"));
REQUIRE(IsConcept(j, "greater_than_with_requires<T,P>"));
REQUIRE(IsConcept(j, "max_four_bytes<T>"));
REQUIRE(IsConcept(j, "iterable<T>"));
REQUIRE(IsConcept(j, "has_value_type<T>"));
REQUIRE(IsConcept(j, "convertible_to_string<T>"));
REQUIRE(IsConcept(j, "iterable_with_value_type<T>"));
REQUIRE(IsConcept(j, "iterable_or_small_value_type<T>"));
save_json(config.output_directory() + "/" + diagram->name + ".json", j); save_json(config.output_directory() + "/" + diagram->name + ".json", j);
} }
} }

View File

@@ -65,6 +65,13 @@ TEST_CASE("t00057", "[test-case][class]")
using namespace json; using namespace json;
REQUIRE(get_element(j, "t00057_A").value()["type"] == "class");
REQUIRE(get_element(j, "t00057_B").value()["type"] == "class");
REQUIRE(get_element(j, "t00057_C").value()["type"] == "class");
REQUIRE(get_element(j, "t00057_D").value()["type"] == "class");
REQUIRE(get_element(j, "t00057_E").value()["type"] == "class");
REQUIRE(get_element(j, "t00057_R").value()["type"] == "class");
save_json(config.output_directory() + "/" + diagram->name + ".json", j); save_json(config.output_directory() + "/" + diagram->name + ".json", j);
} }
} }

View File

@@ -75,6 +75,10 @@ TEST_CASE("t00058", "[test-case][class]")
using namespace json; using namespace json;
REQUIRE(IsClass(j, "A<int,int,double,std::string>"));
REQUIRE(IsClass(
j, "B<int,std::string,int,double,clanguml::t00058::A<int,int>>"));
save_json(config.output_directory() + "/" + diagram->name + ".json", j); save_json(config.output_directory() + "/" + diagram->name + ".json", j);
} }
} }

View File

@@ -95,6 +95,10 @@ TEST_CASE("t00059", "[test-case][class]")
using namespace json; using namespace json;
REQUIRE(IsConcept(j, "fruit_c<T>"));
REQUIRE(IsConcept(j, "apple_c<T>"));
REQUIRE(IsConcept(j, "orange_c<T>"));
save_json(config.output_directory() + "/" + diagram->name + ".json", j); save_json(config.output_directory() + "/" + diagram->name + ".json", j);
} }
} }

View File

@@ -55,6 +55,13 @@ TEST_CASE("t00060", "[test-case][class]")
using namespace json; using namespace json;
REQUIRE(IsClass(j, "A"));
REQUIRE(IsClass(j, "B"));
REQUIRE(IsClass(j, "C"));
REQUIRE(IsClass(j, "D"));
REQUIRE(!IsClass(j, "E"));
REQUIRE(!IsClass(j, "F"));
save_json(config.output_directory() + "/" + diagram->name + ".json", j); save_json(config.output_directory() + "/" + diagram->name + ".json", j);
} }
} }

View File

@@ -611,10 +611,12 @@ ContainsMatcher IsDeprecated(std::string const &str,
} }
namespace json { namespace json {
namespace detail {
std::optional<nlohmann::json> get_element( std::optional<nlohmann::json> get_element(
const nlohmann::json &j, const std::string &name) const nlohmann::json &j, const std::string &name)
{ {
if (!j.contains("elements"))
return {};
for (const nlohmann::json &e : j["elements"]) { for (const nlohmann::json &e : j["elements"]) {
if (e["display_name"] == name) if (e["display_name"] == name)
return {e}; return {e};
@@ -642,14 +644,13 @@ auto get_relationship(const nlohmann::json &j, const nlohmann::json &from,
auto get_relationship(const nlohmann::json &j, const std::string &from, auto get_relationship(const nlohmann::json &j, const std::string &from,
const std::string &to, const std::string &type) const std::string &to, const std::string &type)
{ {
auto source = detail::get_element(j, from); auto source = get_element(j, from);
auto destination = detail::get_element(j, to); auto destination = get_element(j, to);
if (!(source && destination)) if (!(source && destination))
return j["relationships"].end(); return j["relationships"].end();
return detail::get_relationship( return get_relationship(j, source->at("id"), destination->at("id"), type);
j, source->at("id"), destination->at("id"), type);
} }
std::string expand_name(const nlohmann::json &j, const std::string &name) std::string expand_name(const nlohmann::json &j, const std::string &name)
@@ -662,36 +663,47 @@ std::string expand_name(const nlohmann::json &j, const std::string &name)
return fmt::format("{}::{}", j["using_namespace"].get<std::string>(), name); return fmt::format("{}::{}", j["using_namespace"].get<std::string>(), name);
} }
} // namespace detail
bool IsClass(const nlohmann::json &j, const std::string &name) bool IsClass(const nlohmann::json &j, const std::string &name)
{ {
auto e = detail::get_element(j, detail::expand_name(j, name)); auto e = get_element(j, expand_name(j, name));
return e && e->at("type") == "class"; return e && e->at("type") == "class";
} }
bool IsAbstractClass(const nlohmann::json &j, const std::string &name)
{
auto e = get_element(j, expand_name(j, name));
return e && (e->at("type") == "class") && (e->at("is_abstract") == true);
}
bool IsClassTemplate(const nlohmann::json &j, const std::string &name) bool IsClassTemplate(const nlohmann::json &j, const std::string &name)
{ {
auto e = detail::get_element(j, detail::expand_name(j, name)); auto e = get_element(j, expand_name(j, name));
return e && e->at("type") == "class" && e->at("is_template") == true; return e && e->at("type") == "class" && e->at("is_template") == true;
} }
bool IsConcept(const nlohmann::json &j, const std::string &name)
{
auto e = get_element(j, expand_name(j, name));
return e && e->at("type") == "concept";
}
bool IsEnum(const nlohmann::json &j, const std::string &name) bool IsEnum(const nlohmann::json &j, const std::string &name)
{ {
auto e = detail::get_element(j, detail::expand_name(j, name)); auto e = get_element(j, expand_name(j, name));
return e && e->at("type") == "enum"; return e && e->at("type") == "enum";
} }
bool IsPackage(const nlohmann::json &j, const std::string &name) bool IsPackage(const nlohmann::json &j, const std::string &name)
{ {
auto e = detail::get_element(j, detail::expand_name(j, name)); auto e = get_element(j, expand_name(j, name));
return e && e->at("type") == "namespace"; return e && e->at("type") == "namespace";
} }
bool IsBaseClass(const nlohmann::json &j, const std::string &base, bool IsBaseClass(const nlohmann::json &j, const std::string &base,
const std::string &subclass) const std::string &subclass)
{ {
auto sc = detail::get_element(j, detail::expand_name(j, subclass)); auto sc = get_element(j, expand_name(j, subclass));
if (!sc) if (!sc)
return false; return false;
@@ -699,14 +711,14 @@ bool IsBaseClass(const nlohmann::json &j, const std::string &base,
const nlohmann::json &bases = (*sc)["bases"]; const nlohmann::json &bases = (*sc)["bases"];
return std::find_if(bases.begin(), bases.end(), [&](const auto &it) { return std::find_if(bases.begin(), bases.end(), [&](const auto &it) {
return it["name"] == detail::expand_name(j, base); return it["name"] == expand_name(j, base);
}) != bases.end(); }) != bases.end();
} }
bool IsMethod( bool IsMethod(
const nlohmann::json &j, const std::string &cls, const std::string &name) const nlohmann::json &j, const std::string &cls, const std::string &name)
{ {
auto sc = detail::get_element(j, detail::expand_name(j, cls)); auto sc = get_element(j, expand_name(j, cls));
if (!sc) if (!sc)
return false; return false;
@@ -718,10 +730,10 @@ bool IsMethod(
}) != methods.end(); }) != methods.end();
} }
bool IsMember(const nlohmann::json &j, const std::string &cls, bool IsField(const nlohmann::json &j, const std::string &cls,
const std::string &name, const std::string &type) const std::string &name, const std::string &type)
{ {
auto sc = detail::get_element(j, detail::expand_name(j, cls)); auto sc = get_element(j, expand_name(j, cls));
if (!sc) if (!sc)
return false; return false;
@@ -736,8 +748,8 @@ bool IsMember(const nlohmann::json &j, const std::string &cls,
bool IsAssociation(nlohmann::json j, const std::string &from, bool IsAssociation(nlohmann::json j, const std::string &from,
const std::string &to, const std::string &label = "") const std::string &to, const std::string &label = "")
{ {
auto rel = detail::get_relationship(j, detail::expand_name(j, from), auto rel = get_relationship(
detail::expand_name(j, to), "association"); j, expand_name(j, from), expand_name(j, to), "association");
if (rel == j["relationships"].end()) if (rel == j["relationships"].end())
return false; return false;
@@ -751,8 +763,8 @@ bool IsAssociation(nlohmann::json j, const std::string &from,
bool IsComposition(nlohmann::json j, const std::string &from, bool IsComposition(nlohmann::json j, const std::string &from,
const std::string &to, const std::string &label = "") const std::string &to, const std::string &label = "")
{ {
auto rel = detail::get_relationship(j, detail::expand_name(j, from), auto rel = get_relationship(
detail::expand_name(j, to), "composition"); j, expand_name(j, from), expand_name(j, to), "composition");
if (rel == j["relationships"].end()) if (rel == j["relationships"].end())
return false; return false;
@@ -766,8 +778,8 @@ bool IsComposition(nlohmann::json j, const std::string &from,
bool IsAggregation(nlohmann::json j, const std::string &from, bool IsAggregation(nlohmann::json j, const std::string &from,
const std::string &to, const std::string &label = "") const std::string &to, const std::string &label = "")
{ {
auto rel = detail::get_relationship(j, detail::expand_name(j, from), auto rel = get_relationship(
detail::expand_name(j, to), "aggregation"); j, expand_name(j, from), expand_name(j, to), "aggregation");
if (rel == j["relationships"].end()) if (rel == j["relationships"].end())
return false; return false;
@@ -781,8 +793,8 @@ bool IsAggregation(nlohmann::json j, const std::string &from,
bool IsDependency( bool IsDependency(
nlohmann::json j, const std::string &from, const std::string &to) nlohmann::json j, const std::string &from, const std::string &to)
{ {
auto rel = detail::get_relationship(j, detail::expand_name(j, from), auto rel = get_relationship(
detail::expand_name(j, to), "aggregation"); j, expand_name(j, from), expand_name(j, to), "dependency");
return rel != j["relationships"].end(); return rel != j["relationships"].end();
} }
@@ -790,8 +802,16 @@ bool IsDependency(
bool IsInstantiation( bool IsInstantiation(
nlohmann::json j, const std::string &from, const std::string &to) nlohmann::json j, const std::string &from, const std::string &to)
{ {
auto rel = detail::get_relationship(j, detail::expand_name(j, to), auto rel = get_relationship(
detail::expand_name(j, from), "instantiation"); j, expand_name(j, to), expand_name(j, from), "instantiation");
return rel != j["relationships"].end();
}
bool IsFriend(nlohmann::json j, const std::string &from, const std::string &to)
{
auto rel = get_relationship(
j, expand_name(j, from), expand_name(j, to), "friendship");
return rel != j["relationships"].end(); return rel != j["relationships"].end();
} }
@@ -799,8 +819,8 @@ bool IsInstantiation(
bool IsInnerClass( bool IsInnerClass(
nlohmann::json j, const std::string &from, const std::string &to) nlohmann::json j, const std::string &from, const std::string &to)
{ {
auto rel = detail::get_relationship(j, detail::expand_name(j, to), auto rel = get_relationship(
detail::expand_name(j, from), "containment"); j, expand_name(j, to), expand_name(j, from), "containment");
return rel != j["relationships"].end(); return rel != j["relationships"].end();
} }