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