hemplateSimple XML template engine |
git clone git://git.dimitrijedobrota.com/hemplate.git |
Log | Files | Refs | README | LICENSE | HACKING | CONTRIBUTING | CODE_OF_CONDUCT | BUILDING |
attribute_list_test.cpp (2007B)
0 #include "hemplate/attribute.hpp"
2 #include <catch2/catch_test_macros.hpp>
4 // NOLINTBEGIN(*readability-container-size-empty*)
6 TEST_CASE("set class", "[attribute_list]")
7 {
8 hemplate::attribute_list attrs = hemplate::attribute {"class", "first"};
10 REQUIRE(std::string(attrs) == R"(class="first")");
12 SECTION("second")
13 {
14 attrs.set({"class", "second"});
16 REQUIRE(std::string(attrs) == R"(class="first second")");
17 }
19 SECTION("random")
20 {
21 attrs.set({"test"});
23 REQUIRE(std::string(attrs) == R"(class="first" test)");
24 }
25 }
27 TEST_CASE("set style", "[attribute_list]")
28 {
29 hemplate::attribute_list attrs = hemplate::attribute {"style", "first"};
31 REQUIRE(std::string(attrs) == R"(style="first")");
33 SECTION("second")
34 {
35 attrs.set({"style", "second"});
37 REQUIRE(std::string(attrs) == R"(style="first; second")");
38 }
40 SECTION("random")
41 {
42 attrs.set({"test"});
44 REQUIRE(std::string(attrs) == R"(style="first" test)");
45 }
46 }
48 TEST_CASE("set list", "[attribute_list]")
49 {
50 hemplate::attribute_list attrs {
51 {"class", "first"},
52 {"style", "first"},
53 {"test_first"},
54 {"class", "second"},
55 {"style", "second"},
56 {"test_second"},
57 };
59 REQUIRE(
60 std::string(attrs)
61 == R"(class="first second" style="first; second" test_first test_second)"
62 );
64 SECTION("set")
65 {
66 attrs.set({
67 {"class", "third"},
68 {"style", "third"},
69 {"test_third"},
70 });
72 REQUIRE(
73 std::string(attrs)
74 == R"(class="first second third" style="first; second; third" test_first test_second test_third)"
75 );
76 }
77 }
79 TEST_CASE("add", "[attribute_list]")
80 {
81 using namespace std::literals::string_view_literals;
83 const auto tmp = hemplate::attribute_list {{"class", "first"}};
84 const auto attrs = hemplate::attribute_list {
85 tmp, {{"class"sv, "second"sv}, {"class"sv, "third"sv}}
86 };
88 REQUIRE(std::string(attrs) == R"(class="first second third")");
89 }
91 // NOLINTEND(*readability-container-size-empty*)