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 (1501B)
0 #include "hemplate/common.hpp"
2 #include <catch2/catch_test_macros.hpp>
4 TEST_CASE("comment", "[common/comment]")
5 {
6 const hemplate::comment comment {"hello world"};
8 REQUIRE(std::string(comment) == "<-- hello world -->\n");
9 }
11 TEST_CASE("xml", "[common/xml]")
12 {
13 SECTION("default")
14 {
15 const hemplate::xml xml;
17 REQUIRE(
18 std::string(xml) == "<? xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
19 );
20 }
22 SECTION("version")
23 {
24 const hemplate::xml xml {"ver"};
26 REQUIRE(
27 std::string(xml) == "<? xml version=\"ver\" encoding=\"UTF-8\"?>\n"
28 );
29 }
31 SECTION("version encoding")
32 {
33 const hemplate::xml xml {"ver", "utf"};
35 REQUIRE(std::string(xml) == "<? xml version=\"ver\" encoding=\"utf\"?>\n");
36 }
37 }
39 TEST_CASE("transform", "[common/transform]")
40 {
41 using tag = hemplate::element_boolean<"t">;
42 using child = hemplate::element_boolean<"c">;
44 SECTION("direct")
45 {
46 const std::vector<std::string> vec = {"1", "2"};
47 const auto tmp = tag {hemplate::transform(
48 vec,
49 [](const auto& elem)
50 {
51 return child {elem};
52 }
53 )};
55 REQUIRE(std::string(tmp) == "<t>\n <c>1</c>\n <c>2</c>\n</t>\n");
56 }
58 SECTION("indirect")
59 {
60 const std::vector<std::string> vec = {"1", "2"};
61 const auto tmp = tag {hemplate::transform(
62 vec,
63 [](const auto& elem)
64 {
65 return hemplate::element {elem};
66 }
67 )};
69 REQUIRE(std::string(tmp) == "<t>\n 1\n 2\n</t>\n");
70 }
71 }