aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2020-05-29 01:23:04 +0200
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2020-05-29 01:23:04 +0200
commit050d32ae204b64f7098b12c77cdb92a33ebc7562 (patch)
tree94868415de1ed42705769b6354c012220572b806 /tests
parent82a6868991472fc0b95981c3f116f5583254fa06 (diff)
downloadblogc-050d32ae204b64f7098b12c77cdb92a33ebc7562.tar.gz
blogc-050d32ae204b64f7098b12c77cdb92a33ebc7562.tar.bz2
blogc-050d32ae204b64f7098b12c77cdb92a33ebc7562.zip
blogc: added filelist parser
Diffstat (limited to 'tests')
-rw-r--r--tests/blogc/check_filelist_parser.c131
1 files changed, 131 insertions, 0 deletions
diff --git a/tests/blogc/check_filelist_parser.c b/tests/blogc/check_filelist_parser.c
new file mode 100644
index 0000000..0db50ec
--- /dev/null
+++ b/tests/blogc/check_filelist_parser.c
@@ -0,0 +1,131 @@
+/*
+ * blogc: A blog compiler.
+ * Copyright (C) 2014-2019 Rafael G. Martins <rafael@rafaelmartins.eng.br>
+ *
+ * This program can be distributed under the terms of the BSD License.
+ * See the file LICENSE.
+ */
+
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include <string.h>
+#include <stdlib.h>
+#include "../../src/common/utils.h"
+#include "../../src/blogc/filelist-parser.h"
+
+
+static void
+test_filelist_parse_empty(void **state)
+{
+ bc_slist_t *l = blogc_filelist_parse("", 0);
+ assert_null(l);
+}
+
+
+static void
+test_filelist_parse(void **state)
+{
+ const char *a =
+ "content/post/post1.txt";
+ bc_slist_t *l = blogc_filelist_parse(a, strlen(a));
+ assert_non_null(l);
+ assert_string_equal(l->data, "content/post/post1.txt");
+ assert_null(l->next);
+ bc_slist_free_full(l, free);
+ a =
+ "content/post/post1.txt\n";
+ l = blogc_filelist_parse(a, strlen(a));
+ assert_non_null(l);
+ assert_string_equal(l->data, "content/post/post1.txt");
+ assert_null(l->next);
+ bc_slist_free_full(l, free);
+ a =
+ "content/post/post1.txt\n"
+ "content/post/post2.txt\n";
+ l = blogc_filelist_parse(a, strlen(a));
+ assert_non_null(l);
+ assert_string_equal(l->data, "content/post/post1.txt");
+ assert_string_equal(l->next->data, "content/post/post2.txt");
+ assert_null(l->next->next);
+ bc_slist_free_full(l, free);
+ a =
+ "content/post/post1.txt\n"
+ "content/post/post2.txt\n"
+ "content/post/post3.txt";
+ l = blogc_filelist_parse(a, strlen(a));
+ assert_non_null(l);
+ assert_string_equal(l->data, "content/post/post1.txt");
+ assert_string_equal(l->next->data, "content/post/post2.txt");
+ assert_string_equal(l->next->next->data, "content/post/post3.txt");
+ assert_null(l->next->next->next);
+ bc_slist_free_full(l, free);
+ a =
+ " content/post/post1.txt\n"
+ "content/post/post2.txt\t\n"
+ "\tcontent/post/post3.txt";
+ l = blogc_filelist_parse(a, strlen(a));
+ assert_non_null(l);
+ assert_string_equal(l->data, "content/post/post1.txt");
+ assert_string_equal(l->next->data, "content/post/post2.txt");
+ assert_string_equal(l->next->next->data, "content/post/post3.txt");
+ assert_null(l->next->next->next);
+ bc_slist_free_full(l, free);
+}
+
+
+static void
+test_filelist_parse_crlf(void **state)
+{
+ const char *a =
+ "content/post/post1.txt\r\n";
+ bc_slist_t *l = blogc_filelist_parse(a, strlen(a));
+ assert_non_null(l);
+ assert_string_equal(l->data, "content/post/post1.txt");
+ assert_null(l->next);
+ bc_slist_free_full(l, free);
+ a =
+ "content/post/post1.txt\r\n"
+ "content/post/post2.txt\r\n";
+ l = blogc_filelist_parse(a, strlen(a));
+ assert_non_null(l);
+ assert_string_equal(l->data, "content/post/post1.txt");
+ assert_string_equal(l->next->data, "content/post/post2.txt");
+ assert_null(l->next->next);
+ bc_slist_free_full(l, free);
+ a =
+ "content/post/post1.txt\r\n"
+ "content/post/post2.txt\r\n"
+ "content/post/post3.txt";
+ l = blogc_filelist_parse(a, strlen(a));
+ assert_non_null(l);
+ assert_string_equal(l->data, "content/post/post1.txt");
+ assert_string_equal(l->next->data, "content/post/post2.txt");
+ assert_string_equal(l->next->next->data, "content/post/post3.txt");
+ assert_null(l->next->next->next);
+ bc_slist_free_full(l, free);
+ a =
+ " content/post/post1.txt\r\n"
+ "content/post/post2.txt\t\r\n"
+ "\tcontent/post/post3.txt";
+ l = blogc_filelist_parse(a, strlen(a));
+ assert_non_null(l);
+ assert_string_equal(l->data, "content/post/post1.txt");
+ assert_string_equal(l->next->data, "content/post/post2.txt");
+ assert_string_equal(l->next->next->data, "content/post/post3.txt");
+ assert_null(l->next->next->next);
+ bc_slist_free_full(l, free);
+}
+
+
+int
+main(void)
+{
+ const UnitTest tests[] = {
+ unit_test(test_filelist_parse_empty),
+ unit_test(test_filelist_parse),
+ unit_test(test_filelist_parse_crlf),
+ };
+ return run_tests(tests);
+}