hemplateSimple XML template engine |
git clone git://git.dimitrijedobrota.com/hemplate.git |
Log | Files | Refs | README | LICENSE | HACKING | CONTRIBUTING | CODE_OF_CONDUCT | BUILDING |
common_test.cpp (1503B)
0 #include "hemplate/common.hpp" 1 2 #include <catch2/catch_test_macros.hpp> 3 4 TEST_CASE("comment", "[common/comment]") 5 { 6 const hemplate::comment comment {"hello world"}; 7 8 REQUIRE(std::string(comment) == "<-- hello world -->\n"); 9 } 10 11 TEST_CASE("xml", "[common/xml]") 12 { 13 SECTION("default") 14 { 15 const hemplate::xml xml; 16 17 REQUIRE( 18 std::string(xml) == "<? xml version=\"1.0\" encoding=\"UTF-8\"?>\n" 19 ); 20 } 21 22 SECTION("version") 23 { 24 const hemplate::xml xml {"ver"}; 25 26 REQUIRE( 27 std::string(xml) == "<? xml version=\"ver\" encoding=\"UTF-8\"?>\n" 28 ); 29 } 30 31 SECTION("version encoding") 32 { 33 const hemplate::xml xml {"ver", "utf"}; 34 35 REQUIRE(std::string(xml) == "<? xml version=\"ver\" encoding=\"utf\"?>\n"); 36 } 37 } 38 39 TEST_CASE("transform", "[common/transform]") 40 { 41 using tag = hemplate::element_boolean<"t">; 42 using child = hemplate::element_boolean<"c">; 43 44 SECTION("direct") 45 { 46 const std::vector<std::string> vec = {"1", "2"}; 47 const auto t = tag {hemplate::transform( 48 vec, 49 [](const auto& e) 50 { 51 return child {e}; 52 } 53 )}; 54 55 REQUIRE( 56 std::string(t) 57 == "<t>\n <c>1</c>\n <c>2</c>\n</t>\n" 58 ); 59 } 60 61 SECTION("indirect") 62 { 63 const std::vector<std::string> vec = {"1", "2"}; 64 const auto t = tag {hemplate::transform( 65 vec, 66 [](const auto& e) 67 { 68 return hemplate::element {e}; 69 } 70 )}; 71 72 REQUIRE(std::string(t) == "<t>\n 1\n 2\n</t>\n"); 73 } 74 }