hemplate

Simple 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" 1 2 #include <catch2/catch_test_macros.hpp> 3 4 // NOLINTBEGIN(*readability-container-size-empty*) 5 6 TEST_CASE("set class", "[attribute_list]") 7 { 8 hemplate::attribute_list attrs = hemplate::attribute {"class", "first"}; 9 10 REQUIRE(std::string(attrs) == R"(class="first")"); 11 12 SECTION("second") 13 { 14 attrs.set({"class", "second"}); 15 16 REQUIRE(std::string(attrs) == R"(class="first second")"); 17 } 18 19 SECTION("random") 20 { 21 attrs.set({"test"}); 22 23 REQUIRE(std::string(attrs) == R"(class="first" test)"); 24 } 25 } 26 27 TEST_CASE("set style", "[attribute_list]") 28 { 29 hemplate::attribute_list attrs = hemplate::attribute {"style", "first"}; 30 31 REQUIRE(std::string(attrs) == R"(style="first")"); 32 33 SECTION("second") 34 { 35 attrs.set({"style", "second"}); 36 37 REQUIRE(std::string(attrs) == R"(style="first; second")"); 38 } 39 40 SECTION("random") 41 { 42 attrs.set({"test"}); 43 44 REQUIRE(std::string(attrs) == R"(style="first" test)"); 45 } 46 } 47 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 }; 58 59 REQUIRE( 60 std::string(attrs) 61 == R"(class="first second" style="first; second" test_first test_second)" 62 ); 63 64 SECTION("set") 65 { 66 attrs.set({ 67 {"class", "third"}, 68 {"style", "third"}, 69 {"test_third"}, 70 }); 71 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 } 78 79 TEST_CASE("add", "[attribute_list]") 80 { 81 using namespace std::literals::string_view_literals; 82 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 }; 87 88 REQUIRE(std::string(attrs) == R"(class="first second third")"); 89 } 90 91 // NOLINTEND(*readability-container-size-empty*)