gplate/tags/tests/gplate-variable-tag-test.c
author Gary Kramlich <grim@reaperworld.com>
Sun Jul 04 02:02:59 2010 -0500 (22 months ago)
changeset 395 2a257237a0ef
parent 394 ad26d98e20e6
permissions -rw-r--r--
removed gplate_tag_test_output
renamed gplate_tag_test_output_full to gplate_tag_test_output
updated as necessary
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
	va_start(vargs, expected);
grim@392
    35
	while((name = va_arg(vargs, const gchar *))) {
grim@392
    36
		value = va_arg(vargs, const gchar *);
grim@392
    37
grim@392
    38
		gplate_collection_add_string(GPLATE_COLLECTION(fixture->template),
grim@392
    39
		                             name, value);
grim@392
    40
	}
grim@392
    41
	va_end(vargs);
grim@392
    42
grim@395
    43
	gplate_tag_test_output(fixture, data, template_string, expected);
grim@392
    44
}
grim@392
    45
grim@392
    46
/******************************************************************************
grim@389
    47
 * Tests
grim@389
    48
 *****************************************************************************/
grim@389
    49
static void
grim@389
    50
gplate_variable_tag_test_single(GPlateTagTestFixture *fixture,
grim@389
    51
                                gconstpointer data)
grim@389
    52
{
grim@392
    53
	gplate_variable_tag_test(fixture, data,
grim@392
    54
	                         "{{ foo }}", "foo",
grim@392
    55
	                         "foo", "foo",
grim@392
    56
	                         NULL);
grim@389
    57
}
grim@389
    58
grim@389
    59
static void
grim@389
    60
gplate_variable_tag_test_double(GPlateTagTestFixture *fixture,
grim@389
    61
                                gconstpointer data)
grim@389
    62
{
grim@392
    63
	gplate_variable_tag_test(fixture, data,
grim@392
    64
	                         "{{ foo }}{{ bar }}", "foobar",
grim@392
    65
	                         "foo", "foo",
grim@392
    66
	                         "bar", "bar",
grim@392
    67
	                         NULL);
grim@389
    68
}
grim@389
    69
grim@389
    70
static void
grim@389
    71
gplate_variable_tag_test_tripple(GPlateTagTestFixture *fixture,
grim@389
    72
                                 gconstpointer data)
grim@389
    73
{
grim@392
    74
	gplate_variable_tag_test(fixture, data,
grim@392
    75
	                         "{{ foo }}{{ bar }}{{ baz }}", "foobarbaz",
grim@392
    76
	                         "foo", "foo",
grim@392
    77
	                         "bar", "bar",
grim@392
    78
	                         "baz", "baz",
grim@392
    79
	                         NULL);
grim@389
    80
}
grim@389
    81
grim@389
    82
static void
grim@389
    83
gplate_variable_tag_test_newline_prefix(GPlateTagTestFixture *fixture,
grim@389
    84
                                        gconstpointer data)
grim@389
    85
{
grim@392
    86
	gplate_variable_tag_test(fixture, data,
grim@392
    87
	                         "{{\nfoo}}", "foo",
grim@392
    88
	                         "foo", "foo",
grim@392
    89
	                         NULL);
grim@389
    90
}
grim@389
    91
grim@389
    92
static void
grim@389
    93
gplate_variable_tag_test_newline_suffix(GPlateTagTestFixture *fixture,
grim@389
    94
                                        gconstpointer data)
grim@389
    95
{
grim@392
    96
	gplate_variable_tag_test(fixture, data,
grim@392
    97
	                         "{{foo\n}}", "foo",
grim@392
    98
	                         "foo", "foo",
grim@392
    99
	                         NULL);
grim@389
   100
}
grim@389
   101
grim@389
   102
static void
grim@389
   103
gplate_variable_tag_test_newline_wrapped(GPlateTagTestFixture *fixture,
grim@389
   104
                                         gconstpointer data)
grim@389
   105
{
grim@392
   106
	gplate_variable_tag_test(fixture, data,
grim@392
   107
	                         "{{\nfoo\n}}", "foo",
grim@392
   108
	                         "foo", "foo",
grim@392
   109
	                         NULL);
grim@389
   110
}
grim@389
   111
