2 * Copyright (C) 2007-2010 Gary Kramlich <grim@reaperworld.com>
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include <gplate/gplate.h>
21 #include "test-gplate-tag.h"
23 /******************************************************************************
25 *****************************************************************************/
27 test_gplate_variable_tag(TestGPlateTagFixture *fixture, gconstpointer data,
28 const gchar *template_string, const gchar *expected,
32 const gchar *name = NULL, *value = NULL;
34 va_start(vargs, expected);
35 while((name = va_arg(vargs, const gchar *))) {
36 value = va_arg(vargs, const gchar *);
38 gplate_collection_add_string(GPLATE_COLLECTION(fixture->template),
43 test_gplate_tag_output(fixture, data, template_string, expected);
46 /******************************************************************************
48 *****************************************************************************/
50 test_gplate_variable_tag_single(TestGPlateTagFixture *fixture,
53 test_gplate_variable_tag(fixture, data,
60 test_gplate_variable_tag_double(TestGPlateTagFixture *fixture,
63 test_gplate_variable_tag(fixture, data,
64 "{{ foo }}{{ bar }}", "foobar",
71 test_gplate_variable_tag_tripple(TestGPlateTagFixture *fixture,
74 test_gplate_variable_tag(fixture, data,
75 "{{ foo }}{{ bar }}{{ baz }}", "foobarbaz",
83 test_gplate_variable_tag_newline_prefix(TestGPlateTagFixture *fixture,
86 test_gplate_variable_tag(fixture, data,
93 test_gplate_variable_tag_newline_suffix(TestGPlateTagFixture *fixture,
96 test_gplate_variable_tag(fixture, data,
103 test_gplate_variable_tag_newline_wrapped(TestGPlateTagFixture *fixture,
106 test_gplate_variable_tag(fixture, data,
107 "{{\nfoo\n}}", "foo",
113 test_gplate_variable_tag_single_quotes(TestGPlateTagFixture *fixture,
116 test_gplate_variable_tag(fixture, data,
117 "foo '{{ bar }}' baz", "foo 'bar' baz",
123 test_gplate_variable_tag_double_quotes(TestGPlateTagFixture *fixture,
126 test_gplate_variable_tag(fixture, data,
127 "foo \"{{ bar }}\" baz", "foo \"bar\" baz",
133 test_gplate_variable_tag_mixed_quotes(TestGPlateTagFixture *fixture,
136 test_gplate_variable_tag(fixture, data,
137 "foo \"{{ bar }}' baz", "foo \"bar' baz",
141 test_gplate_variable_tag(fixture, data,
142 "foo '{{ bar }}\" baz", "foo 'bar\" baz",
148 test_gplate_variable_tag_two_vars_one_block(TestGPlateTagFixture *fixture,
151 test_gplate_variable_tag(fixture, data,
152 "one {{ two five }} three",
160 test_gplate_variable_tag_nested_single(TestGPlateTagFixture *fixture,
163 GPlateVariable *dict = gplate_dictionary_variable_new("foo");
165 gplate_collection_add_string(GPLATE_COLLECTION(dict),
168 test_gplate_tag_output(fixture, data, "{{ foo.bar }}", "baz");
172 test_gplate_variable_tag_nested_double(TestGPlateTagFixture *fixture,
175 GPlateVariable *dict1 = gplate_dictionary_variable_new("foo");
176 GPlateVariable *dict2 = gplate_dictionary_variable_new("bar");
178 gplate_collection_add_variable(GPLATE_COLLECTION(fixture->template),
180 gplate_collection_add_variable(GPLATE_COLLECTION(dict1), dict2);
181 gplate_collection_add_string(GPLATE_COLLECTION(dict2),
184 test_gplate_tag_output(fixture, data, "{{ foo.bar.baz }}", "42");
187 /******************************************************************************
189 *****************************************************************************/
191 main(gint argc, gchar **argv) {
192 g_test_init(&argc, &argv, NULL);
196 gplate_config_load_default();
198 test_gplate_tag_add("/tags/variable/single",
199 test_gplate_variable_tag_single);
201 test_gplate_tag_add("/tags/variable/double",
202 test_gplate_variable_tag_double);
204 test_gplate_tag_add("/tags/variable/tripple",
205 test_gplate_variable_tag_tripple);
207 test_gplate_tag_add("/tags/variable/newline_prefix",
208 test_gplate_variable_tag_newline_prefix);
210 test_gplate_tag_add("/tags/variable/newline_suffix",
211 test_gplate_variable_tag_newline_suffix);
213 test_gplate_tag_add("/tags/variable/newline_wrapped",
214 test_gplate_variable_tag_newline_wrapped);
216 test_gplate_tag_add("/tags/variable/quotes/single",
217 test_gplate_variable_tag_single_quotes);
219 test_gplate_tag_add("/tags/variable/quotes/double",
220 test_gplate_variable_tag_double_quotes);
222 test_gplate_tag_add("/tags/variable/quotes/mixed",
223 test_gplate_variable_tag_mixed_quotes);
225 test_gplate_tag_add("/tags/variable/two_vars_one_block",
226 test_gplate_variable_tag_two_vars_one_block);
228 test_gplate_tag_add("/tags/variables/nested/single",
229 test_gplate_variable_tag_nested_single);
231 test_gplate_tag_add("/tags/variable/nested/double",
232 test_gplate_variable_tag_nested_double);