Home | History | Annotate | Download | only in text

Lines Matching defs:templates

29 #include "utils/text/templates.hpp"
47 /// Applies a set of templates to an input string and validates the output.
50 /// by the application of the templates.
52 /// \param templates The templates to apply.
53 /// \param input_str The input document to which to apply the templates.
56 do_test_ok(const text::templates_def& templates, const std::string& input_str,
62 text::instantiate(templates, input, output);
67 /// Applies a set of templates to an input string and checks for an error.
72 /// \param templates The templates to apply.
73 /// \param input_str The input document to which to apply the templates.
76 do_test_fail(const text::templates_def& templates, const std::string& input_str,
83 text::instantiate(templates, input, output));
93 text::templates_def templates;
94 templates.add_variable("the-name", "first-value");
95 ATF_REQUIRE_EQ("first-value", templates.get_variable("the-name"));
102 text::templates_def templates;
103 templates.add_variable("the-name", "first-value");
104 templates.add_variable("the-name", "second-value");
105 ATF_REQUIRE_EQ("second-value", templates.get_variable("the-name"));
112 text::templates_def templates;
113 templates.add_variable("the-name", "the-value");
114 templates.get_variable("the-name"); // Should not throw.
115 templates.remove_variable("the-name");
116 ATF_REQUIRE_THROW(text::syntax_error, templates.get_variable("the-name"));
123 text::templates_def templates;
124 templates.add_vector("the-name");
125 ATF_REQUIRE(templates.get_vector("the-name").empty());
132 text::templates_def templates;
133 templates.add_vector("the-name");
134 templates.add_to_vector("the-name", "foo");
135 ATF_REQUIRE(!templates.get_vector("the-name").empty());
136 templates.add_vector("the-name");
137 ATF_REQUIRE(templates.get_vector("the-name").empty());
144 text::templates_def templates;
145 templates.add_vector("the-name");
146 ATF_REQUIRE_EQ(0, templates.get_vector("the-name").size());
147 templates.add_to_vector("the-name", "first");
148 ATF_REQUIRE_EQ(1, templates.get_vector("the-name").size());
149 templates.add_to_vector("the-name", "second");
150 ATF_REQUIRE_EQ(2, templates.get_vector("the-name").size());
151 templates.add_to_vector("the-name", "third");
152 ATF_REQUIRE_EQ(3, templates.get_vector("the-name").size());
158 ATF_REQUIRE(expected == templates.get_vector("the-name"));
165 text::templates_def templates;
166 ATF_REQUIRE(!templates.exists("some-name"));
167 templates.add_variable("some-name ", "foo");
168 ATF_REQUIRE(!templates.exists("some-name"));
169 templates.add_variable("some-name", "foo");
170 ATF_REQUIRE(templates.exists("some-name"));
177 text::templates_def templates;
178 ATF_REQUIRE(!templates.exists("some-name"));
179 templates.add_vector("some-name ");
180 ATF_REQUIRE(!templates.exists("some-name"));
181 templates.add_vector("some-name");
182 ATF_REQUIRE(templates.exists("some-name"));
189 text::templates_def templates;
190 templates.add_variable("foo", "");
191 templates.add_variable("bar", " baz ");
192 ATF_REQUIRE_EQ("", templates.get_variable("foo"));
193 ATF_REQUIRE_EQ(" baz ", templates.get_variable("bar"));
200 text::templates_def templates;
201 templates.add_variable("foo", "");
203 templates.get_variable("foo "));
210 text::templates_def templates;
211 templates.add_vector("foo");
212 templates.add_vector("bar");
213 templates.add_to_vector("bar", "baz");
214 ATF_REQUIRE_EQ(0, templates.get_vector("foo").size());
215 ATF_REQUIRE_EQ(1, templates.get_vector("bar").size());
222 text::templates_def templates;
223 templates.add_vector("foo");
225 templates.get_vector("foo "));
232 text::templates_def templates;
233 templates.add_variable("foo", "");
234 templates.add_variable("bar", " baz ");
235 ATF_REQUIRE_EQ("", templates.evaluate("foo"));
236 ATF_REQUIRE_EQ(" baz ", templates.evaluate("bar"));
243 text::templates_def templates;
244 templates.add_variable("foo", "");
246 templates.evaluate("foo1"));
253 text::templates_def templates;
254 templates.add_vector("v");
255 templates.add_to_vector("v", "foo");
256 templates.add_to_vector("v", "bar");
257 templates.add_to_vector("v", "baz");
259 templates.add_variable("index", "0");
260 ATF_REQUIRE_EQ("foo", templates.evaluate("v(index)"));
261 templates.add_variable("index", "1");
262 ATF_REQUIRE_EQ("bar", templates.evaluate("v(index)"));
263 templates.add_variable("index", "2");
264 ATF_REQUIRE_EQ("baz", templates.evaluate("v(index)"));
271 text::templates_def templates;
272 templates.add_vector("v");
273 templates.add_to_vector("v", "foo");
274 templates.add_variable("index", "0");
276 templates.evaluate("fooz(index)"));
283 text::templates_def templates;
284 templates.add_vector("v");
285 templates.add_to_vector("v", "foo");
286 templates.add_variable("index", "0");
288 templates.evaluate("v(indexz)"));
295 text::templates_def templates;
296 templates.add_vector("v");
297 templates.add_to_vector("v", "foo");
298 templates.add_variable("index", "1");
300 "at position '1'", templates.evaluate("v(index)"));
307 text::templates_def templates;
308 templates.add_vector("the-variable");
309 templates.add_vector("the-vector");
310 ATF_REQUIRE_EQ("false", templates.evaluate("defined(the-variabl)"));
311 ATF_REQUIRE_EQ("false", templates.evaluate("defined(the-vecto)"));
312 ATF_REQUIRE_EQ("true", templates.evaluate("defined(the-variable)"));
313 ATF_REQUIRE_EQ("true", templates.evaluate("defined(the-vector)"));
320 text::templates_def templates;
321 templates.add_vector("v");
322 ATF_REQUIRE_EQ("0", templates.evaluate("length(v)"));
323 templates.add_to_vector("v", "foo");
324 ATF_REQUIRE_EQ("1", templates.evaluate("length(v)"));
325 templates.add_to_vector("v", "bar");
326 ATF_REQUIRE_EQ("2", templates.evaluate("length(v)"));
327 templates.add_to_vector("v", "baz");
328 ATF_REQUIRE_EQ("3", templates.evaluate("length(v)"));
335 text::templates_def templates;
336 templates.add_vector("foo1");
338 templates.evaluate("length(foo)"));
345 text::templates_def templates;
348 templates.evaluate("foo(abc"));
351 templates.evaluate("a(b)c"));
358 const text::templates_def templates;
359 do_test_ok(templates, "", "");
380 text::templates_def templates;
381 templates.add_variable("testvar1", "second line");
382 templates.add_variable("testvar2", "fourth");
383 templates.add_variable("testvar3", "line");
384 templates.add_variable("testvar4", ".");
386 do_test_ok(templates, input, exp_output);
396 text::templates_def templates;
397 templates.add_variable("testvar2", "fourth line");
399 do_test_fail(templates, input, "Unknown variable 'testvar1'");
414 text::templates_def templates;
415 templates.add_vector("testvector1");
416 templates.add_to_vector("testvector1", "000");
417 templates.add_to_vector("testvector1", "111");
418 templates.add_to_vector("testvector1", "543");
419 templates.add_to_vector("testvector1", "999");
420 templates.add_vector("testvector2");
421 templates.add_vector("testvector3");
422 templates.add_to_vector("testvector3", "123");
424 do_test_ok(templates, input, exp_output);
434 text::templates_def templates;
435 templates.add_vector("testvector2");
437 do_test_fail(templates, input, "Unknown vector 'testvector'");
458 text::templates_def templates;
459 templates.add_variable("i", "2");
460 templates.add_variable("j", "0");
461 templates.add_vector("testvector1");
462 templates.add_to_vector("testvector1", "000");
463 templates.add_to_vector("testvector1", "111");
464 templates.add_to_vector("testvector1", "543");
465 templates.add_to_vector("testvector1", "999");
466 templates.add_vector("testvector2");
467 templates.add_to_vector("testvector2", "123");
469 do_test_ok(templates, input, exp_output);
479 text::templates_def templates;
480 templates.add_vector("testvector2");
482 do_test_fail(templates, input, "Unknown vector 'testvector'");
492 text::templates_def templates;
493 templates.add_vector("testvector");
494 templates.add_variable("j", "0");
496 do_test_fail(templates, input, "Index 'j' out of range at position '0'");
506 text::templates_def templates;
507 templates.add_vector("testvector");
508 templates.add_to_vector("testvector", "a");
509 templates.add_to_vector("testvector", "b");
510 templates.add_variable("j", "2");
512 do_test_fail(templates, input, "Index 'j' out of range at position '2'");
537 text::templates_def templates;
538 templates.add_variable("some_var", "zzz");
539 templates.add_vector("some_vector");
541 do_test_ok(templates, input, exp_output);
565 text::templates_def templates;
567 do_test_ok(templates, input, exp_output);
604 text::templates_def templates;
605 templates.add_variable("var1", "false");
606 templates.add_vector("var2");
607 templates.add_to_vector("var2", "not-empty");
608 templates.add_variable("var3", "foobar");
610 do_test_ok(templates, input, exp_output);
645 text::templates_def templates;
646 templates.add_variable("var1", "false");
647 templates.add_vector("var2");
648 templates.add_vector("var3");
650 do_test_ok(templates, input, exp_output);
670 text::templates_def templates;
671 templates.add_variable("var1", "defined");
672 templates.add_vector("table1");
674 do_test_ok(templates, input, exp_output);
694 text::templates_def templates;
695 templates.add_vector("table1");
696 templates.add_to_vector("table1", "foo1");
697 templates.add_to_vector("table1", "bar1");
698 templates.add_vector("table2");
699 templates.add_to_vector("table2", "foo2");
700 templates.add_to_vector("table2", "bar2");
702 do_test_ok(templates, input, exp_output);
732 text::templates_def templates;
733 templates.add_vector("table1");
734 templates.add_to_vector("table1", "a");
735 templates.add_to_vector("table1", "b");
736 templates.add_vector("table2");
737 templates.add_vector("table3");
738 templates.add_to_vector("table3", "1");
740 do_test_ok(templates, input, exp_output);
766 text::templates_def templates;
767 templates.add_vector("table1");
768 templates.add_to_vector("table1", "a");
769 templates.add_to_vector("table1", "b");
770 templates.add_vector("table2");
771 templates.add_to_vector("table2", "1");
772 templates.add_to_vector("table2", "2");
773 templates.add_to_vector("table2", "3");
775 do_test_ok(templates, input, exp_output);
813 text::templates_def templates;
814 templates.add_vector("table1");
815 templates.add_to_vector("table1", "a");
816 templates.add_to_vector("table1", "b");
817 templates.add_vector("table2");
818 templates.add_vector("table3");
819 templates.add_vector("table4");
820 templates.add_to_vector("table4", "1");
821 templates.add_to_vector("table4", "2");
822 templates.add_to_vector("table4", "3");
824 do_test_ok(templates, input, exp_output);
851 text::templates_def templates;
852 templates.add_vector("table1");
853 templates.add_to_vector("table1", "first");
854 templates.add_to_vector("table1", "second");
855 templates.add_vector("table2");
856 templates.add_to_vector("table2", "first");
858 do_test_ok(templates, input, exp_output);
873 text::templates_def templates;
874 templates.add_variable("var", "some more");
876 do_test_ok(templates, input, exp_output);
905 text::templates_def templates;
906 templates.add_variable("string", "Hello, world!");
910 text::instantiate(templates, fs::path("input.txt"), fs::path("output.txt"));
923 text::templates_def templates;
925 text::instantiate(templates, fs::path("input.txt"),
937 text::templates_def templates;
944 text::instantiate(templates, fs::path("input.txt"),