grim@393
   112
static void
grim@393
   113
gplate_variable_tag_test_single_quotes(GPlateTagTestFixture *fixture,
grim@393
   114
                                       gconstpointer data)
grim@393
   115
{
grim@393
   116
	gplate_variable_tag_test(fixture, data,
grim@393
   117
	                         "foo '{{ bar }}' baz", "foo 'bar' baz",
grim@393
   118
	                         "bar", "bar",
grim@393
   119
	                         NULL);
grim@393
   120
}
grim@393
   121
grim@393
   122
static void
grim@393
   123
gplate_variable_tag_test_double_quotes(GPlateTagTestFixture *fixture,
grim@393
   124
                                       gconstpointer data)
grim@393
   125
{
grim@393
   126
	gplate_variable_tag_test(fixture, data,
grim@393
   127
	                         "foo \"{{ bar }}\" baz", "foo \"bar\" baz",
grim@393
   128
	                         "bar", "bar",
grim@393
   129
	                         NULL);
grim@393
   130
}
grim@393
   131
grim@393
   132
static void
grim@393
   133
gplate_variable_tag_test_mixed_quotes(GPlateTagTestFixture *fixture,
grim@393
   134
                                      gconstpointer data)
grim@393
   135
{
grim@393
   136
	gplate_variable_tag_test(fixture, data,
grim@393
   137
	                         "foo \"{{ bar }}' baz", "foo \"bar' baz",
grim@393
   138
	                         "bar", "bar",
grim@393
   139
	                         NULL);
grim@393
   140
grim@393
   141
	gplate_variable_tag_test(fixture, data,
grim@393
   142
	                         "foo '{{ bar }}\" baz", "foo 'bar\" baz",
grim@393
   143
	                         "bar", "bar",
grim@393
   144
	                         NULL);
grim@393
   145
}
grim@389
   146
/******************************************************************************
grim@389
   147
 * Main
grim@389
   148
 *****************************************************************************/
grim@389
   149
gint
grim@389
   150
main(gint argc, gchar **argv) {
grim@389
   151
	g_test_init(&argc, &argv, NULL);
grim@389
   152
grim@389
   153
	g_type_init();
grim@389
   154
grim@389
   155
	gplate_config_load_default();
grim@389
   156
grim@389
   157
	gplate_tag_test_add("/tags/variable/single",
grim@389
   158
	                    gplate_variable_tag_test_single);
grim@389
   159
grim@389
   160
	gplate_tag_test_add("/tags/variable/double",
grim@389
   161
	                    gplate_variable_tag_test_double);
grim@389
   162
grim@389
   163
	gplate_tag_test_add("/tags/variable/tripple",
grim@389
   164
	                    gplate_variable_tag_test_tripple);
grim@389
   165
grim@389
   166
	gplate_tag_test_add("/tags/variable/newline_prefix",
grim@389
   167
	                    gplate_variable_tag_test_newline_prefix);
grim@389
   168
grim@389
   169
	gplate_tag_test_add("/tags/variable/newline_suffix",
grim@389
   170
	                    gplate_variable_tag_test_newline_suffix);
grim@389
   171
grim@389
   172
	gplate_tag_test_add("/tags/variable/newline_wrapped",
grim@389
   173
	                    gplate_variable_tag_test_newline_wrapped);
grim@389
   174
grim@393
   175
	gplate_tag_test_add("/tags/variable/quotes/single",
grim@393
   176
	                    gplate_variable_tag_test_single_quotes);
grim@393
   177
grim@393
   178
	gplate_tag_test_add("/tags/variable/quotes/double",
grim@393
   179
	                    gplate_variable_tag_test_double_quotes);
grim@393
   180
grim@393
   181
	gplate_tag_test_add("/tags/variable/quotes/mixed",
grim@393
   182
	                    gplate_variable_tag_test_mixed_quotes);
grim@393
   183
grim@389
   184
	return g_test_run();
grim@389
   185
}
grim@389
   186