gplate/tags/tests/test-gplate-variable-tag.c
changeset 400 0938cb5d076b
parent 395 2a257237a0ef
child 403 13b5031b2846
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gplate/tags/tests/test-gplate-variable-tag.c	Sun Jul 04 03:34:39 2010 -0500
     1.3 @@ -0,0 +1,186 @@
     1.4 +/*
     1.5 + * Copyright (C) 2007-2010 Gary Kramlich <grim@reaperworld.com>
     1.6 + *
     1.7 + * This program is free software: you can redistribute it and/or modify
     1.8 + * it under the terms of the GNU General Public License as published by
     1.9 + * the Free Software Foundation, either version 3 of the License, or
    1.10 + * (at your option) any later version.
    1.11 + *
    1.12 + * This program is distributed in the hope that it will be useful,
    1.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.15 + * GNU General Public License for more details.
    1.16 + *
    1.17 + * You should have received a copy of the GNU General Public License
    1.18 + * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    1.19 + */
    1.20 +#include <gplate/gplate.h>
    1.21 +
    1.22 +#include <glib.h>
    1.23 +
    1.24 +#include "test-gplate-tag.h"
    1.25 +
    1.26 +/******************************************************************************
    1.27 + * Helpers
    1.28 + *****************************************************************************/
    1.29 +static void
    1.30 +test_gplate_variable_tag(TestGPlateTagFixture *fixture, gconstpointer data,
    1.31 +                         const gchar *template_string, const gchar *expected,
    1.32 +                         ...)
    1.33 +{
    1.34 +	va_list vargs;
    1.35 +	const gchar *name = NULL, *value = NULL;
    1.36 +
    1.37 +	va_start(vargs, expected);
    1.38 +	while((name = va_arg(vargs, const gchar *))) {
    1.39 +		value = va_arg(vargs, const gchar *);
    1.40 +
    1.41 +		gplate_collection_add_string(GPLATE_COLLECTION(fixture->template),
    1.42 +		                             name, value);
    1.43 +	}
    1.44 +	va_end(vargs);
    1.45 +
    1.46 +	test_gplate_tag_output(fixture, data, template_string, expected);
    1.47 +}
    1.48 +
    1.49 +/******************************************************************************
    1.50 + * Tests
    1.51 + *****************************************************************************/
    1.52 +static void
    1.53 +test_gplate_variable_tag_single(TestGPlateTagFixture *fixture,
    1.54 +                                gconstpointer data)
    1.55 +{
    1.56 +	test_gplate_variable_tag(fixture, data,
    1.57 +	                         "{{ foo }}", "foo",
    1.58 +	                         "foo", "foo",
    1.59 +	                         NULL);
    1.60 +}
    1.61 +
    1.62 +static void
    1.63 +test_gplate_variable_tag_double(TestGPlateTagFixture *fixture,
    1.64 +                                gconstpointer data)
    1.65 +{
    1.66 +	test_gplate_variable_tag(fixture, data,
    1.67 +	                         "{{ foo }}{{ bar }}", "foobar",
    1.68 +	                         "foo", "foo",
    1.69 +	                         "bar", "bar",
    1.70 +	                         NULL);
    1.71 +}
    1.72 +
    1.73 +static void
    1.74 +test_gplate_variable_tag_tripple(TestGPlateTagFixture *fixture,
    1.75 +                                 gconstpointer data)
    1.76 +{
    1.77 +	test_gplate_variable_tag(fixture, data,
    1.78 +	                         "{{ foo }}{{ bar }}{{ baz }}", "foobarbaz",
    1.79 +	                         "foo", "foo",
    1.80 +	                         "bar", "bar",
    1.81 +	                         "baz", "baz",
    1.82 +	                         NULL);
    1.83 +}
    1.84 +
    1.85 +static void
    1.86 +test_gplate_variable_tag_newline_prefix(TestGPlateTagFixture *fixture,
    1.87 +                                        gconstpointer data)
    1.88 +{
    1.89 +	test_gplate_variable_tag(fixture, data,
    1.90 +	                         "{{\nfoo}}", "foo",
    1.91 +	                         "foo", "foo",
    1.92 +	                         NULL);
    1.93 +}
    1.94 +
    1.95 +static void
    1.96 +test_gplate_variable_tag_newline_suffix(TestGPlateTagFixture *fixture,
    1.97 +                                        gconstpointer data)
    1.98 +{
    1.99 +	test_gplate_variable_tag(fixture, data,
   1.100 +	                         "{{foo\n}}", "foo",
   1.101 +	                         "foo", "foo",
   1.102 +	                         NULL);
   1.103 +}
   1.104 +
   1.105 +static void
   1.106 +test_gplate_variable_tag_newline_wrapped(TestGPlateTagFixture *fixture,
   1.107 +                                         gconstpointer data)
   1.108 +{
   1.109 +	test_gplate_variable_tag(fixture, data,
   1.110 +	                         "{{\nfoo\n}}", "foo",
   1.111 +	                         "foo", "foo",
   1.112 +	                         NULL);
   1.113 +}
   1.114 +
   1.115 +static void
   1.116 +test_gplate_variable_tag_single_quotes(TestGPlateTagFixture *fixture,
   1.117 +                                       gconstpointer data)
   1.118 +{
   1.119 +	test_gplate_variable_tag(fixture, data,
   1.120 +	                         "foo '{{ bar }}' baz", "foo 'bar' baz",
   1.121 +	                         "bar", "bar",
   1.122 +	                         NULL);
   1.123 +}
   1.124 +
   1.125 +static void
   1.126 +test_gplate_variable_tag_double_quotes(TestGPlateTagFixture *fixture,
   1.127 +                                       gconstpointer data)
   1.128 +{
   1.129 +	test_gplate_variable_tag(fixture, data,
   1.130 +	                         "foo \"{{ bar }}\" baz", "foo \"bar\" baz",
   1.131 +	                         "bar", "bar",
   1.132 +	                         NULL);
   1.133 +}
   1.134 +
   1.135 +static void
   1.136 +test_gplate_variable_tag_mixed_quotes(TestGPlateTagFixture *fixture,
   1.137 +                                      gconstpointer data)
   1.138 +{
   1.139 +	test_gplate_variable_tag(fixture, data,
   1.140 +	                         "foo \"{{ bar }}' baz", "foo \"bar' baz",
   1.141 +	                         "bar", "bar",
   1.142 +	                         NULL);
   1.143 +
   1.144 +	test_gplate_variable_tag(fixture, data,
   1.145 +	                         "foo '{{ bar }}\" baz", "foo 'bar\" baz",
   1.146 +	                         "bar", "bar",
   1.147 +	                         NULL);
   1.148 +}
   1.149 +/******************************************************************************
   1.150 + * Main
   1.151 + *****************************************************************************/
   1.152 +gint
   1.153 +main(gint argc, gchar **argv) {
   1.154 +	g_test_init(&argc, &argv, NULL);
   1.155 +
   1.156 +	g_type_init();
   1.157 +
   1.158 +	gplate_config_load_default();
   1.159 +
   1.160 +	test_gplate_tag_add("/tags/variable/single",
   1.161 +	                    test_gplate_variable_tag_single);
   1.162 +
   1.163 +	test_gplate_tag_add("/tags/variable/double",
   1.164 +	                    test_gplate_variable_tag_double);
   1.165 +
   1.166 +	test_gplate_tag_add("/tags/variable/tripple",
   1.167 +	                    test_gplate_variable_tag_tripple);
   1.168 +
   1.169 +	test_gplate_tag_add("/tags/variable/newline_prefix",
   1.170 +	                    test_gplate_variable_tag_newline_prefix);
   1.171 +
   1.172 +	test_gplate_tag_add("/tags/variable/newline_suffix",
   1.173 +	                    test_gplate_variable_tag_newline_suffix);
   1.174 +
   1.175 +	test_gplate_tag_add("/tags/variable/newline_wrapped",
   1.176 +	                    test_gplate_variable_tag_newline_wrapped);
   1.177 +
   1.178 +	test_gplate_tag_add("/tags/variable/quotes/single",
   1.179 +	                    test_gplate_variable_tag_single_quotes);
   1.180 +
   1.181 +	test_gplate_tag_add("/tags/variable/quotes/double",
   1.182 +	                    test_gplate_variable_tag_double_quotes);
   1.183 +
   1.184 +	test_gplate_tag_add("/tags/variable/quotes/mixed",
   1.185 +	                    test_gplate_variable_tag_mixed_quotes);
   1.186 +
   1.187 +	return g_test_run();
   1.188 +}
   1.189 +