gplate/tags/tests/test-variable-tag.c
author Gary Kramlich <grim@reaperworld.com>
Fri Jul 02 02:56:50 2010 -0500 (22 months ago)
changeset 389 8baf0603ff07
permissions -rw-r--r--
Create a sublibrary for the tag testing. I'll probably do this for all components going forward.

Pretty much just reimplemented the tests that were created for check with gtester and ctest
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@389
     8
 * Tests
grim@389
     9
 *****************************************************************************/
grim@389
    10
static void
grim@389
    11
gplate_variable_tag_test_single(GPlateTagTestFixture *fixture,
grim@389
    12
                                gconstpointer data)
grim@389
    13
{
grim@389
    14
	gplate_collection_add_string(GPLATE_COLLECTION(fixture->template),
grim@389
    15
	                             "foo", "bar");
grim@389
    16
grim@389
    17
	fixture->template_string = "{{ foo }}";
grim@389
    18
	fixture->expected = "bar";
grim@389
    19
grim@389
    20
	gplate_tag_test_output(fixture, data);
grim@389
    21
}
grim@389
    22
grim@389
    23
static void
grim@389
    24
gplate_variable_tag_test_double(GPlateTagTestFixture *fixture,
grim@389
    25
                                gconstpointer data)
grim@389
    26
{
grim@389
    27
	gplate_collection_add_string(GPLATE_COLLECTION(fixture->template),
grim@389
    28
	                             "foo", "foo");
grim@389
    29
	gplate_collection_add_string(GPLATE_COLLECTION(fixture->template),
grim@389
    30
	                             "bar", "bar");
grim@389
    31
grim@389
    32
	fixture->template_string = "{{ foo }}{{ bar }}";
grim@389
    33
	fixture->expected = "foobar";
grim@389
    34
grim@389
    35
	gplate_tag_test_output(fixture, data);
grim@389
    36
}
grim@389
    37
grim@389
    38
static void
grim@389
    39
gplate_variable_tag_test_tripple(GPlateTagTestFixture *fixture,
grim@389
    40
                                 gconstpointer data)
grim@389
    41
{
grim@389
    42
	gplate_collection_add_string(GPLATE_COLLECTION(fixture->template),
grim@389
    43
	                             "foo", "foo");
grim@389
    44
	gplate_collection_add_string(GPLATE_COLLECTION(fixture->template),
grim@389
    45
	                             "bar", "bar");
grim@389
    46
	gplate_collection_add_string(GPLATE_COLLECTION(fixture->template),
grim@389
    47
	                             "baz", "baz");
grim@389
    48
grim@389
    49
	fixture->template_string = "{{ foo }}{{ bar }}{{ baz }}";
grim@389
    50
	fixture->expected = "foobarbaz";
grim@389
    51
grim@389
    52
	gplate_tag_test_output(fixture, data);
grim@389
    53
}
grim@389
    54
grim@389
    55
static void
grim@389
    56
gplate_variable_tag_test_newline_prefix(GPlateTagTestFixture *fixture,
grim@389
    57
                                        gconstpointer data)
grim@389
    58
{
grim@389
    59
	gplate_collection_add_string(GPLATE_COLLECTION(fixture->template),
grim@389
    60
	                             "foo", "bar");
grim@389
    61
grim@389
    62
	fixture->template_string = "{{\nfoo}}";
grim@389
    63
	fixture->expected = "bar";
grim@389
    64
grim@389
    65
	gplate_tag_test_output(fixture, data);
grim@389
    66
}
grim@389
    67
grim@389
    68
static void
grim@389
    69
gplate_variable_tag_test_newline_suffix(GPlateTagTestFixture *fixture,
grim@389
    70
                                        gconstpointer data)
grim@389
    71
{
grim@389
    72
	gplate_collection_add_string(GPLATE_COLLECTION(fixture->template),
grim@389
    73
	                             "foo", "bar");
grim@389
    74
grim@389
    75
	fixture->template_string = "{{foo\n}}";
grim@389
    76
	fixture->expected = "bar";
grim@389
    77
grim@389
    78
	gplate_tag_test_output(fixture, data);
grim@389
    79
}
grim@389
    80
grim@389
    81
static void
grim@389
    82
gplate_variable_tag_test_newline_wrapped(GPlateTagTestFixture *fixture,
grim@389
    83
                                         gconstpointer data)
grim@389
    84
{
grim@389
    85
	gplate_collection_add_string(GPLATE_COLLECTION(fixture->template),
grim@389
    86
	                             "foo", "bar");
grim@389
    87
grim@389
    88
	fixture->template_string = "{{\nfoo\n}}";
grim@389
    89
	fixture->expected = "bar";
grim@389
    90
grim@389
    91
	gplate_tag_test_output(fixture, data);
grim@389
    92
}
grim@389
    93
grim@389
    94
/******************************************************************************
grim@389
    95
 * Main
grim@389
    96
 *****************************************************************************/
grim@389
    97
gint
grim@389
    98
main(gint argc, gchar **argv) {
grim@389
    99
	g_test_init(&argc, &argv, NULL);
grim@389
   100
grim@389
   101
	g_type_init();
grim@389
   102
grim@389
   103
	gplate_config_load_default();
grim@389
   104
grim@389
   105
	gplate_tag_test_add("/tags/variable/single",
grim@389
   106
	                    gplate_variable_tag_test_single);
grim@389
   107
grim@389
   108
	gplate_tag_test_add("/tags/variable/double",
grim@389
   109
	                    gplate_variable_tag_test_double);
grim@389
   110
grim@389
   111
	gplate_tag_test_add("/tags/variable/tripple",
grim@389
   112
	                    gplate_variable_tag_test_tripple);
grim@389
   113
grim@389
   114
	gplate_tag_test_add("/tags/variable/newline_prefix",
grim@389
   115
	                    gplate_variable_tag_test_newline_prefix);
grim@389
   116
grim@389
   117
	gplate_tag_test_add("/tags/variable/newline_suffix",
grim@389
   118
	                    gplate_variable_tag_test_newline_suffix);
grim@389
   119
grim@389
   120
	gplate_tag_test_add("/tags/variable/newline_wrapped",
grim@389
   121
	                    gplate_variable_tag_test_newline_wrapped);
grim@389
   122
grim@389
   123
	return g_test_run();
grim@389
   124
}
grim@389
   125