gplate/tags/tests/gplate-variable-tag-test.c
author Gary Kramlich <grim@reaperworld.com>
Sat Jul 03 16:53:48 2010 -0500 (22 months ago)
changeset 393 e54d0b8f5a56
parent 392 27f9b7952d63
child 394 ad26d98e20e6
permissions -rw-r--r--
added some more tests for variable tags
grim@389
     1
#include <gplate/gplate.h>
grim@389
     2
grim@389
     3
#include <glib.h>
grim@389
     4
grim@389
     5
#include "gplate-tag-test.h"
grim@389
     6
grim@389
     7
/******************************************************************************
grim@392
     8
 * Helpers
grim@392
     9
 *****************************************************************************/
grim@392
    10
static void
grim@392
    11
gplate_variable_tag_test(GPlateTagTestFixture *fixture, gconstpointer data,
grim@392
    12
                         const gchar *template_string, const gchar *expected,
grim@392
    13
                         ...)
grim@392
    14
{
grim@392
    15
	va_list vargs;
grim@392
    16
	const gchar *name = NULL, *value = NULL;
grim@392
    17
grim@392
    18
	fixture->template_string = template_string;
grim@392
    19
	fixture->expected = expected;
grim@392
    20
grim@392
    21
	va_start(vargs, expected);
grim@392
    22
	while((name = va_arg(vargs, const gchar *))) {
grim@392
    23
		value = va_arg(vargs, const gchar *);
grim@392
    24
grim@392
    25
		gplate_collection_add_string(GPLATE_COLLECTION(fixture->template),
grim@392
    26
		                             name, value);
grim@392
    27
	}
grim@392
    28
grim@392
    29
	va_end(vargs);
grim@392
    30
grim@392
    31
	gplate_tag_test_output(fixture, data);
grim@392
    32
}
grim@392
    33
grim@392
    34
/******************************************************************************
grim@389
    35
 * Tests
grim@389
    36
 *****************************************************************************/
grim@389
    37
static void
grim@389
    38
gplate_variable_tag_test_single(GPlateTagTestFixture *fixture,
grim@389
    39
                                gconstpointer data)
grim@389
    40
{
grim@392
    41
	gplate_variable_tag_test(fixture, data,
grim@392
    42
	                         "{{ foo }}", "foo",
grim@392
    43
	                         "foo", "foo",
grim@392
    44
	                         NULL);
grim@389
    45
}
grim@389
    46
grim@389
    47
static void
grim@389
    48
gplate_variable_tag_test_double(GPlateTagTestFixture *fixture,
grim@389
    49
                                gconstpointer data)
grim@389
    50
{
grim@392
    51
	gplate_variable_tag_test(fixture, data,
grim@392
    52
	                         "{{ foo }}{{ bar }}", "foobar",
grim@392
    53
	                         "foo", "foo",
grim@392
    54
	                         "bar", "bar",
grim@392
    55
	                         NULL);
grim@389
    56
}
grim@389
    57
grim@389
    58
static void
grim@389
    59
gplate_variable_tag_test_tripple(GPlateTagTestFixture *fixture,
grim@389
    60
                                 gconstpointer data)
grim@389
    61
{
grim@392
    62
	gplate_variable_tag_test(fixture, data,
grim@392
    63
	                         "{{ foo }}{{ bar }}{{ baz }}", "foobarbaz",
grim@392
    64
	                         "foo", "foo",
grim@392
    65
	                         "bar", "bar",
grim@392
    66
	                         "baz", "baz",
grim@392
    67
	                         NULL);
grim@389
    68
}
grim@389
    69
grim@389
    70
static void
grim@389
    71
gplate_variable_tag_test_newline_prefix(GPlateTagTestFixture *fixture,
grim@389
    72
                                        gconstpointer data)
grim@389
    73
{
grim@392
    74
	gplate_variable_tag_test(fixture, data,
grim@392
    75
	                         "{{\nfoo}}", "foo",
grim@392
    76
	                         "foo", "foo",
grim@392
    77
	                         NULL);
grim@389
    78
}
grim@389
    79
grim@389
    80
static void
grim@389
    81
gplate_variable_tag_test_newline_suffix(GPlateTagTestFixture *fixture,
grim@389
    82
                                        gconstpointer data)
grim@389
    83
{
grim@392
    84
	gplate_variable_tag_test(fixture, data,
grim@392
    85
	                         "{{foo\n}}", "foo",
grim@392
    86
	                         "foo", "foo",
grim@392
    87
	                         NULL);
grim@389
    88
}
grim@389
    89
