hemplateSimple XML template engine |
git clone git://git.dimitrijedobrota.com/hemplate.git |
Log | Files | Refs | README | LICENSE | HACKING | CONTRIBUTING | CODE_OF_CONDUCT | BUILDING |
element_test.cpp (5441B)
0 #include "hemplate/element.hpp"
2 #include <catch2/catch_test_macros.hpp>
4 using namespace hemplate; // NOLINT
6 TEST_CASE("boolean", "[element]")
7 {
8 using tag = element_boolean<"tag">;
9 using child = element_boolean<"child">;
11 SECTION("empty")
12 {
13 const auto tmp = tag {};
15 REQUIRE(std::string(tmp) == "<tag>\n</tag>\n");
16 }
18 SECTION("attribute")
19 {
20 const auto tmp = tag {{{"attr", "val"}}};
22 REQUIRE(std::string(tmp) == "<tag attr=\"val\">\n</tag>\n");
23 }
25 SECTION("data")
26 {
27 const auto tmp = tag {"text"};
29 REQUIRE(std::string(tmp) == "<tag>text</tag>\n");
30 }
32 SECTION("attribute data")
33 {
34 const auto tmp = tag {{{"attr", "val"}}, "text"};
36 REQUIRE(std::string(tmp) == "<tag attr=\"val\">text</tag>\n");
37 }
39 SECTION("child")
40 {
41 const auto tmp = tag {
42 child {},
43 };
45 REQUIRE(std::string(tmp) == "<tag>\n <child>\n </child>\n</tag>\n");
46 }
48 SECTION("attribute child")
49 {
50 const auto tmp = tag {
51 {{"attr", "val"}},
52 child {},
53 };
55 REQUIRE(
56 std::string(tmp)
57 == "<tag attr=\"val\">\n <child>\n </child>\n</tag>\n"
58 );
59 }
61 SECTION("child data")
62 {
63 const auto tmp = tag {
64 child {"text"},
65 };
67 REQUIRE(std::string(tmp) == "<tag>\n <child>text</child>\n</tag>\n");
68 }
70 SECTION("attribute child data")
71 {
72 const auto tmp = tag {
73 {{"attr", "val"}},
74 child {"text"},
75 };
77 REQUIRE(
78 std::string(tmp)
79 == "<tag attr=\"val\">\n <child>text</child>\n</tag>\n"
80 );
81 }
83 SECTION("range")
84 {
85 const std::vector<std::string> vec = {"hello", "world"};
86 const auto tmp = tag {vec};
88 REQUIRE(std::string(tmp) == "<tag>\n hello\n world\n</tag>\n");
89 }
91 SECTION("tag element elemetn tag")
92 {
93 const auto tmp = tag {element {element {tag {}}}};
94 REQUIRE(std::string(tmp) == "<tag>\n <tag>\n </tag>\n</tag>\n");
95 }
96 }
98 TEST_CASE("atomic", "[element]")
99 {
100 using tag = element_atomic<"tag">;
102 SECTION("empty")
103 {
104 const auto tmp = tag {};
106 REQUIRE(std::string(tmp) == "<tag />\n");
107 }
109 SECTION("attribute")
110 {
111 const auto tmp = tag {{{"attr", "val"}}};
113 REQUIRE(std::string(tmp) == "<tag attr=\"val\" />\n");
114 }
115 }
117 TEST_CASE("element", "[element]")
118 {
119 using tag = element_boolean<"tag">;
120 using child = element_boolean<"child">;
122 SECTION("empty")
123 {
124 const auto tmp = element {};
126 REQUIRE(std::string(tmp) == ""); // NOLINT
127 }
129 SECTION("data")
130 {
131 const auto tmp = element {"text"};
133 REQUIRE(std::string(tmp) == "text\n");
134 }
136 SECTION("tag")
137 {
138 const auto tmp = element {
139 tag {},
140 };
142 REQUIRE(std::string(tmp) == "<tag>\n</tag>\n");
143 }
145 SECTION("tag element")
146 {
147 const auto tmp = tag {
148 element {},
149 };
151 REQUIRE(std::string(tmp) == "<tag>\n</tag>\n");
152 }
154 SECTION("element tag")
155 {
156 const auto tmp = element {
157 tag {},
158 };
160 REQUIRE(std::string(tmp) == "<tag>\n</tag>\n");
161 }
163 SECTION("element tag data")
164 {
165 const auto tmp = element {
166 tag {"text"},
167 };
169 REQUIRE(std::string(tmp) == "<tag>text</tag>\n");
170 }
172 SECTION("tag element data")
173 {
174 const auto tmp = tag {
175 element {"text"},
176 };
178 REQUIRE(std::string(tmp) == "<tag>text</tag>\n");
179 }
181 SECTION("tag element data")
182 {
183 const auto tmp = tag {
184 element {"text"},
185 };
187 REQUIRE(std::string(tmp) == "<tag>text</tag>\n");
188 }
190 SECTION("element tag child data")
191 {
192 const auto tmp = element {
193 tag {
194 child {
195 "text",
196 },
197 },
198 };
200 REQUIRE(std::string(tmp) == "<tag>\n <child>text</child>\n</tag>\n");
201 }
203 SECTION("element tag element child data")
204 {
205 const auto tmp = element {
206 tag {
207 element {
208 child {
209 "text",
210 },
211 },
212 },
213 };
215 REQUIRE(std::string(tmp) == "<tag>\n <child>text</child>\n</tag>\n");
216 }
218 SECTION("element tag child element data")
219 {
220 const auto tmp = element {
221 tag {
222 child {
223 element {
224 "text",
225 },
226 },
227 },
228 };
230 REQUIRE(std::string(tmp) == "<tag>\n <child>text</child>\n</tag>\n");
231 }
233 SECTION("element tag element child element data")
234 {
235 const auto tmp = element {
236 tag {
237 element {
238 child {
239 element {
240 "text",
241 },
242 },
243 },
244 },
245 };
247 REQUIRE(std::string(tmp) == "<tag>\n <child>text</child>\n</tag>\n");
248 }
250 SECTION("tag element child data")
251 {
252 const auto tmp = tag {
253 element {
254 child {
255 "text",
256 },
257 },
258 };
260 REQUIRE(std::string(tmp) == "<tag>\n <child>text</child>\n</tag>\n");
261 }
263 SECTION("tag child element data")
264 {
265 const auto tmp = tag {
266 child {
267 element {
268 "text",
269 },
270 },
271 };
273 REQUIRE(std::string(tmp) == "<tag>\n <child>text</child>\n</tag>\n");
274 }
276 SECTION("tag element child element data")
277 {
278 const auto tmp = tag {
279 element {
280 child {
281 element {
282 "text",
283 },
284 },
285 },
286 };
288 REQUIRE(std::string(tmp) == "<tag>\n <child>text</child>\n</tag>\n");
289 }
290 }