gplate/tags/tests/gplate-variable-tag-test.c
author Gary Kramlich <grim@reaperworld.com>
Fri Jul 02 03:00:15 2010 -0500 (22 months ago)
changeset 391 20d032b30b6a
parent 389 gplate/tags/tests/test-variable-tag.c@8baf0603ff07
child 392 27f9b7952d63
permissions -rw-r--r--
renamed test-variable-tag.c to gplate-variable-tag-test.c
renamed test-text-tag.c to gplate-text-tag-test.c
     1 #include <gplate/gplate.h>
     2 
     3 #include <glib.h>
     4 
     5 #include "gplate-tag-test.h"
     6 
     7 /******************************************************************************
     8  * Tests
     9  *****************************************************************************/
    10 static void
    11 gplate_variable_tag_test_single(GPlateTagTestFixture *fixture,
    12                                 gconstpointer data)
    13 {
    14 	gplate_collection_add_string(GPLATE_COLLECTION(fixture->template),
    15 	                             "foo", "bar");
    16 
    17 	fixture->template_string = "{{ foo }}";
    18 	fixture->expected = "bar";
    19 
    20 	gplate_tag_test_output(fixture, data);
    21 }
    22 
    23 static void
    24 gplate_variable_tag_test_double(GPlateTagTestFixture *fixture,
    25                                 gconstpointer data)
    26 {
    27 	gplate_collection_add_string(GPLATE_COLLECTION(fixture->template),
    28 	                             "foo", "foo");
    29 	gplate_collection_add_string(GPLATE_COLLECTION(fixture->template),
    30 	                             "bar", "bar");
    31 
    32 	fixture->template_string = "{{ foo }}{{ bar }}";
    33 	fixture->expected = "foobar";
    34 
    35 	gplate_tag_test_output(fixture, data);
    36 }
    37 
    38 static void
    39 gplate_variable_tag_test_tripple(GPlateTagTestFixture *fixture,
    40                                  gconstpointer data)
    41 {
    42 	gplate_collection_add_string(GPLATE_COLLECTION(fixture->template),
    43 	                             "foo", "foo");
    44 	gplate_collection_add_string(GPLATE_COLLECTION(fixture->template),
    45 	                             "bar", "bar");
    46 	gplate_collection_add_string(GPLATE_COLLECTION(fixture->template),
    47 	                             "baz", "baz");
    48 
    49 	fixture->template_string = "{{ foo }}{{ bar }}{{ baz }}";
    50 	fixture->expected = "foobarbaz";
    51 
    52 	gplate_tag_test_output(fixture, data);
    53 }
    54 
    55 static void
    56 gplate_variable_tag_test_newline_prefix(GPlateTagTestFixture *fixture,
    57                                         gconstpointer data)
    58 {
    59 	gplate_collection_add_string(GPLATE_COLLECTION(fixture->template),
    60 	                             "foo", "bar");
    61 
    62 	fixture->template_string = "{{\nfoo}}";
    63 	fixture->expected = "bar";
    64 
    65 	gplate_tag_test_output(fixture, data);
    66 }
    67 
    68 static void
    69 gplate_variable_tag_test_newline_suffix(GPlateTagTestFixture *fixture,
    70                                         gconstpointer data)
    71 {
    72 	gplate_collection_add_string(GPLATE_COLLECTION(fixture->template),
    73 	                             "foo", "bar");
    74 
    75 	fixture->template_string = "{{foo\n}}";
    76 	fixture->expected = "bar";
    77 
    78 	gplate_tag_test_output(fixture, data);
    79 }
    80 
    81 static void
    82 gplate_variable_tag_test_newline_wrapped(GPlateTagTestFixture *fixture,
    83                                          gconstpointer data)
    84 {
    85 	gplate_collection_add_string(GPLATE_COLLECTION(fixture->template),
    86 	                             "foo", "bar");
    87 
    88 	fixture->template_string = "{{\nfoo\n}}";
    89 	fixture->expected = "bar";
    90 
    91 	gplate_tag_test_output(fixture, data);
    92 }
    93 
    94 /******************************************************************************
    95  * Main
    96  *****************************************************************************/
    97 gint
    98 main(gint argc, gchar **argv) {
    99 	g_test_init(&argc, &argv, NULL);
   100 
   101 	g_type_init();
   102 
   103 	gplate_config_load_default();
   104 
   105 	gplate_tag_test_add("/tags/variable/single",
   106 	                    gplate_variable_tag_test_single);
   107 
   108 	gplate_tag_test_add("/tags/variable/double",
   109 	                    gplate_variable_tag_test_double);
   110 
   111 	gplate_tag_test_add("/tags/variable/tripple",
   112 	                    gplate_variable_tag_test_tripple);
   113 
   114 	gplate_tag_test_add("/tags/variable/newline_prefix",
   115 	                    gplate_variable_tag_test_newline_prefix);
   116 
   117 	gplate_tag_test_add("/tags/variable/newline_suffix",
   118 	                    gplate_variable_tag_test_newline_suffix);
   119 
   120 	gplate_tag_test_add("/tags/variable/newline_wrapped",
   121 	                    gplate_variable_tag_test_newline_wrapped);
   122 
   123 	return g_test_run();
   124 }
   125