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