gplate/tags/tests/gplate-variable-tag-test.c
author Gary Kramlich <grim@reaperworld.com>
Sat Jul 03 23:24:33 2010 -0500 (22 months ago)
changeset 394 ad26d98e20e6
parent 393 e54d0b8f5a56
child 395 2a257237a0ef
permissions -rw-r--r--
Changed the license from gplv2 to gplv3
Updated copyrights to be 2007-2010 rather than 2007-2008 (since just about everything has been touched recently
Ignored the top level tests/ directory for now since that is slowly being replaced
grim@394
     1
/*
grim@394
     2
 * Copyright (C) 2007-2010 Gary Kramlich <grim@reaperworld.com>
grim@394
     3
 *
grim@394
     4
 * This program is free software: you can redistribute it and/or modify
grim@394
     5
 * it under the terms of the GNU General Public License as published by
grim@394
     6
 * the Free Software Foundation, either version 3 of the License, or
grim@394
     7
 * (at your option) any later version.
grim@394
     8
 *
grim@394
     9
 * This program is distributed in the hope that it will be useful,
grim@394
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
grim@394
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
grim@394
    12
 * GNU General Public License for more details.
grim@394
    13
 *
grim@394
    14
 * You should have received a copy of the GNU General Public License
grim@394
    15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
grim@394
    16
 */
grim@389
    17
#include <gplate/gplate.h>
grim@389
    18
grim@389
    19
#include <glib.h>
grim@389
    20
grim@389
    21
#include "gplate-tag-test.h"
grim@389
    22
grim@389
    23
/******************************************************************************
grim@392
    24
 * Helpers
grim@392
    25
 *****************************************************************************/
grim@392
    26
static void
grim@392
    27
gplate_variable_tag_test(GPlateTagTestFixture *fixture, gconstpointer data,
grim@392
    28
                         const gchar *template_string, const gchar *expected,
grim@392
    29
                         ...)
grim@392
    30
{
grim@392
    31
	va_list vargs;
grim@392
    32
	const gchar *name = NULL, *value = NULL;
grim@392
    33
grim@392
    34
	fixture->template_string = template_string;
grim@392
    35
	fixture->expected = expected;
grim@392
    36
grim@392
    37
	va_start(vargs, expected);
grim@392
    38
	while((name = va_arg(vargs, const gchar *))) {
grim@392
    39
		value = va_arg(vargs, const gchar *);
grim@392
    40
grim@392
    41
		gplate_collection_add_string(GPLATE_COLLECTION(fixture->template),
grim@392
    42
		                             name, value);
grim@392
    43
	}
grim@392
    44
grim@392
    45
	va_end(vargs);
grim@392
    46
grim@392
    47
	gplate_tag_test_output(fixture, data);
grim@392
    48
}
grim@392
    49
grim@392
    50
/******************************************************************************
grim@389
    51
 * Tests
grim@389
    52
 *****************************************************************************/
grim@389
    53
static void
grim@389
    54
gplate_variable_tag_test_single(GPlateTagTestFixture *fixture,
grim@389
    55
                                gconstpointer data)
grim@389
    56
{
grim@392
    57
	gplate_variable_tag_test(fixture, data,
grim@392
    58
	                         "{{ foo }}", "foo",
grim@392
    59
	                         "foo", "foo",
grim@392
    60
	                         NULL);
grim@389
    61
}
grim@389
    62
grim@389
    63
static void
grim@389
    64
gplate_variable_tag_test_double(GPlateTagTestFixture *fixture,
grim@389
    65
                                gconstpointer data)
grim@389
    66
{
grim@392
    67
	gplate_variable_tag_test(fixture, data,
grim@392
    68
	                         "{{ foo }}{{ bar }}", "foobar",
grim@392
    69
	                         "foo", "foo",
grim@392
    70
	                         "bar", "bar",
grim@392
    71
	                         NULL);
grim@389
    72
}
grim@389
    73
grim@389
    74
static void
grim@389
    75
gplate_variable_tag_test_tripple(GPlateTagTestFixture *fixture,
grim@389
    76
                                 gconstpointer data)
grim@389
    77
{
grim@392
    78
	gplate_variable_tag_test(fixture, data,
grim@392
    79
	                         "{{ foo }}{{ bar }}{{ baz }}", "foobarbaz",
grim@392
    80
	                         "foo", "foo",
grim@392
    81
	                         "bar", "bar",
grim@392
    82
	                         "baz", "baz",
grim@392
    83
	                         NULL);
grim@389
    84
}
grim@389
    85
grim@389
    86
static void
grim@389
    87
gplate_variable_tag_test_newline_prefix(GPlateTagTestFixture *fixture,
grim@389
    88
                                        gconstpointer data)
grim@389
    89
{
grim@392
    90
	gplate_variable_tag_test(fixture, data,
grim@392
    91
	                         "{{\nfoo}}", "foo",
grim@392
    92
	                         "foo", "foo",
grim@392
    93
	                         NULL);
grim@389
    94
}
grim@389
    95
grim@389
    96
static void
grim@389
    97
gplate_variable_tag_test_newline_suffix(GPlateTagTestFixture *fixture,
grim@389
    98
                                        gconstpointer data)
grim@389
    99
{
grim@392
   100
	gplate_variable_tag_test(fixture, data,
grim@392
   101
	                         "{{foo\n}}", "foo",
grim@392
   102
	                         "foo", "foo",
grim@392
   103
	                         NULL);
grim@389
   104
}
grim@389
   105
grim@389
   106
static void
grim@389
   107
gplate_variable_tag_test_newline_wrapped(GPlateTagTestFixture *fixture,
grim@389
   108
                                         gconstpointer data)
grim@389
   109
{
grim@392
   110
	gplate_variable_tag_test(fixture, data,
grim@392
   111
	                         "{{\nfoo\n}}", "foo",
grim@392
   112
	                         "foo", "foo",
grim@392
   113
	                         NULL);
grim@389
   114
}
grim@389
   115
grim@393
   116
static void
grim@393
   117
gplate_variable_tag_test_single_quotes(GPlateTagTestFixture *fixture,
grim@393
   118
                                       gconstpointer data)
grim@393
   119
{
grim@393
   120
	gplate_variable_tag_test(fixture, data,
grim@393
   121
	                         "foo '{{ bar }}' baz", "foo 'bar' baz",
grim@393
   122
	                         "bar", "bar",
grim@393
   123
	                         NULL);
grim@393
   124
}
grim@393
   125
grim@393
   126
static void
grim@393
   127
gplate_variable_tag_test_double_quotes(GPlateTagTestFixture *fixture,
grim@393
   128
                                       gconstpointer data)
grim@393
   129
{
grim@393
   130
	gplate_variable_tag_test(fixture, data,
grim@393
   131
	                         "foo \"{{ bar }}\" baz", "foo \"bar\" baz",
grim@393
   132
	                         "bar", "bar",
grim@393
   133
	                         NULL);
grim@393
   134
}
grim@393
   135
grim@393
   136
static void
grim@393
   137
gplate_variable_tag_test_mixed_quotes(GPlateTagTestFixture *fixture,
grim@393
   138
                                      gconstpointer data)
grim@393
   139
{
grim@393
   140
	gplate_variable_tag_test(fixture, data,
grim@393
   141
	                         "foo \"{{ bar }}' baz", "foo \"bar' baz",
grim@393
   142
	                         "bar", "bar",
grim@393
   143
	                         NULL);
grim@393
   144
grim@393
   145
	gplate_variable_tag_test(fixture, data,
grim@393
   146
	                         "foo '{{ bar }}\" baz", "foo 'bar\" baz",
grim@393
   147
	                         "bar", "bar",
grim@393
   148
	                         NULL);
grim@393
   149
}
grim@389
   150
/******************************************************************************
grim@389
   151
 * Main
grim@389
   152
 *****************************************************************************/
grim@389
   153
gint
grim@389
   154
main(gint argc, gchar **argv) {
grim@389
   155
	g_test_init(&argc, &argv, NULL);
grim@389
   156
grim@389
   157
	g_type_init();
grim@389
   158
grim@389
   159
	gplate_config_load_default();
grim@389
   160
grim@389
   161
	gplate_tag_test_add("/tags/variable/single",
grim@389
   162
	                    gplate_variable_tag_test_single);
grim@389
   163
grim@389
   164
	gplate_tag_test_add("/tags/variable/double",
grim@389
   165
	                    gplate_variable_tag_test_double);
grim@389
   166
grim@389
   167
	gplate_tag_test_add("/tags/variable/tripple",
grim@389
   168
	                    gplate_variable_tag_test_tripple);
grim@389
   169
grim@389
   170
	gplate_tag_test_add("/tags/variable/newline_prefix",
grim@389
   171
	                    gplate_variable_tag_test_newline_prefix);
grim@389
   172
grim@389
   173
	gplate_tag_test_add("/tags/variable/newline_suffix",
grim@389
   174
	                    gplate_variable_tag_test_newline_suffix);
grim@389
   175
grim@389
   176
	gplate_tag_test_add("/tags/variable/newline_wrapped",
grim@389
   177
	                    gplate_variable_tag_test_newline_wrapped);
grim@389
   178
grim@393
   179
	gplate_tag_test_add("/tags/variable/quotes/single",
grim@393
   180
	                    gplate_variable_tag_test_single_quotes);
grim@393
   181
grim@393
   182
	gplate_tag_test_add("/tags/variable/quotes/double",
grim@393
   183
	                    gplate_variable_tag_test_double_quotes);
grim@393
   184
grim@393
   185
	gplate_tag_test_add("/tags/variable/quotes/mixed",
grim@393
   186
	                    gplate_variable_tag_test_mixed_quotes);
grim@393
   187
grim@389
   188
	return g_test_run();
grim@389
   189
}
grim@389
   190