aboutsummaryrefslogtreecommitdiffstats
path: root/tests/check_source_parser.c
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2015-04-17 01:47:41 -0300
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2015-04-17 01:47:41 -0300
commit047e4e3753c597628024847a524d44ca67fa1382 (patch)
tree8c0d63ecd8d395815a4eee155c2ce6283e0e7fab /tests/check_source_parser.c
parentf5da9cc42acc79d7dda78e57fab8a1b8d7aa6a7d (diff)
downloadblogc-047e4e3753c597628024847a524d44ca67fa1382.tar.gz
blogc-047e4e3753c597628024847a524d44ca67fa1382.tar.bz2
blogc-047e4e3753c597628024847a524d44ca67fa1382.zip
replaced leg-based parser with handmade parser for source files
Diffstat (limited to 'tests/check_source_parser.c')
-rw-r--r--tests/check_source_parser.c77
1 files changed, 77 insertions, 0 deletions
diff --git a/tests/check_source_parser.c b/tests/check_source_parser.c
new file mode 100644
index 0000000..2f5880a
--- /dev/null
+++ b/tests/check_source_parser.c
@@ -0,0 +1,77 @@
+/*
+ * blogc: A blog compiler.
+ * Copyright (C) 2015 Rafael G. Martins <rafael@rafaelmartins.eng.br>
+ *
+ * This program can be distributed under the terms of the BSD License.
+ * See the file COPYING.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif /* HAVE_CONFIG_H */
+
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include <string.h>
+#include "../src/source-parser.h"
+
+
+static void
+test_source_parse(void **state)
+{
+ const char *a =
+ "VAR1: asd asd\n"
+ "VAR2: 123chunda\n"
+ "----------\n"
+ "# This is a test\n"
+ "\n"
+ "bola\n";
+ blogc_source_t *source = blogc_source_parse(a, strlen(a));
+ assert_non_null(source);
+ assert_int_equal(b_trie_size(source->config), 2);
+ assert_string_equal(b_trie_lookup(source->config, "VAR1"), "asd asd");
+ assert_string_equal(b_trie_lookup(source->config, "VAR2"), "123chunda");
+ assert_string_equal(source->content,
+ "# This is a test\n"
+ "\n"
+ "bola\n");
+ blogc_source_free(source);
+}
+
+
+static void
+test_source_parse_with_spaces(void **state)
+{
+ const char *a =
+ "\n \n"
+ "VAR1: chunda \t \n"
+ "\n\n"
+ "BOLA: guda\n"
+ "----------\n"
+ "# This is a test\n"
+ "\n"
+ "bola\n";
+ blogc_source_t *source = blogc_source_parse(a, strlen(a));
+ assert_non_null(source);
+ assert_int_equal(b_trie_size(source->config), 2);
+ assert_string_equal(b_trie_lookup(source->config, "VAR1"), "chunda");
+ assert_string_equal(b_trie_lookup(source->config, "BOLA"), "guda");
+ assert_string_equal(source->content,
+ "# This is a test\n"
+ "\n"
+ "bola\n");
+ blogc_source_free(source);
+}
+
+
+int
+main(void)
+{
+ const UnitTest tests[] = {
+ unit_test(test_source_parse),
+ unit_test(test_source_parse_with_spaces),
+ };
+ return run_tests(tests);
+}