gplate/tags/tests/test-gplate-variable-tag.c
author Gary Kramlich <grim@reaperworld.com>
Sun Jul 04 03:34:39 2010 -0500 (22 months ago)
changeset 400 0938cb5d076b
parent 395 gplate/tags/tests/gplate-variable-tag-test.c@2a257237a0ef
child 403 13b5031b2846
permissions -rw-r--r--
the start of the test name standardization

refs #15
     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 "test-gplate-tag.h"
    22 
    23 /******************************************************************************
    24  * Helpers
    25  *****************************************************************************/
    26 static void
    27 test_gplate_variable_tag(TestGPlateTagFixture *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 	va_start(vargs, expected);
    35 	while((name = va_arg(vargs, const gchar *))) {
    36 		value = va_arg(vargs, const gchar *);
    37 
    38 		gplate_collection_add_string(GPLATE_COLLECTION(fixture->template),
    39 		                             name, value);
    40 	}
    41 	va_end(vargs);
    42 
    43 	test_gplate_tag_output(fixture, data, template_string, expected);
    44 }
    45 
    46 /******************************************************************************
    47  * Tests
    48  *****************************************************************************/
    49 static void
    50 test_gplate_variable_tag_single(TestGPlateTagFixture *fixture,
    51                                 gconstpointer data)
    52 {
    53 	test_gplate_variable_tag(fixture, data,
    54 	                         "{{ foo }}", "foo",
    55 	                         "foo", "foo",
    56 	                         NULL);
    57 }
    58 
    59 static void
    60 test_gplate_variable_tag_double(TestGPlateTagFixture *fixture,
    61                                 gconstpointer data)
    62 {
    63 	test_gplate_variable_tag(fixture, data,
    64 	                         "{{ foo }}{{ bar }}", "foobar",
    65 	                         "foo", "foo",
    66 	                         "bar", "bar",
    67 	                         NULL);
    68 }
    69 
    70 static void
    71 test_gplate_variable_tag_tripple(TestGPlateTagFixture *fixture,
    72                                  gconstpointer data)
    73 {
    74 	test_gplate_variable_tag(fixture, data,
    75 	                         "{{ foo }}{{ bar }}{{ baz }}", "foobarbaz",
    76 	                         "foo", "foo",
    77 	                         "bar", "bar",
    78 	                         "baz", "baz",
    79 	                         NULL);
    80 }
    81 
    82 static void
    83 test_gplate_variable_tag_newline_prefix(TestGPlateTagFixture *fixture,
    84                                         gconstpointer data)
    85 {
    86 	test_gplate_variable_tag(fixture, data,
    87 	                         "{{\nfoo}}", "foo",
    88 	                         "foo", "foo",
    89 	                         NULL);
    90 }
    91 
    92 static void
    93 test_gplate_variable_tag_newline_suffix(TestGPlateTagFixture *fixture,
    94                                         gconstpointer data)
    95 {
    96 	test_gplate_variable_tag(fixture, data,
    97 	                         "{{foo\n}}", "foo",
    98 	                         "foo", "foo",
    99 	                         NULL);
   100 }
   101 
   102 static void
   103 test_gplate_variable_tag_newline_wrapped(TestGPlateTagFixture *fixture,
   104                                          gconstpointer data)
   105 {
   106 	test_gplate_variable_tag(fixture, data,
   107 	                         "{{\nfoo\n}}", "foo",
   108 	                         "foo", "foo",
   109 	                         NULL);
   110 }
   111 
   112 static void
   113 test_gplate_variable_tag_single_quotes(TestGPlateTagFixture *fixture,
   114                                        gconstpointer data)
   115 {
   116 	test_gplate_variable_tag(fixture, data,
   117 	                         "foo '{{ bar }}' baz", "foo 'bar' baz",
   118 	                         "bar", "bar",
   119 	                         NULL);
   120 }
   121 
   122 static void
   123 test_gplate_variable_tag_double_quotes(TestGPlateTagFixture *fixture,
   124                                        gconstpointer data)
   125 {
   126 	test_gplate_variable_tag(fixture, data,
   127 	                         "foo \"{{ bar }}\" baz", "foo \"bar\" baz",
   128 	                         "bar", "bar",
   129 	                         NULL);
   130 }
   131 
   132 static void
   133 test_gplate_variable_tag_mixed_quotes(TestGPlateTagFixture *fixture,
   134                                       gconstpointer data)
   135 {
   136 	test_gplate_variable_tag(fixture, data,
   137 	                         "foo \"{{ bar }}' baz", "foo \"bar' baz",
   138 	                         "bar", "bar",
   139 	                         NULL);
   140 
   141 	test_gplate_variable_tag(fixture, data,
   142 	                         "foo '{{ bar }}\" baz", "foo 'bar\" baz",
   143 	                         "bar", "bar",
   144 	                         NULL);
   145 }
   146 /******************************************************************************
   147  * Main
   148  *****************************************************************************/
   149 gint
   150 main(gint argc, gchar **argv) {
   151 	g_test_init(&argc, &argv, NULL);
   152 
   153 	g_type_init();
   154 
   155 	gplate_config_load_default();
   156 
   157 	test_gplate_tag_add("/tags/variable/single",
   158 	                    test_gplate_variable_tag_single);
   159 
   160 	test_gplate_tag_add("/tags/variable/double",
   161 	                    test_gplate_variable_tag_double);
   162 
   163 	test_gplate_tag_add("/tags/variable/tripple",
   164 	                    test_gplate_variable_tag_tripple);
   165 
   166 	test_gplate_tag_add("/tags/variable/newline_prefix",
   167 	                    test_gplate_variable_tag_newline_prefix);
   168 
   169 	test_gplate_tag_add("/tags/variable/newline_suffix",
   170 	                    test_gplate_variable_tag_newline_suffix);
   171 
   172 	test_gplate_tag_add("/tags/variable/newline_wrapped",
   173 	                    test_gplate_variable_tag_newline_wrapped);
   174 
   175 	test_gplate_tag_add("/tags/variable/quotes/single",
   176 	                    test_gplate_variable_tag_single_quotes);
   177 
   178 	test_gplate_tag_add("/tags/variable/quotes/double",
   179 	                    test_gplate_variable_tag_double_quotes);
   180 
   181 	test_gplate_tag_add("/tags/variable/quotes/mixed",
   182 	                    test_gplate_variable_tag_mixed_quotes);
   183 
   184 	return g_test_run();
   185 }
   186