grim@389
    90
static void
grim@389
    91
gplate_variable_tag_test_newline_wrapped(GPlateTagTestFixture *fixture,
grim@389
    92
                                         gconstpointer data)
grim@389
    93
{
grim@392
    94
	gplate_variable_tag_test(fixture, data,
grim@392
    95
	                         "{{\nfoo\n}}", "foo",
grim@392
    96
	                         "foo", "foo",
grim@392
    97
	                         NULL);
grim@389
    98
}
grim@389
    99
grim@393
   100
static void
grim@393
   101
gplate_variable_tag_test_single_quotes(GPlateTagTestFixture *fixture,
grim@393
   102
                                       gconstpointer data)
grim@393
   103
{
grim@393
   104
	gplate_variable_tag_test(fixture, data,
grim@393
   105
	                         "foo '{{ bar }}' baz", "foo 'bar' baz",
grim@393
   106
	                         "bar", "bar",
grim@393
   107
	                         NULL);
grim@393
   108
}
grim@393
   109
grim@393
   110
static void
grim@393
   111
gplate_variable_tag_test_double_quotes(GPlateTagTestFixture *fixture,
grim@393
   112
                                       gconstpointer data)
grim@393
   113
{
grim@393
   114
	gplate_variable_tag_test(fixture, data,
grim@393
   115
	                         "foo \"{{ bar }}\" baz", "foo \"bar\" baz",
grim@393
   116
	                         "bar", "bar",
grim@393
   117
	                         NULL);
grim@393
   118
}
grim@393
   119
grim@393
   120
static void
grim@393
   121
gplate_variable_tag_test_mixed_quotes(GPlateTagTestFixture *fixture,
grim@393
   122
                                      gconstpointer data)
grim@393
   123
{
grim@393
   124
	gplate_variable_tag_test(fixture, data,
grim@393
   125
	                         "foo \"{{ bar }}' baz", "foo \"bar' baz",
grim@393
   126
	                         "bar", "bar",
grim@393
   127
	                         NULL);
grim@393
   128
grim@393
   129
	gplate_variable_tag_test(fixture, data,
grim@393
   130
	                         "foo '{{ bar }}\" baz", "foo 'bar\" baz",
grim@393
   131
	                         "bar", "bar",
grim@393
   132
	                         NULL);
grim@393
   133
}
grim@389
   134
/******************************************************************************
grim@389
   135
 * Main
grim@389
   136
 *****************************************************************************/
grim@389
   137
gint
grim@389
   138
main(gint argc, gchar **argv) {
grim@389
   139
	g_test_init(&argc, &argv, NULL);
grim@389
   140
grim@389
   141
	g_type_init();
grim@389
   142
grim@389
   143
	gplate_config_load_default();
grim@389
   144
grim@389
   145
	gplate_tag_test_add("/tags/variable/single",
grim@389
   146
	                    gplate_variable_tag_test_single);
grim@389
   147
grim@389
   148
	gplate_tag_test_add("/tags/variable/double",
grim@389
   149
	                    gplate_variable_tag_test_double);
grim@389
   150
grim@389
   151
	gplate_tag_test_add("/tags/variable/tripple",
grim@389
   152
	                    gplate_variable_tag_test_tripple);
grim@389
   153
grim@389
   154
	gplate_tag_test_add("/tags/variable/newline_prefix",
grim@389
   155
	                    gplate_variable_tag_test_newline_prefix);
grim@389
   156
grim@389
   157
	gplate_tag_test_add("/tags/variable/newline_suffix",
grim@389
   158
	                    gplate_variable_tag_test_newline_suffix);
grim@389
   159
grim@389
   160
	gplate_tag_test_add("/tags/variable/newline_wrapped",
grim@389
   161
	                    gplate_variable_tag_test_newline_wrapped);
grim@389
   162
grim@393
   163
	gplate_tag_test_add("/tags/variable/quotes/single",
grim@393
   164
	                    gplate_variable_tag_test_single_quotes);
grim@393
   165
grim@393
   166
	gplate_tag_test_add("/tags/variable/quotes/double",
grim@393
   167
	                    gplate_variable_tag_test_double_quotes);
grim@393
   168
grim@393
   169
	gplate_tag_test_add("/tags/variable/quotes/mixed",
grim@393
   170
	                    gplate_variable_tag_test_mixed_quotes);
grim@393
   171
grim@389
   172
	return g_test_run();
grim@389
   173
}
grim@389
   174