grim/gplate

Parents 13b5031b2846
Children b90b9411363f
finally got all of the tests in here moved to the new format

refs #16
--- a/tests/test-syntax.c Sun Jul 04 15:34:45 2010 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,212 +0,0 @@
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif /* HAVE_CONFIG_H */
-
-#include <check.h>
-
-#include <stdio.h>
-#include <string.h>
-
-#include <gplate/gplate.h>
-
-#include "test.h"
-
-#define OUTPUT_TEST(tplate, input, output) { \
- gchar *o = NULL, *msg = NULL; \
- \
- o = gplate_template_render(tplate, input, NULL); \
- \
- msg = g_strdup_printf("\ngot: '%s'\nwanted: '%s'\n", \
- g_strescape(o, NULL), g_strescape(output, NULL)); \
- \
- fail_unless(g_ascii_strcasecmp(o, output) == 0, msg); \
-}
-
-#define SIMPLE_OUTPUT_TEST(input, output) { \
- GPlateTemplate *tplate = gplate_template_new(); \
- OUTPUT_TEST(tplate, input, output); \
-}
-
-/******************************************************************************
- * Text Tags
- *****************************************************************************/
-START_TEST(test_syntax_no_keywords_no_variables)
- SIMPLE_OUTPUT_TEST("simple template",
- "simple template");
-END_TEST
-
-START_TEST(test_syntax_keywords_no_subst)
- SIMPLE_OUTPUT_TEST("extends if else endif for endfor",
- "extends if else endif for endfor");
-END_TEST
-
-START_TEST(test_syntax_keywords_no_subst_case)
- SIMPLE_OUTPUT_TEST("EXteNds iF eLse enDif fOr enDFor",
- "EXteNds iF eLse enDif fOr enDFor");
-END_TEST
-
-/******************************************************************************
- * Variable Tags
- *****************************************************************************/
-START_TEST(test_syntax_one_var)
- GPlateTemplate *tplate = gplate_template_new();
-
- gplate_collection_add_integer(tplate, "two", 2);
-
- OUTPUT_TEST(tplate, "one {{ two }} three", "one 2 three");
-END_TEST
-
-START_TEST(test_variable_newline_prefix)
- GPlateTemplate *tplate = gplate_template_new();
-
- gplate_collection_add_string(tplate, "bar", "|");
-
- OUTPUT_TEST(tplate, "{{\nbar}}", "|");
-END_TEST
-
-START_TEST(test_variable_newline_suffix)
- GPlateTemplate *tplate = gplate_template_new();
-
- gplate_collection_add_string(tplate, "bar", "|");
-
- OUTPUT_TEST(tplate, "{{bar\n}}", "|");
-END_TEST
-
-START_TEST(test_variable_newline_wrapped)
- GPlateTemplate *tplate = gplate_template_new();
-
- gplate_collection_add_string(tplate, "bar", "|");
-
- OUTPUT_TEST(tplate, "{{\nbar\n}}", "|");
-END_TEST
-
-START_TEST(test_syntax_var_in_single_quotes)
- GPlateTemplate *tplate = gplate_template_new();
-
- gplate_collection_add_string(tplate, "quoted", "in quotes");
-
- OUTPUT_TEST(tplate, "abc '{{ quoted }}' xyz", "abc 'in quotes' xyz");
-END_TEST
-
-START_TEST(test_syntax_var_in_double_quotes)
- GPlateTemplate *tplate = gplate_template_new();
-
- gplate_collection_add_string(tplate, "quoted", "in quotes");
-
- OUTPUT_TEST(tplate, "abc \"{{ quoted }}\" xyz", "abc \"in quotes\" xyz");
-END_TEST
-
-START_TEST(test_syntax_var_in_anchor_tag)
- GPlateTemplate *tplate = gplate_template_new();
-
- gplate_collection_add_string(tplate, "href", "http://guifications.org");
-
- OUTPUT_TEST(tplate,
- "<a href=\"{{ href }}\">{{ href }}</a>",
- "<a href=\"http://guifications.org\">http://guifications.org</a>");
-END_TEST
-
-START_TEST(test_syntax_two_vars_one_block)
- GPlateTemplate *tplate = gplate_template_new();
-
- gplate_collection_add_integer(tplate, "two", 2);
- gplate_collection_add_integer(tplate, "three", 3);
-
- OUTPUT_TEST(tplate, "one {{ two three }} four", "one 2 four");
-END_TEST
-
-START_TEST(test_syntax_one_var_nested)
- GPlateTemplate *tplate = gplate_template_new();
- GPlateVariable *dict = NULL;
-
- dict = gplate_dictionary_variable_new("two");
- gplate_collection_add_variable(GPLATE_COLLECTION(tplate), dict);
-
- gplate_collection_add_integer(dict, "too", 2);
-
- OUTPUT_TEST(tplate, "one {{ two.too }} three", "one 2 three");
-END_TEST
-
-START_TEST(test_syntax_one_var_double_nested)
- GPlateTemplate *tplate = gplate_template_new();
- GPlateVariable *dict1 = NULL, *dict2 = NULL;
-
- dict1 = gplate_dictionary_variable_new("one");
- gplate_collection_add_variable(GPLATE_COLLECTION(tplate), dict1);
-
- dict2 = gplate_dictionary_variable_new("two");
- gplate_collection_add_variable(GPLATE_COLLECTION(dict1), dict2);
-
- gplate_collection_add_string(dict2, "five", "three sir!");
-
- OUTPUT_TEST(tplate,
- "one, two, five! {{ one.two.five }}",
- "one, two, five! three sir!");
-END_TEST
-
-/******************************************************************************
- * Comment Tags
- *****************************************************************************/
-START_TEST(test_comment_empty)
- SIMPLE_OUTPUT_TEST("{##}", "");
-END_TEST
-
-START_TEST(test_comment_simple)
- SIMPLE_OUTPUT_TEST("{#simple#}", "");
-END_TEST
-
-START_TEST(test_comment_simple_with_whitespace)
- SIMPLE_OUTPUT_TEST("{# simple #}", "");
-END_TEST
-
-START_TEST(test_comment_newline_prefix)
- SIMPLE_OUTPUT_TEST("{#\n1#}", "");
-END_TEST
-
-START_TEST(test_comment_newline_suffix)
- SIMPLE_OUTPUT_TEST("{#1\n#}", "");
-END_TEST
-
-START_TEST(test_comment_newline_wrapped)
- SIMPLE_OUTPUT_TEST("{#\n1\n#}", "");
-END_TEST
-
-/******************************************************************************
- * Exported
- *****************************************************************************/
-Suite *
-syntax_suite(void) {
- Suite *s = suite_create("Tag Suite");
- TCase *tc = NULL;
-
- tc = tcase_create("Text Tag");
- tcase_add_test(tc, test_syntax_no_keywords_no_variables);
- tcase_add_test(tc, test_syntax_keywords_no_subst);
- tcase_add_test(tc, test_syntax_keywords_no_subst_case);
- suite_add_tcase(s, tc);
-
- tc = tcase_create("Variable Tag");
- tcase_add_test(tc, test_syntax_one_var);
- tcase_add_test(tc, test_variable_newline_prefix);
- tcase_add_test(tc, test_variable_newline_suffix);
- tcase_add_test(tc, test_variable_newline_wrapped);
- tcase_add_test(tc, test_syntax_var_in_single_quotes);
- tcase_add_test(tc, test_syntax_var_in_double_quotes);
- tcase_add_test(tc, test_syntax_var_in_anchor_tag);
- tcase_add_test(tc, test_syntax_two_vars_one_block);
- tcase_add_test(tc, test_syntax_one_var_nested);
- tcase_add_test(tc, test_syntax_one_var_double_nested);
- suite_add_tcase(s, tc);
-
- tc = tcase_create("Comment Tag");
- tcase_add_test(tc, test_comment_empty);
- tcase_add_test(tc, test_comment_simple);
- tcase_add_test(tc, test_comment_simple_with_whitespace);
- tcase_add_test(tc, test_comment_newline_prefix);
- tcase_add_test(tc, test_comment_newline_suffix);
- tcase_add_test(tc, test_comment_newline_wrapped);
- suite_add_tcase(s, tc);
-
- return s;
-}
-