aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitmodules3
-rw-r--r--Makefile.am94
-rw-r--r--configure.ac13
m---------squareball0
-rw-r--r--src/content-parser.c252
-rw-r--r--src/datetime-parser.c4
-rw-r--r--src/error.c12
-rw-r--r--src/file.c8
-rw-r--r--src/loader.c86
-rw-r--r--src/loader.h8
-rw-r--r--src/main.c52
-rw-r--r--src/renderer.c46
-rw-r--r--src/renderer.h10
-rw-r--r--src/source-parser.c26
-rw-r--r--src/source-parser.h4
-rw-r--r--src/template-parser.c32
-rw-r--r--src/template-parser.h6
-rw-r--r--src/utils/mem.c42
-rw-r--r--src/utils/slist.c68
-rw-r--r--src/utils/strings.c283
-rw-r--r--src/utils/trie.c199
-rw-r--r--src/utils/utils.h77
-rw-r--r--tests/check_content_parser.c2
-rw-r--r--tests/check_error.c2
-rw-r--r--tests/check_loader.c544
-rw-r--r--tests/check_renderer.c224
-rw-r--r--tests/check_source_parser.c142
-rw-r--r--tests/check_template_parser.c62
-rw-r--r--tests/check_utils.c824
29 files changed, 847 insertions, 2278 deletions
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..061fb99
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "squareball"]
+ path = squareball
+ url = https://github.com/rafaelmartins/squareball.git
diff --git a/Makefile.am b/Makefile.am
index 78738cc..3f70901 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -6,15 +6,65 @@ AM_DISTCHECK_CONFIGURE_FLAGS = \
--enable-tests \
--enable-ronn \
--disable-valgrind \
+ --with-squareball=internal \
$(NULL)
+## squareball stuff
+
+SQUAREBALL_EXTRA_DIST_ = \
+ squareball/LICENSE \
+ squareball/README.md \
+ $(NULL)
+
+if USE_SYSTEM_SQUAREBALL
+
+SQUAREBALL_HEADERS_ =
+
+SQUAREBALL_SOURCES_ =
+
+SQUAREBALL_CFLAGS_ = \
+ $(SQUAREBALL_CFLAGS) \
+ $(NULL)
+
+SQUAREBALL_LIBS_ = \
+ $(SQUAREBALL_LIBS) \
+ $(NULL)
+
+else
+
+SQUAREBALL_HEADERS_ = \
+ squareball/src/squareball.h \
+ squareball/src/squareball/sb-mem.h \
+ squareball/src/squareball/sb-slist.h \
+ squareball/src/squareball/sb-string.h \
+ squareball/src/squareball/sb-trie.h \
+ squareball/src/squareball/sb-trie-private.h \
+ $(NULL)
+
+SQUAREBALL_SOURCES_ = \
+ squareball/src/sb-mem.c \
+ squareball/src/sb-slist.c \
+ squareball/src/sb-string.c \
+ squareball/src/sb-trie.c \
+ $(NULL)
+
+SQUAREBALL_CFLAGS_ = \
+ -I$(top_srcdir)/squareball/src \
+ $(NULL)
+
+SQUAREBALL_LIBS_ =
+
+endif
+
+
## File listings
EXTRA_DIST = \
autogen.sh \
LICENSE \
README.md \
+ $(SQUAREBALL_EXTRA_DIST_)
$(NULL)
CLEANFILES = \
@@ -32,7 +82,7 @@ noinst_HEADERS = \
src/renderer.h \
src/source-parser.h \
src/template-parser.h \
- src/utils/utils.h \
+ $(SQUAREBALL_HEADERS_)
$(NULL)
noinst_LTLIBRARIES = \
@@ -59,22 +109,20 @@ libblogc_la_SOURCES = \
src/renderer.c \
src/source-parser.c \
src/template-parser.c \
- src/utils/mem.c \
- src/utils/slist.c \
- src/utils/strings.c \
- src/utils/trie.c \
+ $(SQUAREBALL_SOURCES_) \
$(NULL)
libblogc_la_CFLAGS = \
$(AM_CFLAGS) \
-I$(top_srcdir)/src \
+ $(SQUAREBALL_CFLAGS_) \
$(NULL)
libblogc_la_LIBADD = \
$(LIBM) \
+ $(SQUAREBALL_LIBS_) \
$(NULL)
-
blogc_SOURCES = \
src/main.c \
$(NULL)
@@ -82,10 +130,12 @@ blogc_SOURCES = \
blogc_CFLAGS = \
$(AM_CFLAGS) \
-I$(top_srcdir)/src \
+ $(SQUAREBALL_CFLAGS_) \
$(NULL)
blogc_LDADD = \
libblogc.la \
+ $(SQUAREBALL_LIBS_) \
$(NULL)
@@ -160,7 +210,6 @@ check_PROGRAMS += \
tests/check_renderer \
tests/check_source_parser \
tests/check_template_parser \
- tests/check_utils \
$(NULL)
tests_check_error_SOURCES = \
@@ -169,6 +218,7 @@ tests_check_error_SOURCES = \
tests_check_error_CFLAGS = \
$(CMOCKA_CFLAGS) \
+ $(SQUAREBALL_CFLAGS_) \
$(NULL)
tests_check_error_LDFLAGS = \
@@ -177,6 +227,7 @@ tests_check_error_LDFLAGS = \
tests_check_error_LDADD = \
$(CMOCKA_LIBS) \
+ $(SQUAREBALL_LIBS_) \
libblogc.la \
$(NULL)
@@ -186,6 +237,7 @@ tests_check_loader_SOURCES = \
tests_check_loader_CFLAGS = \
$(CMOCKA_CFLAGS) \
+ $(SQUAREBALL_CFLAGS_) \
$(NULL)
tests_check_loader_LDFLAGS = \
@@ -196,6 +248,7 @@ tests_check_loader_LDFLAGS = \
tests_check_loader_LDADD = \
$(CMOCKA_LIBS) \
+ $(SQUAREBALL_LIBS_) \
libblogc.la \
$(NULL)
@@ -205,6 +258,7 @@ tests_check_content_parser_SOURCES = \
tests_check_content_parser_CFLAGS = \
$(CMOCKA_CFLAGS) \
+ $(SQUAREBALL_CFLAGS_) \
$(NULL)
tests_check_content_parser_LDFLAGS = \
@@ -213,6 +267,7 @@ tests_check_content_parser_LDFLAGS = \
tests_check_content_parser_LDADD = \
$(CMOCKA_LIBS) \
+ $(SQUAREBALL_LIBS_) \
libblogc.la \
$(NULL)
@@ -222,6 +277,7 @@ tests_check_datetime_parser_SOURCES = \
tests_check_datetime_parser_CFLAGS = \
$(CMOCKA_CFLAGS) \
+ $(SQUAREBALL_CFLAGS_) \
$(NULL)
tests_check_datetime_parser_LDFLAGS = \
@@ -230,6 +286,7 @@ tests_check_datetime_parser_LDFLAGS = \
tests_check_datetime_parser_LDADD = \
$(CMOCKA_LIBS) \
+ $(SQUAREBALL_LIBS_) \
libblogc.la \
$(NULL)
@@ -239,6 +296,7 @@ tests_check_renderer_SOURCES = \
tests_check_renderer_CFLAGS = \
$(CMOCKA_CFLAGS) \
+ $(SQUAREBALL_CFLAGS_) \
$(NULL)
tests_check_renderer_LDFLAGS = \
@@ -247,6 +305,7 @@ tests_check_renderer_LDFLAGS = \
tests_check_renderer_LDADD = \
$(CMOCKA_LIBS) \
+ $(SQUAREBALL_LIBS_) \
libblogc.la \
$(NULL)
@@ -256,6 +315,7 @@ tests_check_source_parser_SOURCES = \
tests_check_source_parser_CFLAGS = \
$(CMOCKA_CFLAGS) \
+ $(SQUAREBALL_CFLAGS_) \
$(NULL)
tests_check_source_parser_LDFLAGS = \
@@ -264,6 +324,7 @@ tests_check_source_parser_LDFLAGS = \
tests_check_source_parser_LDADD = \
$(CMOCKA_LIBS) \
+ $(SQUAREBALL_LIBS_) \
libblogc.la \
$(NULL)
@@ -273,6 +334,7 @@ tests_check_template_parser_SOURCES = \
tests_check_template_parser_CFLAGS = \
$(CMOCKA_CFLAGS) \
+ $(SQUAREBALL_CFLAGS_) \
$(NULL)
tests_check_template_parser_LDFLAGS = \
@@ -281,23 +343,7 @@ tests_check_template_parser_LDFLAGS = \
tests_check_template_parser_LDADD = \
$(CMOCKA_LIBS) \
- libblogc.la \
- $(NULL)
-
-tests_check_utils_SOURCES = \
- tests/check_utils.c \
- $(NULL)
-
-tests_check_utils_CFLAGS = \
- $(CMOCKA_CFLAGS) \
- $(NULL)
-
-tests_check_utils_LDFLAGS = \
- -no-install \
- $(NULL)
-
-tests_check_utils_LDADD = \
- $(CMOCKA_LIBS) \
+ $(SQUAREBALL_LIBS_) \
libblogc.la \
$(NULL)
diff --git a/configure.ac b/configure.ac
index 3cfb07d..30f36c6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -22,6 +22,18 @@ AS_IF([test "x$ac_cv_prog_cc_c99" = "xno"], [
PKG_PROG_PKG_CONFIG
+SQUAREBALL="internal"
+AC_ARG_WITH([squareball], [AS_HELP_STRING([--with-squareball=@<:@internal/system@:>@],
+ [whether to use library squareball from system [default=internal]])])
+AS_IF([test "x$with_squareball" = "xsystem"], [
+ PKG_CHECK_MODULES([SQUAREBALL], [squareball], [
+ SQUAREBALL="system"
+ ], [
+ AC_MSG_ERROR([library squareball requested from system but not found])
+ ])
+])
+AM_CONDITIONAL(USE_SYSTEM_SQUAREBALL, [test "x$with_squareball" = "xsystem"])
+
AC_ARG_ENABLE([ronn], AS_HELP_STRING([--disable-ronn],
[ignore presence of ronn and disable man pages generation]))
AS_IF([test "x$enable_ronn" != "xno"], [
@@ -117,6 +129,7 @@ AS_ECHO("
tests: ${TESTS}
+ squareball: ${SQUAREBALL}
ronn: ${RONN}
valgrind: ${VALGRIND}
")
diff --git a/squareball b/squareball
new file mode 160000
+Subproject ebf83dd6d91d271b7cad6f89a3a7a2ef61bdff3
diff --git a/src/content-parser.c b/src/content-parser.c
index f5450d6..1a80572 100644
--- a/src/content-parser.c
+++ b/src/content-parser.c
@@ -12,8 +12,8 @@
#include <stdbool.h>
#include <string.h>
+#include <squareball.h>
-#include "utils/utils.h"
#include "content-parser.h"
// this is a half ass implementation of a markdown-like syntax. bugs are
@@ -25,7 +25,7 @@ blogc_slugify(const char *str)
{
if (str == NULL)
return NULL;
- char *new_str = b_strdup(str);
+ char *new_str = sb_strdup(str);
int diff = 'a' - 'A'; // just to avoid magic numbers
for (unsigned int i = 0; new_str[i] != '\0'; i++) {
if (new_str[i] >= 'a' && new_str[i] <= 'z')
@@ -92,7 +92,7 @@ blogc_content_parse_inline(const char *src)
size_t start_state = 0;
size_t end = 0;
- b_string_t *rv = b_string_new();
+ sb_string_t *rv = sb_string_new();
bool open_em_ast = false;
bool open_strong_ast = false;
@@ -118,7 +118,7 @@ blogc_content_parse_inline(const char *src)
if (escape) {
if (state == LINK_CLOSED)
- b_string_append_c(rv, c);
+ sb_string_append_c(rv, c);
current++;
escape = false;
continue;
@@ -131,7 +131,7 @@ blogc_content_parse_inline(const char *src)
case '\\':
if (state == LINK_CLOSED && (open_code || open_code_double)) {
- b_string_append_c(rv, c);
+ sb_string_append_c(rv, c);
break;
}
if (!escape)
@@ -141,7 +141,7 @@ blogc_content_parse_inline(const char *src)
case '*':
case '_':
if (state == LINK_CLOSED && (open_code || open_code_double)) {
- b_string_append_c(rv, c);
+ sb_string_append_c(rv, c);
break;
}
if (!is_last && src[current + 1] == c) {
@@ -150,7 +150,7 @@ blogc_content_parse_inline(const char *src)
(c == '_' && open_strong_und))
{
if (state == LINK_CLOSED)
- b_string_append(rv, "</strong>");
+ sb_string_append(rv, "</strong>");
if (c == '*')
open_strong_ast = false;
else
@@ -158,7 +158,7 @@ blogc_content_parse_inline(const char *src)
break;
}
if (state == LINK_CLOSED)
- b_string_append(rv, "<strong>");
+ sb_string_append(rv, "<strong>");
if (c == '*')
open_strong_ast = true;
else
@@ -167,7 +167,7 @@ blogc_content_parse_inline(const char *src)
}
if ((c == '*' && open_em_ast) || (c == '_' && open_em_und)) {
if (state == LINK_CLOSED)
- b_string_append(rv, "</em>");
+ sb_string_append(rv, "</em>");
if (c == '*')
open_em_ast = false;
else
@@ -175,7 +175,7 @@ blogc_content_parse_inline(const char *src)
break;
}
if (state == LINK_CLOSED)
- b_string_append(rv, "<em>");
+ sb_string_append(rv, "<em>");
if (c == '*')
open_em_ast = true;
else
@@ -186,19 +186,19 @@ blogc_content_parse_inline(const char *src)
if (!is_last && src[current + 1] == c) {
current++;
if (state == LINK_CLOSED)
- b_string_append_printf(rv, "<%scode>",
+ sb_string_append_printf(rv, "<%scode>",
open_code_double ? "/" : "");
open_code_double = !open_code_double;
break;
}
if (state == LINK_CLOSED)
- b_string_append_printf(rv, "<%scode>", open_code ? "/" : "");
+ sb_string_append_printf(rv, "<%scode>", open_code ? "/" : "");
open_code = !open_code;
break;
case '!':
if (state == LINK_CLOSED && (open_code || open_code_double)) {
- b_string_append_c(rv, c);
+ sb_string_append_c(rv, c);
break;
}
if (state == LINK_CLOSED) {
@@ -210,7 +210,7 @@ blogc_content_parse_inline(const char *src)
case '[':
if (state == LINK_CLOSED && (open_code || open_code_double)) {
- b_string_append_c(rv, c);
+ sb_string_append_c(rv, c);
break;
}
if (state == LINK_CLOSED || state == LINK_IMAGE) {
@@ -240,8 +240,8 @@ blogc_content_parse_inline(const char *src)
}
if (state == LINK_AUTO_CLOSE) {
state = LINK_CLOSED;
- tmp = b_strndup(src + start, end - start);
- b_string_append_printf(rv, "<a href=\"%s\">%s</a>", tmp, tmp);
+ tmp = sb_strndup(src + start, end - start);
+ sb_string_append_printf(rv, "<a href=\"%s\">%s</a>", tmp, tmp);
end = 0;
free(tmp);
tmp = NULL;
@@ -251,7 +251,7 @@ blogc_content_parse_inline(const char *src)
if (state == LINK_TEXT) {
if (open_bracket-- == 0) {
state = LINK_TEXT_CLOSE;
- tmp = b_strndup(src + start, current - start);
+ tmp = sb_strndup(src + start, current - start);
tmp2 = blogc_content_parse_inline(tmp);
free(tmp);
tmp = NULL;
@@ -259,7 +259,7 @@ blogc_content_parse_inline(const char *src)
break;
}
if (state == LINK_CLOSED)
- b_string_append_c(rv, c);
+ sb_string_append_c(rv, c);
break;
case '(':
@@ -269,18 +269,18 @@ blogc_content_parse_inline(const char *src)
break;
}
if (state == LINK_CLOSED)
- b_string_append_c(rv, c);
+ sb_string_append_c(rv, c);
break;
case ')':
if (state == LINK_URL) {
state = LINK_CLOSED;
- tmp = b_strndup(src + start, current - start);
+ tmp = sb_strndup(src + start, current - start);
if (is_image)
- b_string_append_printf(rv, "<img src=\"%s\" alt=\"%s\">",
+ sb_string_append_printf(rv, "<img src=\"%s\" alt=\"%s\">",
tmp, tmp2);
else
- b_string_append_printf(rv, "<a href=\"%s\">%s</a>",
+ sb_string_append_printf(rv, "<a href=\"%s\">%s</a>",
tmp, tmp2);
free(tmp);
tmp = NULL;
@@ -290,13 +290,13 @@ blogc_content_parse_inline(const char *src)
break;
}
if (state == LINK_CLOSED)
- b_string_append_c(rv, c);
+ sb_string_append_c(rv, c);
break;
case ' ':
if (state == LINK_CLOSED) {
spaces++;
- b_string_append_c(rv, c);
+ sb_string_append_c(rv, c);
}
if (!is_last)
break;
@@ -305,53 +305,53 @@ blogc_content_parse_inline(const char *src)
case '\r':
if (state == LINK_CLOSED) {
if (spaces >= 2) {
- b_string_append(rv, "<br />");
+ sb_string_append(rv, "<br />");
spaces = 0;
}
if (c == '\n' || c == '\r')
- b_string_append_c(rv, c);
+ sb_string_append_c(rv, c);
}
break;
case '&':
if (state == LINK_CLOSED)
- b_string_append(rv, "&amp;");
+ sb_string_append(rv, "&amp;");
break;
case '<':
if (state == LINK_CLOSED)
- b_string_append(rv, "&lt;");
+ sb_string_append(rv, "&lt;");
break;
case '>':
if (state == LINK_CLOSED)
- b_string_append(rv, "&gt;");
+ sb_string_append(rv, "&gt;");
break;
case '"':
if (state == LINK_CLOSED)
- b_string_append(rv, "&quot;");
+ sb_string_append(rv, "&quot;");
break;
case '\'':
if (state == LINK_CLOSED)
- b_string_append(rv, "&#x27;");
+ sb_string_append(rv, "&#x27;");
break;
case '/':
if (state == LINK_CLOSED)
- b_string_append(rv, "&#x2F;");
+ sb_string_append(rv, "&#x2F;");
break;
default:
if (state == LINK_CLOSED)
- b_string_append_c(rv, c);
+ sb_string_append_c(rv, c);
}
if (is_last && state != LINK_CLOSED) {
- b_string_append_c(rv, src[start_state]);
+ sb_string_append_c(rv, src[start_state]);
tmp = blogc_content_parse_inline(src + start_state + 1);
- b_string_append(rv, tmp);
+ sb_string_append(rv, tmp);
free(tmp);
tmp = NULL;
}
@@ -361,7 +361,7 @@ blogc_content_parse_inline(const char *src)
free(tmp);
free(tmp2);
- return b_string_free(rv, false);
+ return sb_string_free(rv, false);
}
@@ -423,11 +423,11 @@ blogc_content_parse(const char *src, size_t *end_excerpt)
char d = '\0';
- b_slist_t *lines = NULL;
- b_slist_t *lines2 = NULL;
+ sb_slist_t *lines = NULL;
+ sb_slist_t *lines2 = NULL;
- b_string_t *rv = b_string_new();
- b_string_t *tmp_str = NULL;
+ sb_string_t *rv = sb_string_new();
+ sb_string_t *tmp_str = NULL;
blogc_content_parser_state_t state = CONTENT_START_LINE;
@@ -554,14 +554,14 @@ blogc_content_parse(const char *src, size_t *end_excerpt)
if (c == '\n' || c == '\r' || is_last) {
end = is_last && c != '\n' && c != '\r' ? src_len :
(real_end != 0 ? real_end : current);
- tmp = b_strndup(src + start, end - start);
+ tmp = sb_strndup(src + start, end - start);
parsed = blogc_content_parse_inline(tmp);
slug = blogc_slugify(tmp);
if (slug == NULL)
- b_string_append_printf(rv, "<h%d>%s</h%d>%s",
+ sb_string_append_printf(rv, "<h%d>%s</h%d>%s",
header_level, parsed, header_level, line_ending);
else
- b_string_append_printf(rv, "<h%d id=\"%s\">%s</h%d>%s",
+ sb_string_append_printf(rv, "<h%d id=\"%s\">%s</h%d>%s",
header_level, slug, parsed, header_level,
line_ending);
free(slug);
@@ -585,8 +585,8 @@ blogc_content_parse(const char *src, size_t *end_excerpt)
case CONTENT_HTML_END:
if (c == '\n' || c == '\r' || is_last) {
- tmp = b_strndup(src + start, end - start);
- b_string_append_printf(rv, "%s%s", tmp, line_ending);
+ tmp = sb_strndup(src + start, end - start);
+ sb_string_append_printf(rv, "%s%s", tmp, line_ending);
free(tmp);
tmp = NULL;
state = CONTENT_START_LINE;
@@ -599,7 +599,7 @@ blogc_content_parse(const char *src, size_t *end_excerpt)
case CONTENT_BLOCKQUOTE:
if (c == ' ' || c == '\t')
break;
- prefix = b_strndup(src + start, current - start);
+ prefix = sb_strndup(src + start, current - start);
state = CONTENT_BLOCKQUOTE_START;
break;
@@ -607,16 +607,16 @@ blogc_content_parse(const char *src, size_t *end_excerpt)
if (c == '\n' || c == '\r' || is_last) {
end = is_last && c != '\n' && c != '\r' ? src_len :
(real_end != 0 ? real_end : current);
- tmp = b_strndup(src + start2, end - start2);
- if (b_str_starts_with(tmp, prefix)) {
- lines = b_slist_append(lines, b_strdup(tmp + strlen(prefix)));
+ tmp = sb_strndup(src + start2, end - start2);
+ if (sb_str_starts_with(tmp, prefix)) {
+ lines = sb_slist_append(lines, sb_strdup(tmp + strlen(prefix)));
state = CONTENT_BLOCKQUOTE_END;
}
else {
state = CONTENT_PARAGRAPH;
free(prefix);
prefix = NULL;
- b_slist_free_full(lines, free);
+ sb_slist_free_full(lines, free);
lines = NULL;
if (is_last) {
free(tmp);
@@ -632,22 +632,22 @@ blogc_content_parse(const char *src, size_t *end_excerpt)
case CONTENT_BLOCKQUOTE_END:
if (c == '\n' || c == '\r' || is_last) {
- tmp_str = b_string_new();
- for (b_slist_t *l = lines; l != NULL; l = l->next) {
+ tmp_str = sb_string_new();
+ for (sb_slist_t *l = lines; l != NULL; l = l->next) {
if (l->next == NULL)
- b_string_append_printf(tmp_str, "%s", l->data);
+ sb_string_append_printf(tmp_str, "%s", l->data);
else
- b_string_append_printf(tmp_str, "%s%s", l->data,
+ sb_string_append_printf(tmp_str, "%s%s", l->data,
line_ending);
}
tmp = blogc_content_parse(tmp_str->str, NULL);
- b_string_append_printf(rv, "<blockquote>%s</blockquote>%s",
+ sb_string_append_printf(rv, "<blockquote>%s</blockquote>%s",
tmp, line_ending);
free(tmp);
tmp = NULL;
- b_string_free(tmp_str, true);
+ sb_string_free(tmp_str, true);
tmp_str = NULL;
- b_slist_free_full(lines, free);
+ sb_slist_free_full(lines, free);
lines = NULL;
free(prefix);
prefix = NULL;
@@ -663,7 +663,7 @@ blogc_content_parse(const char *src, size_t *end_excerpt)
case CONTENT_CODE:
if (c == ' ' || c == '\t')
break;
- prefix = b_strndup(src + start, current - start);
+ prefix = sb_strndup(src + start, current - start);
state = CONTENT_CODE_START;
break;
@@ -671,16 +671,16 @@ blogc_content_parse(const char *src, size_t *end_excerpt)
if (c == '\n' || c == '\r' || is_last) {
end = is_last && c != '\n' && c != '\r' ? src_len :
(real_end != 0 ? real_end : current);
- tmp = b_strndup(src + start2, end - start2);
- if (b_str_starts_with(tmp, prefix)) {
- lines = b_slist_append(lines, b_strdup(tmp + strlen(prefix)));
+ tmp = sb_strndup(src + start2, end - start2);
+ if (sb_str_starts_with(tmp, prefix)) {
+ lines = sb_slist_append(lines, sb_strdup(tmp + strlen(prefix)));
state = CONTENT_CODE_END;
}
else {
state = CONTENT_PARAGRAPH;
free(prefix);
prefix = NULL;
- b_slist_free_full(lines, free);
+ sb_slist_free_full(lines, free);
lines = NULL;
free(tmp);
tmp = NULL;
@@ -696,16 +696,16 @@ blogc_content_parse(const char *src, size_t *end_excerpt)
case CONTENT_CODE_END:
if (c == '\n' || c == '\r' || is_last) {
- b_string_append(rv, "<pre><code>");
- for (b_slist_t *l = lines; l != NULL; l = l->next) {
+ sb_string_append(rv, "<pre><code>");
+ for (sb_slist_t *l = lines; l != NULL; l = l->next) {
if (l->next == NULL)
- b_string_append_printf(rv, "%s", l->data);
+ sb_string_append_printf(rv, "%s", l->data);
else
- b_string_append_printf(rv, "%s%s", l->data,
+ sb_string_append_printf(rv, "%s%s", l->data,
line_ending);
}
- b_string_append_printf(rv, "</code></pre>%s", line_ending);
- b_slist_free_full(lines, free);
+ sb_string_append_printf(rv, "</code></pre>%s", line_ending);
+ sb_slist_free_full(lines, free);
lines = NULL;
free(prefix);
prefix = NULL;
@@ -727,7 +727,7 @@ blogc_content_parse(const char *src, size_t *end_excerpt)
}
if (c == ' ' || c == '\t')
break;
- prefix = b_strndup(src + start, current - start);
+ prefix = sb_strndup(src + start, current - start);
state = CONTENT_UNORDERED_LIST_START;
break;
@@ -737,7 +737,7 @@ blogc_content_parse(const char *src, size_t *end_excerpt)
}
hr:
if (c == '\n' || c == '\r' || is_last) {
- b_string_append_printf(rv, "<hr />%s", line_ending);
+ sb_string_append_printf(rv, "<hr />%s", line_ending);
state = CONTENT_START_LINE;
start = current;
d = '\0';
@@ -750,30 +750,30 @@ hr:
if (c == '\n' || c == '\r' || is_last) {
end = is_last && c != '\n' && c != '\r' ? src_len :
(real_end != 0 ? real_end : current);
- tmp = b_strndup(src + start2, end - start2);
- tmp2 = b_strdup_printf("%-*s", strlen(prefix), "");
- if (b_str_starts_with(tmp, prefix)) {
+ tmp = sb_strndup(src + start2, end - start2);
+ tmp2 = sb_strdup_printf("%-*s", strlen(prefix), "");
+ if (sb_str_starts_with(tmp, prefix)) {
if (lines2 != NULL) {
- tmp_str = b_string_new();
- for (b_slist_t *l = lines2; l != NULL; l = l->next) {
+ tmp_str = sb_string_new();
+ for (sb_slist_t *l = lines2; l != NULL; l = l->next) {
if (l->next == NULL)
- b_string_append_printf(tmp_str, "%s", l->data);
+ sb_string_append_printf(tmp_str, "%s", l->data);
else
- b_string_append_printf(tmp_str, "%s%s", l->data,
+ sb_string_append_printf(tmp_str, "%s%s", l->data,
line_ending);
}
- b_slist_free_full(lines2, free);
+ sb_slist_free_full(lines2, free);
lines2 = NULL;
parsed = blogc_content_parse_inline(tmp_str->str);
- b_string_free(tmp_str, true);
- lines = b_slist_append(lines, b_strdup(parsed));
+ sb_string_free(tmp_str, true);
+ lines = sb_slist_append(lines, sb_strdup(parsed));
free(parsed);
parsed = NULL;
}
- lines2 = b_slist_append(lines2, b_strdup(tmp + strlen(prefix)));
+ lines2 = sb_slist_append(lines2, sb_strdup(tmp + strlen(prefix)));
}
- else if (b_str_starts_with(tmp, tmp2)) {
- lines2 = b_slist_append(lines2, b_strdup(tmp + strlen(prefix)));
+ else if (sb_str_starts_with(tmp, tmp2)) {
+ lines2 = sb_slist_append(lines2, sb_strdup(tmp + strlen(prefix)));
}
else {
state = CONTENT_PARAGRAPH_END;
@@ -783,8 +783,8 @@ hr:
tmp2 = NULL;
free(prefix);
prefix = NULL;
- b_slist_free_full(lines, free);
- b_slist_free_full(lines2, free);
+ sb_slist_free_full(lines, free);
+ sb_slist_free_full(lines2, free);
lines = NULL;
if (is_last)
goto para;
@@ -803,28 +803,28 @@ hr:
if (c == '\n' || c == '\r' || is_last) {
if (lines2 != NULL) {
// FIXME: avoid repeting the code below
- tmp_str = b_string_new();
- for (b_slist_t *l = lines2; l != NULL; l = l->next) {
+ tmp_str = sb_string_new();
+ for (sb_slist_t *l = lines2; l != NULL; l = l->next) {
if (l->next == NULL)
- b_string_append_printf(tmp_str, "%s", l->data);
+ sb_string_append_printf(tmp_str, "%s", l->data);
else
- b_string_append_printf(tmp_str, "%s%s", l->data,
+ sb_string_append_printf(tmp_str, "%s%s", l->data,
line_ending);
}
- b_slist_free_full(lines2, free);
+ sb_slist_free_full(lines2, free);
lines2 = NULL;
parsed = blogc_content_parse_inline(tmp_str->str);
- b_string_free(tmp_str, true);
- lines = b_slist_append(lines, b_strdup(parsed));
+ sb_string_free(tmp_str, true);
+ lines = sb_slist_append(lines, sb_strdup(parsed));
free(parsed);
parsed = NULL;
}
- b_string_append_printf(rv, "<ul>%s", line_ending);
- for (b_slist_t *l = lines; l != NULL; l = l->next)
- b_string_append_printf(rv, "<li>%s</li>%s", l->data,
+ sb_string_append_printf(rv, "<ul>%s", line_ending);
+ for (sb_slist_t *l = lines; l != NULL; l = l->next)
+ sb_string_append_printf(rv, "<li>%s</li>%s", l->data,
line_ending);
- b_string_append_printf(rv, "</ul>%s", line_ending);
- b_slist_free_full(lines, free);
+ sb_string_append_printf(rv, "</ul>%s", line_ending);
+ sb_slist_free_full(lines, free);
lines = NULL;
free(prefix);
prefix = NULL;
@@ -861,30 +861,30 @@ hr:
if (c == '\n' || c == '\r' || is_last) {
end = is_last && c != '\n' && c != '\r' ? src_len :
(real_end != 0 ? real_end : current);
- tmp = b_strndup(src + start2, end - start2);
- tmp2 = b_strdup_printf("%-*s", prefix_len, "");
+ tmp = sb_strndup(src + start2, end - start2);
+ tmp2 = sb_strdup_printf("%-*s", prefix_len, "");
if (blogc_is_ordered_list_item(tmp, prefix_len)) {
if (lines2 != NULL) {
- tmp_str = b_string_new();
- for (b_slist_t *l = lines2; l != NULL; l = l->next) {
+ tmp_str = sb_string_new();
+ for (sb_slist_t *l = lines2; l != NULL; l = l->next) {
if (l->next == NULL)
- b_string_append_printf(tmp_str, "%s", l->data);
+ sb_string_append_printf(tmp_str, "%s", l->data);
else
- b_string_append_printf(tmp_str, "%s%s", l->data,
+ sb_string_append_printf(tmp_str, "%s%s", l->data,
line_ending);
}
- b_slist_free_full(lines2, free);
+ sb_slist_free_full(lines2, free);
lines2 = NULL;
parsed = blogc_content_parse_inline(tmp_str->str);
- b_string_free(tmp_str, true);
- lines = b_slist_append(lines, b_strdup(parsed));
+ sb_string_free(tmp_str, true);
+ lines = sb_slist_append(lines, sb_strdup(parsed));
free(parsed);
parsed = NULL;
}
- lines2 = b_slist_append(lines2, b_strdup(tmp + prefix_len));
+ lines2 = sb_slist_append(lines2, sb_strdup(tmp + prefix_len));
}
- else if (b_str_starts_with(tmp, tmp2)) {
- lines2 = b_slist_append(lines2, b_strdup(tmp + prefix_len));
+ else if (sb_str_starts_with(tmp, tmp2)) {
+ lines2 = sb_slist_append(lines2, sb_strdup(tmp + prefix_len));
}
else {
state = CONTENT_PARAGRAPH_END;
@@ -894,8 +894,8 @@ hr:
tmp2 = NULL;
free(parsed);
parsed = NULL;
- b_slist_free_full(lines, free);
- b_slist_free_full(lines2, free);
+ sb_slist_free_full(lines, free);
+ sb_slist_free_full(lines2, free);
lines = NULL;
if (is_last)
goto para;
@@ -914,28 +914,28 @@ hr:
if (c == '\n' || c == '\r' || is_last) {
if (lines2 != NULL) {
// FIXME: avoid repeting the code below
- tmp_str = b_string_new();
- for (b_slist_t *l = lines2; l != NULL; l = l->next) {
+ tmp_str = sb_string_new();
+ for (sb_slist_t *l = lines2; l != NULL; l = l->next) {
if (l->next == NULL)
- b_string_append_printf(tmp_str, "%s", l->data);
+ sb_string_append_printf(tmp_str, "%s", l->data);
else
- b_string_append_printf(tmp_str, "%s%s", l->data,
+ sb_string_append_printf(tmp_str, "%s%s", l->data,
line_ending);
}
- b_slist_free_full(lines2, free);
+ sb_slist_free_full(lines2, free);
lines2 = NULL;
parsed = blogc_content_parse_inline(tmp_str->str);
- b_string_free(tmp_str, true);
- lines = b_slist_append(lines, b_strdup(parsed));
+ sb_string_free(tmp_str, true);
+ lines = sb_slist_append(lines, sb_strdup(parsed));
free(parsed);
parsed = NULL;
}
- b_string_append_printf(rv, "<ol>%s", line_ending);
- for (b_slist_t *l = lines; l != NULL; l = l->next)
- b_string_append_printf(rv, "<li>%s</li>%s", l->data,
+ sb_string_append_printf(rv, "<ol>%s", line_ending);
+ for (sb_slist_t *l = lines; l != NULL; l = l->next)
+ sb_string_append_printf(rv, "<li>%s</li>%s", l->data,
line_ending);
- b_string_append_printf(rv, "</ol>%s", line_ending);
- b_slist_free_full(lines, free);
+ sb_string_append_printf(rv, "</ol>%s", line_ending);
+ sb_slist_free_full(lines, free);
lines = NULL;
free(prefix);
prefix = NULL;
@@ -967,9 +967,9 @@ para:
else
end = src_len;
}
- tmp = b_strndup(src + start, end - start);
+ tmp = sb_strndup(src + start, end - start);
parsed = blogc_content_parse_inline(tmp);
- b_string_append_printf(rv, "<p>%s</p>%s", parsed,
+ sb_string_append_printf(rv, "<p>%s</p>%s", parsed,
line_ending);
free(parsed);
parsed = NULL;
@@ -987,5 +987,5 @@ para:
current++;
}
- return b_string_free(rv, false);
+ return sb_string_free(rv, false);
}
diff --git a/src/datetime-parser.c b/src/datetime-parser.c
index 6a2162d..50694da 100644
--- a/src/datetime-parser.c
+++ b/src/datetime-parser.c
@@ -17,7 +17,7 @@
#include <string.h>
#include "error.h"
-#include "utils/utils.h"
+#include <squareball.h>
#include "datetime-parser.h"
@@ -380,7 +380,7 @@ blogc_convert_datetime(const char *orig, const char *format,
return NULL;
}
- return b_strdup(buf);
+ return sb_strdup(buf);
#endif
}
diff --git a/src/error.c b/src/error.c
index 28396f8..94d6162 100644
--- a/src/error.c
+++ b/src/error.c
@@ -14,16 +14,16 @@
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
-#include "utils/utils.h"
+#include <squareball.h>
#include "error.h"
blogc_error_t*
blogc_error_new(blogc_error_type_t type, const char *msg)
{
- blogc_error_t *err = b_malloc(sizeof(blogc_error_t));
+ blogc_error_t *err = sb_malloc(sizeof(blogc_error_t));
err->type = type;
- err->msg = b_strdup(msg);
+ err->msg = sb_strdup(msg);
return err;
}
@@ -33,7 +33,7 @@ blogc_error_new_printf(blogc_error_type_t type, const char *format, ...)
{
va_list ap;
va_start(ap, format);
- char *tmp = b_strdup_vprintf(format, ap);
+ char *tmp = sb_strdup_vprintf(format, ap);
va_end(ap);
blogc_error_t *rv = blogc_error_new(type, tmp);
free(tmp);
@@ -47,7 +47,7 @@ blogc_error_parser(blogc_error_type_t type, const char *src, size_t src_len,
{
va_list ap;
va_start(ap, format);
- char *msg = b_strdup_vprintf(format, ap);
+ char *msg = sb_strdup_vprintf(format, ap);
va_end(ap);
size_t lineno = 1;
@@ -88,7 +88,7 @@ blogc_error_parser(blogc_error_type_t type, const char *src, size_t src_len,
if (lineend <= linestart && src_len >= linestart)
lineend = src_len;
- char *line = b_strndup(src + linestart, lineend - linestart);
+ char *line = sb_strndup(src + linestart, lineend - linestart);
blogc_error_t *rv = NULL;
diff --git a/src/file.c b/src/file.c
index d660afc..f6a69c3 100644
--- a/src/file.c
+++ b/src/file.c
@@ -14,7 +14,7 @@
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
-#include "utils/utils.h"
+#include <squareball.h>
#include "file.h"
#include "error.h"
@@ -38,16 +38,16 @@ blogc_file_get_contents(const char *path, size_t *len, blogc_error_t **err)
return NULL;
}
- b_string_t *str = b_string_new();
+ sb_string_t *str = sb_string_new();
char buffer[BLOGC_FILE_CHUNK_SIZE];
while (!feof(fp)) {
size_t read_len = fread(buffer, sizeof(char), BLOGC_FILE_CHUNK_SIZE, fp);
*len += read_len;
- b_string_append_len(str, buffer, read_len);
+ sb_string_append_len(str, buffer, read_len);
}
fclose(fp);
- return b_string_free(str, false);
+ return sb_string_free(str, false);
}
diff --git a/src/loader.c b/src/loader.c
index 8f04dae..6fc9581 100644
--- a/src/loader.c
+++ b/src/loader.c
@@ -14,7 +14,7 @@
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
-#include "utils/utils.h"
+#include <squareball.h>
#include "file.h"
#include "source-parser.h"
#include "template-parser.h"
@@ -31,7 +31,7 @@ blogc_get_filename(const char *f)
if (strlen(f) == 0)
return NULL;
- char *filename = b_strdup(f);
+ char *filename = sb_strdup(f);
// keep a pointer to original string
char *tmp = filename;
@@ -52,14 +52,14 @@ blogc_get_filename(const char *f)
}
}
- char *final_filename = b_strdup(tmp);
+ char *final_filename = sb_strdup(tmp);
free(filename);
return final_filename;
}
-b_slist_t*
+sb_slist_t*
blogc_template_parse_from_file(const char *f, blogc_error_t **err)
{
if (err == NULL || *err != NULL)
@@ -68,13 +68,13 @@ blogc_template_parse_from_file(const char *f, blogc_error_t **err)
char *s = blogc_file_get_contents(f, &len, err);
if (s == NULL)
return NULL;
- b_slist_t *rv = blogc_template_parse(s, len, err);
+ sb_slist_t *rv = blogc_template_parse(s, len, err);
free(s);
return rv;
}
-b_trie_t*
+sb_trie_t*
blogc_source_parse_from_file(const char *f, blogc_error_t **err)
{
if (err == NULL || *err != NULL)
@@ -83,13 +83,13 @@ blogc_source_parse_from_file(const char *f, blogc_error_t **err)
char *s = blogc_file_get_contents(f, &len, err);
if (s == NULL)
return NULL;
- b_trie_t *rv = blogc_source_parse(s, len, err);
+ sb_trie_t *rv = blogc_source_parse(s, len, err);
// set FILENAME variable
if (rv != NULL) {
char *filename = blogc_get_filename(f);
if (filename != NULL)
- b_trie_insert(rv, "FILENAME", filename);
+ sb_trie_insert(rv, "FILENAME", filename);
}
free(s);
@@ -97,16 +97,16 @@ blogc_source_parse_from_file(const char *f, blogc_error_t **err)
}
-b_slist_t*
-blogc_source_parse_from_files(b_trie_t *conf, b_slist_t *l, blogc_error_t **err)
+sb_slist_t*
+blogc_source_parse_from_files(sb_trie_t *conf, sb_slist_t *l, blogc_error_t **err)
{
blogc_error_t *tmp_err = NULL;
- b_slist_t *rv = NULL;
+ sb_slist_t *rv = NULL;
unsigned int with_date = 0;
- const char *filter_tag = b_trie_lookup(conf, "FILTER_TAG");
- const char *filter_page = b_trie_lookup(conf, "FILTER_PAGE");
- const char *filter_per_page = b_trie_lookup(conf, "FILTER_PER_PAGE");
+ const char *filter_tag = sb_trie_lookup(conf, "FILTER_TAG");
+ const char *filter_page = sb_trie_lookup(conf, "FILTER_PAGE");
+ const char *filter_per_page = sb_trie_lookup(conf, "FILTER_PER_PAGE");
long page = strtol(filter_page != NULL ? filter_page : "", NULL, 10);
if (page <= 0)
@@ -121,51 +121,51 @@ blogc_source_parse_from_files(b_trie_t *conf, b_slist_t *l, blogc_error_t **err)
unsigned int end = start + per_page;
unsigned int counter = 0;
- for (b_slist_t *tmp = l; tmp != NULL; tmp = tmp->next) {
+ for (sb_slist_t *tmp = l; tmp != NULL; tmp = tmp->next) {
char *f = tmp->data;
- b_trie_t *s = blogc_source_parse_from_file(f, &tmp_err);
+ sb_trie_t *s = blogc_source_parse_from_file(f, &tmp_err);
if (s == NULL) {
*err = blogc_error_new_printf(BLOGC_ERROR_LOADER,
"An error occurred while parsing source file: %s\n\n%s",
f, tmp_err->msg);
blogc_error_free(tmp_err);
tmp_err = NULL;
- b_slist_free_full(rv, (b_free_func_t) b_trie_free);
+ sb_slist_free_full(rv, (sb_free_func_t) sb_trie_free);
rv = NULL;
break;
}
if (filter_tag != NULL) {
- const char *tags_str = b_trie_lookup(s, "TAGS");
+ const char *tags_str = sb_trie_lookup(s, "TAGS");
// if user wants to filter by tag and no tag is provided, skip it
if (tags_str == NULL) {
- b_trie_free(s);
+ sb_trie_free(s);
continue;
}
- char **tags = b_str_split(tags_str, ',', 0);
+ char **tags = sb_str_split(tags_str, ',', 0);
bool found = false;
for (unsigned int i = 0; tags[i] != NULL; i++)
- if (0 == strcmp(b_str_strip(tags[i]), filter_tag))
+ if (0 == strcmp(sb_str_strip(tags[i]), filter_tag))
found = true;
- b_strv_free(tags);
+ sb_strv_free(tags);
if (!found) {
- b_trie_free(s);
+ sb_trie_free(s);
continue;
}
}
if (filter_page != NULL) {
if (counter < start || counter >= end) {
counter++;
- b_trie_free(s);
+ sb_trie_free(s);
continue;
}
counter++;
}
- if (b_trie_lookup(s, "DATE") != NULL)
+ if (sb_trie_lookup(s, "DATE") != NULL)
with_date++;
- rv = b_slist_append(rv, s);
+ rv = sb_slist_append(rv, s);
}
- if (with_date > 0 && with_date < b_slist_length(rv))
+ if (with_date > 0 && with_date < sb_slist_length(rv))
// fatal error, maybe?
blogc_fprintf(stderr,
"blogc: warning: 'DATE' variable provided for at least one source "
@@ -173,38 +173,38 @@ blogc_source_parse_from_files(b_trie_t *conf, b_slist_t *l, blogc_error_t **err)
"wrong values for 'DATE_FIRST' and 'DATE_LAST' variables.\n");
bool first = true;
- for (b_slist_t *tmp = rv; tmp != NULL; tmp = tmp->next) {
- b_trie_t *s = tmp->data;
+ for (sb_slist_t *tmp = rv; tmp != NULL; tmp = tmp->next) {
+ sb_trie_t *s = tmp->data;
if (first) {
- const char *val = b_trie_lookup(s, "DATE");
+ const char *val = sb_trie_lookup(s, "DATE");
if (val != NULL)
- b_trie_insert(conf, "DATE_FIRST", b_strdup(val));
- val = b_trie_lookup(s, "FILENAME");
+ sb_trie_insert(conf, "DATE_FIRST", sb_strdup(val));
+ val = sb_trie_lookup(s, "FILENAME");
if (val != NULL)
- b_trie_insert(conf, "FILENAME_FIRST", b_strdup(val));
+ sb_trie_insert(conf, "FILENAME_FIRST", sb_strdup(val));
first = false;
}
if (tmp->next == NULL) { // last
- const char *val = b_trie_lookup(s, "DATE");
+ const char *val = sb_trie_lookup(s, "DATE");
if (val != NULL)
- b_trie_insert(conf, "DATE_LAST", b_strdup(val));
- val = b_trie_lookup(s, "FILENAME");
+ sb_trie_insert(conf, "DATE_LAST", sb_strdup(val));
+ val = sb_trie_lookup(s, "FILENAME");
if (val != NULL)
- b_trie_insert(conf, "FILENAME_LAST", b_strdup(val));
+ sb_trie_insert(conf, "FILENAME_LAST", sb_strdup(val));
}
}
if (filter_page != NULL) {
unsigned int last_page = ceilf(((float) counter) / per_page);
- b_trie_insert(conf, "CURRENT_PAGE", b_strdup_printf("%ld", page));
+ sb_trie_insert(conf, "CURRENT_PAGE", sb_strdup_printf("%ld", page));
if (page > 1)
- b_trie_insert(conf, "PREVIOUS_PAGE", b_strdup_printf("%ld", page - 1));
+ sb_trie_insert(conf, "PREVIOUS_PAGE", sb_strdup_printf("%ld", page - 1));
if (page < last_page)
- b_trie_insert(conf, "NEXT_PAGE", b_strdup_printf("%ld", page + 1));
- if (b_slist_length(rv) > 0)
- b_trie_insert(conf, "FIRST_PAGE", b_strdup("1"));
+ sb_trie_insert(conf, "NEXT_PAGE", sb_strdup_printf("%ld", page + 1));
+ if (sb_slist_length(rv) > 0)
+ sb_trie_insert(conf, "FIRST_PAGE", sb_strdup("1"));
if (last_page > 0)
- b_trie_insert(conf, "LAST_PAGE", b_strdup_printf("%d", last_page));
+ sb_trie_insert(conf, "LAST_PAGE", sb_strdup_printf("%d", last_page));
}
return rv;
diff --git a/src/loader.h b/src/loader.h
index 610aa42..b4ce569 100644
--- a/src/loader.h
+++ b/src/loader.h
@@ -9,13 +9,13 @@
#ifndef _LOADER_H
#define _LOADER_H
-#include "utils/utils.h"
+#include <squareball.h>
#include "error.h"
char* blogc_get_filename(const char *f);
-b_slist_t* blogc_template_parse_from_file(const char *f, blogc_error_t **err);
-b_trie_t* blogc_source_parse_from_file(const char *f, blogc_error_t **err);
-b_slist_t* blogc_source_parse_from_files(b_trie_t *conf, b_slist_t *l,
+sb_slist_t* blogc_template_parse_from_file(const char *f, blogc_error_t **err);
+sb_trie_t* blogc_source_parse_from_file(const char *f, blogc_error_t **err);
+sb_slist_t* blogc_source_parse_from_files(sb_trie_t *conf, sb_slist_t *l,
blogc_error_t **err);
#endif /* _LOADER_H */
diff --git a/src/main.c b/src/main.c
index 600a131..3315a80 100644
--- a/src/main.c
+++ b/src/main.c
@@ -24,7 +24,7 @@
#include <stdio.h>
#include <string.h>
-#include "utils/utils.h"
+#include <squareball.h>
#include "source-parser.h"
#include "template-parser.h"
#include "loader.h"
@@ -71,7 +71,7 @@ blogc_print_usage(void)
static void
blogc_mkdir_recursive(const char *filename)
{
- char *fname = b_strdup(filename);
+ char *fname = sb_strdup(filename);
for (char *tmp = fname; *tmp != '\0'; tmp++) {
if (*tmp != '/' && *tmp != '\\')
continue;
@@ -117,9 +117,9 @@ main(int argc, char **argv)
char *tmp = NULL;
char **pieces = NULL;
- b_slist_t *sources = NULL;
- b_trie_t *config = b_trie_new(free);
- b_trie_insert(config, "BLOGC_VERSION", b_strdup(PACKAGE_VERSION));
+ sb_slist_t *sources = NULL;
+ sb_trie_t *config = sb_trie_new(free);
+ sb_trie_insert(config, "BLOGC_VERSION", sb_strdup(PACKAGE_VERSION));
for (unsigned int i = 1; i < argc; i++) {
tmp = NULL;
@@ -136,21 +136,21 @@ main(int argc, char **argv)
break;
case 't':
if (argv[i][2] != '\0')
- template = b_strdup(argv[i] + 2);
+ template = sb_strdup(argv[i] + 2);
else if (i + 1 < argc)
- template = b_strdup(argv[++i]);
+ template = sb_strdup(argv[++i]);
break;
case 'o':
if (argv[i][2] != '\0')
- output = b_strdup(argv[i] + 2);
+ output = sb_strdup(argv[i] + 2);
else if (i + 1 < argc)
- output = b_strdup(argv[++i]);
+ output = sb_strdup(argv[++i]);
break;
case 'p':
if (argv[i][2] != '\0')
- print = b_strdup(argv[i] + 2);
+ print = sb_strdup(argv[i] + 2);
else if (i + 1 < argc)
- print = b_strdup(argv[++i]);
+ print = sb_strdup(argv[++i]);
break;
case 'D':
if (argv[i][2] != '\0')
@@ -158,11 +158,11 @@ main(int argc, char **argv)
else if (i + 1 < argc)
tmp = argv[++i];
if (tmp != NULL) {
- pieces = b_str_split(tmp, '=', 2);
- if (b_strv_length(pieces) != 2) {
+ pieces = sb_str_split(tmp, '=', 2);
+ if (sb_strv_length(pieces) != 2) {
fprintf(stderr, "blogc: error: invalid value for "
"-D (must have an '='): %s\n", tmp);
- b_strv_free(pieces);
+ sb_strv_free(pieces);
rv = 2;
goto cleanup;
}
@@ -173,13 +173,13 @@ main(int argc, char **argv)
fprintf(stderr, "blogc: error: invalid value "
"for -D (configuration key must be uppercase "
"with '_'): %s\n", pieces[0]);
- b_strv_free(pieces);
+ sb_strv_free(pieces);
rv = 2;
goto cleanup;
}
}
- b_trie_insert(config, pieces[0], b_strdup(pieces[1]));
- b_strv_free(pieces);
+ sb_trie_insert(config, pieces[0], sb_strdup(pieces[1]));
+ sb_strv_free(pieces);
pieces = NULL;
}
break;
@@ -192,17 +192,17 @@ main(int argc, char **argv)
}
}
else
- sources = b_slist_append(sources, b_strdup(argv[i]));
+ sources = sb_slist_append(sources, sb_strdup(argv[i]));
}
- if (!listing && b_slist_length(sources) == 0) {
+ if (!listing && sb_slist_length(sources) == 0) {
blogc_print_usage();
fprintf(stderr, "blogc: error: one source file is required\n");
rv = 2;
goto cleanup;
}
- if (!listing && b_slist_length(sources) > 1) {
+ if (!listing && sb_slist_length(sources) > 1) {
blogc_print_usage();
fprintf(stderr, "blogc: error: only one source file should be provided, "
"if running without '-l'\n");
@@ -212,14 +212,14 @@ main(int argc, char **argv)
blogc_error_t *err = NULL;
- b_slist_t *s = blogc_source_parse_from_files(config, sources, &err);
+ sb_slist_t *s = blogc_source_parse_from_files(config, sources, &err);
if (err != NULL) {
blogc_error_print(err);
rv = 2;
goto cleanup2;
}
- b_slist_t* l = blogc_template_parse_from_file(template, &err);
+ sb_slist_t* l = blogc_template_parse_from_file(template, &err);
if (err != NULL) {
blogc_error_print(err);
rv = 2;
@@ -227,7 +227,7 @@ main(int argc, char **argv)
}
if (print != NULL) {
- const char *val = b_trie_lookup(config, print);
+ const char *val = sb_trie_lookup(config, print);
if (val == NULL) {
fprintf(stderr, "blogc: error: configuration variable not found: %s\n",
print);
@@ -273,13 +273,13 @@ cleanup4:
cleanup3:
blogc_template_free_stmts(l);
cleanup2:
- b_slist_free_full(s, (b_free_func_t) b_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
blogc_error_free(err);
cleanup:
- b_trie_free(config);
+ sb_trie_free(config);
free(template);
free(output);
free(print);
- b_slist_free_full(sources, free);
+ sb_slist_free_full(sources, free);
return rv;
}
diff --git a/src/renderer.c b/src/renderer.c
index 3061c43..52af8d9 100644
--- a/src/renderer.c
+++ b/src/renderer.c
@@ -13,7 +13,7 @@
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
-#include "utils/utils.h"
+#include <squareball.h>
#include "datetime-parser.h"
#include "error.h"
#include "loader.h"
@@ -23,51 +23,51 @@
const char*
-blogc_get_variable(const char *name, b_trie_t *global, b_trie_t *local)
+blogc_get_variable(const char *name, sb_trie_t *global, sb_trie_t *local)
{
const char *rv = NULL;
if (local != NULL) {
- rv = b_trie_lookup(local, name);
+ rv = sb_trie_lookup(local, name);
if (rv != NULL)
return rv;
}
if (global != NULL)
- rv = b_trie_lookup(global, name);
+ rv = sb_trie_lookup(global, name);
return rv;
}
char*
-blogc_format_date(const char *date, b_trie_t *global, b_trie_t *local)
+blogc_format_date(const char *date, sb_trie_t *global, sb_trie_t *local)
{
const char *date_format = blogc_get_variable("DATE_FORMAT", global, local);
if (date == NULL)
return NULL;
if (date_format == NULL)
- return b_strdup(date);
+ return sb_strdup(date);
blogc_error_t *err = NULL;
char *rv = blogc_convert_datetime(date, date_format, &err);
if (err != NULL) {
blogc_error_print(err);
blogc_error_free(err);
- return b_strdup(date);
+ return sb_strdup(date);
}
return rv;
}
char*
-blogc_format_variable(const char *name, b_trie_t *global, b_trie_t *local)
+blogc_format_variable(const char *name, sb_trie_t *global, sb_trie_t *local)
{
char *var = NULL;
bool must_format = false;
- if (b_str_ends_with(name, "_FORMATTED")) {
- var = b_strndup(name, strlen(name) - 10);
+ if (sb_str_ends_with(name, "_FORMATTED")) {
+ var = sb_strndup(name, strlen(name) - 10);
must_format = true;
}
if (var == NULL)
- var = b_strdup(name);
+ var = sb_strdup(name);
const char *value = blogc_get_variable(var, global, local);
free(var);
@@ -77,29 +77,29 @@ blogc_format_variable(const char *name, b_trie_t *global, b_trie_t *local)
char *rv = NULL;
if (must_format) {
- if (b_str_starts_with(name, "DATE_")) {
+ if (sb_str_starts_with(name, "DATE_")) {
rv = blogc_format_date(value, global, local);
}
}
if (rv == NULL)
- return b_strdup(value);
+ return sb_strdup(value);
return rv;
}
char*
-blogc_render(b_slist_t *tmpl, b_slist_t *sources, b_trie_t *config, bool listing)
+blogc_render(sb_slist_t *tmpl, sb_slist_t *sources, sb_trie_t *config, bool listing)
{
if (tmpl == NULL)
return NULL;
- b_slist_t *current_source = NULL;
- b_slist_t *listing_start = NULL;
+ sb_slist_t *current_source = NULL;
+ sb_slist_t *listing_start = NULL;
- b_string_t *str = b_string_new();
+ sb_string_t *str = sb_string_new();
- b_trie_t *tmp_source = NULL;
+ sb_trie_t *tmp_source = NULL;
char *config_value = NULL;
char *defined = NULL;
@@ -112,7 +112,7 @@ blogc_render(b_slist_t *tmpl, b_slist_t *sources, b_trie_t *config, bool listing
int cmp = 0;
- b_slist_t *tmp = tmpl;
+ sb_slist_t *tmp = tmpl;
while (tmp != NULL) {
blogc_template_stmt_t *stmt = tmp->data;
@@ -120,7 +120,7 @@ blogc_render(b_slist_t *tmpl, b_slist_t *sources, b_trie_t *config, bool listing
case BLOGC_TEMPLATE_CONTENT_STMT:
if (stmt->value != NULL)
- b_string_append(str, stmt->value);
+ sb_string_append(str, stmt->value);
break;
case BLOGC_TEMPLATE_BLOCK_STMT:
@@ -177,7 +177,7 @@ blogc_render(b_slist_t *tmpl, b_slist_t *sources, b_trie_t *config, bool listing
config_value = blogc_format_variable(stmt->value,
config, inside_block ? tmp_source : NULL);
if (config_value != NULL) {
- b_string_append(str, config_value);
+ sb_string_append(str, config_value);
free(config_value);
config_value = NULL;
break;
@@ -218,7 +218,7 @@ blogc_render(b_slist_t *tmpl, b_slist_t *sources, b_trie_t *config, bool listing
(stmt->value2[0] == '"') &&
(stmt->value2[strlen(stmt->value2) - 1] == '"'))
{
- defined2 = b_strndup(stmt->value2 + 1,
+ defined2 = sb_strndup(stmt->value2 + 1,
strlen(stmt->value2) - 2);
}
else {
@@ -285,5 +285,5 @@ blogc_render(b_slist_t *tmpl, b_slist_t *sources, b_trie_t *config, bool listing
tmp = tmp->next;
}
- return b_string_free(str, false);
+ return sb_string_free(str, false);
}
diff --git a/src/renderer.h b/src/renderer.h
index e5cff6e..4361c12 100644
--- a/src/renderer.h
+++ b/src/renderer.h
@@ -10,12 +10,12 @@
#define _RENDERER_H
#include <stdbool.h>
-#include "utils/utils.h"
+#include <squareball.h>
-const char* blogc_get_variable(const char *name, b_trie_t *global, b_trie_t *local);
-char* blogc_format_date(const char *date, b_trie_t *global, b_trie_t *local);
-char* blogc_format_variable(const char *name, b_trie_t *global, b_trie_t *local);
-char* blogc_render(b_slist_t *tmpl, b_slist_t *sources, b_trie_t *config,
+const char* blogc_get_variable(const char *name, sb_trie_t *global, sb_trie_t *local);
+char* blogc_format_date(const char *date, sb_trie_t *global, sb_trie_t *local);
+char* blogc_format_variable(const char *name, sb_trie_t *global, sb_trie_t *local);
+char* blogc_render(sb_slist_t *tmpl, sb_slist_t *sources, sb_trie_t *config,
bool listing);
#endif /* _RENDERER_H */
diff --git a/src/source-parser.c b/src/source-parser.c
index db0792c..8801210 100644
--- a/src/source-parser.c
+++ b/src/source-parser.c
@@ -13,7 +13,7 @@
#include <stdbool.h>
#include <string.h>
-#include "utils/utils.h"
+#include <squareball.h>
#include "content-parser.h"
#include "source-parser.h"
#include "error.h"
@@ -30,7 +30,7 @@ typedef enum {
} blogc_source_parser_state_t;
-b_trie_t*
+sb_trie_t*
blogc_source_parse(const char *src, size_t src_len, blogc_error_t **err)
{
if (err == NULL || *err != NULL)
@@ -43,7 +43,7 @@ blogc_source_parse(const char *src, size_t src_len, blogc_error_t **err)
char *key = NULL;
char *tmp = NULL;
char *content = NULL;
- b_trie_t *rv = b_trie_new(free);
+ sb_trie_t *rv = sb_trie_new(free);
blogc_source_parser_state_t state = SOURCE_START;
@@ -73,7 +73,7 @@ blogc_source_parse(const char *src, size_t src_len, blogc_error_t **err)
if ((c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_')
break;
if (c == ':') {
- key = b_strndup(src + start, current - start);
+ key = sb_strndup(src + start, current - start);
if (((current - start == 8) &&
(0 == strncmp("FILENAME", src + start, 8))) ||
((current - start == 7) &&
@@ -122,8 +122,8 @@ blogc_source_parse(const char *src, size_t src_len, blogc_error_t **err)
case SOURCE_CONFIG_VALUE:
if (c == '\n' || c == '\r') {
- tmp = b_strndup(src + start, current - start);
- b_trie_insert(rv, key, b_strdup(b_str_strip(tmp)));
+ tmp = sb_strndup(src + start, current - start);
+ sb_trie_insert(rv, key, sb_strdup(sb_str_strip(tmp)));
free(tmp);
free(key);
key = NULL;
@@ -152,12 +152,12 @@ blogc_source_parse(const char *src, size_t src_len, blogc_error_t **err)
case SOURCE_CONTENT:
if (current == (src_len - 1)) {
- tmp = b_strndup(src + start, src_len - start);
- b_trie_insert(rv, "RAW_CONTENT", tmp);
+ tmp = sb_strndup(src + start, src_len - start);
+ sb_trie_insert(rv, "RAW_CONTENT", tmp);
content = blogc_content_parse(tmp, &end_excerpt);
- b_trie_insert(rv, "CONTENT", content);
- b_trie_insert(rv, "EXCERPT", end_excerpt == 0 ?
- b_strdup(content) : b_strndup(content, end_excerpt));
+ sb_trie_insert(rv, "CONTENT", content);
+ sb_trie_insert(rv, "EXCERPT", end_excerpt == 0 ?
+ sb_strdup(content) : sb_strndup(content, end_excerpt));
}
break;
}
@@ -168,7 +168,7 @@ blogc_source_parse(const char *src, size_t src_len, blogc_error_t **err)
current++;
}
- if (*err == NULL && b_trie_size(rv) == 0) {
+ if (*err == NULL && sb_trie_size(rv) == 0) {
// ok, nothing found in the config trie, but no error set either.
// let's try to be nice with the users and provide some reasonable
@@ -202,7 +202,7 @@ blogc_source_parse(const char *src, size_t src_len, blogc_error_t **err)
if (*err != NULL) {
free(key);
- b_trie_free(rv);
+ sb_trie_free(rv);
return NULL;
}
diff --git a/src/source-parser.h b/src/source-parser.h
index d92b1ce..94bf0d4 100644
--- a/src/source-parser.h
+++ b/src/source-parser.h
@@ -10,10 +10,10 @@
#define _SOURCE_PARSER_H
#include <stdlib.h>
-#include "utils/utils.h"
+#include <squareball.h>
#include "error.h"
-b_trie_t* blogc_source_parse(const char *src, size_t src_len,
+sb_trie_t* blogc_source_parse(const char *src, size_t src_len,
blogc_error_t **err);
#endif /* _SOURCE_PARSER_H */
diff --git a/src/template-parser.c b/src/template-parser.c
index f6912df..a00a2c2 100644
--- a/src/template-parser.c
+++ b/src/template-parser.c
@@ -13,7 +13,7 @@
#include <stdbool.h>
#include <string.h>
-#include "utils/utils.h"
+#include <squareball.h>
#include "template-parser.h"
#include "error.h"
@@ -48,7 +48,7 @@ typedef enum {
} blogc_template_parser_block_state_t;
-b_slist_t*
+sb_slist_t*
blogc_template_parse(const char *src, size_t src_len, blogc_error_t **err)
{
if (err == NULL || *err != NULL)
@@ -66,7 +66,7 @@ blogc_template_parse(const char *src, size_t src_len, blogc_error_t **err)
unsigned int if_count = 0;
- b_slist_t *stmts = NULL;
+ sb_slist_t *stmts = NULL;
blogc_template_stmt_t *stmt = NULL;
blogc_template_parser_state_t state = TEMPLATE_START;
@@ -81,12 +81,12 @@ blogc_template_parse(const char *src, size_t src_len, blogc_error_t **err)
case TEMPLATE_START:
if (last) {
- stmt = b_malloc(sizeof(blogc_template_stmt_t));
+ stmt = sb_malloc(sizeof(blogc_template_stmt_t));
stmt->type = type;
- stmt->value = b_strndup(src + start, src_len - start);
+ stmt->value = sb_strndup(src + start, src_len - start);
stmt->op = 0;
stmt->value2 = NULL;
- stmts = b_slist_append(stmts, stmt);
+ stmts = sb_slist_append(stmts, stmt);
stmt = NULL;
}
if (c == '{') {
@@ -102,12 +102,12 @@ blogc_template_parse(const char *src, size_t src_len, blogc_error_t **err)
else
state = TEMPLATE_VARIABLE_START;
if (end > start) {
- stmt = b_malloc(sizeof(blogc_template_stmt_t));
+ stmt = sb_malloc(sizeof(blogc_template_stmt_t));
stmt->type = type;
- stmt->value = b_strndup(src + start, end - start);
+ stmt->value = sb_strndup(src + start, end - start);
stmt->op = 0;
stmt->value2 = NULL;
- stmts = b_slist_append(stmts, stmt);
+ stmts = sb_slist_append(stmts, stmt);
stmt = NULL;
}
break;
@@ -426,19 +426,19 @@ blogc_template_parse(const char *src, size_t src_len, blogc_error_t **err)
op_start = 0;
op_end = 0;
}
- stmt = b_malloc(sizeof(blogc_template_stmt_t));
+ stmt = sb_malloc(sizeof(blogc_template_stmt_t));
stmt->type = type;
stmt->value = NULL;
stmt->op = tmp_op;
stmt->value2 = NULL;
if (end > start)
- stmt->value = b_strndup(src + start, end - start);
+ stmt->value = sb_strndup(src + start, end - start);
if (end2 > start2) {
- stmt->value2 = b_strndup(src + start2, end2 - start2);
+ stmt->value2 = sb_strndup(src + start2, end2 - start2);
start2 = 0;
end2 = 0;
}
- stmts = b_slist_append(stmts, stmt);
+ stmts = sb_slist_append(stmts, stmt);
stmt = NULL;
state = TEMPLATE_START;
type = BLOGC_TEMPLATE_CONTENT_STMT;
@@ -485,9 +485,9 @@ blogc_template_parse(const char *src, size_t src_len, blogc_error_t **err)
void
-blogc_template_free_stmts(b_slist_t *stmts)
+blogc_template_free_stmts(sb_slist_t *stmts)
{
- for (b_slist_t *tmp = stmts; tmp != NULL; tmp = tmp->next) {
+ for (sb_slist_t *tmp = stmts; tmp != NULL; tmp = tmp->next) {
blogc_template_stmt_t *data = tmp->data;
if (data == NULL)
continue;
@@ -495,5 +495,5 @@ blogc_template_free_stmts(b_slist_t *stmts)
free(data->value2);
free(data);
}
- b_slist_free(stmts);
+ sb_slist_free(stmts);
}
diff --git a/src/template-parser.h b/src/template-parser.h
index d1e9bd6..c576bc0 100644
--- a/src/template-parser.h
+++ b/src/template-parser.h
@@ -9,7 +9,7 @@
#ifndef _TEMPLATE_PARSER_H
#define _TEMPLATE_PARSER_H
-#include "utils/utils.h"
+#include <squareball.h>
#include "error.h"
typedef enum {
@@ -37,8 +37,8 @@ typedef struct {
blogc_template_stmt_operator_t op;
} blogc_template_stmt_t;
-b_slist_t* blogc_template_parse(const char *src, size_t src_len,
+sb_slist_t* blogc_template_parse(const char *src, size_t src_len,
blogc_error_t **err);
-void blogc_template_free_stmts(b_slist_t *stmts);
+void blogc_template_free_stmts(sb_slist_t *stmts);
#endif /* _TEMPLATE_GRAMMAR_H */
diff --git a/src/utils/mem.c b/src/utils/mem.c
deleted file mode 100644
index 7c5e0a2..0000000
--- a/src/utils/mem.c
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * blogc: A blog compiler.
- * Copyright (C) 2014-2015 Rafael G. Martins <rafael@rafaelmartins.eng.br>
- *
- * This program can be distributed under the terms of the BSD License.
- * See the file LICENSE.
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif /* HAVE_CONFIG_H */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include "utils.h"
-
-
-void*
-b_malloc(size_t size)
-{
- // simple things simple!
- void *rv = malloc(size);
- if (rv == NULL) {
- fprintf(stderr, "fatal error: Failed to allocate memory!\n");
- exit(1);
- }
- return rv;
-}
-
-
-void*
-b_realloc(void *ptr, size_t size)
-{
- // simple things even simpler :P
- void *rv = realloc(ptr, size);
- if (rv == NULL && size != 0) {
- fprintf(stderr, "fatal error: Failed to reallocate memory!\n");
- free(ptr);
- exit(1);
- }
- return rv;
-}
diff --git a/src/utils/slist.c b/src/utils/slist.c
deleted file mode 100644
index 3d9b892..0000000
--- a/src/utils/slist.c
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * blogc: A blog compiler.
- * Copyright (C) 2014-2015 Rafael G. Martins <rafael@rafaelmartins.eng.br>
- *
- * This program can be distributed under the terms of the BSD License.
- * See the file LICENSE.
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif /* HAVE_CONFIG_H */
-
-#include <stdlib.h>
-#include "utils.h"
-
-
-b_slist_t*
-b_slist_append(b_slist_t *l, void *data)
-{
- b_slist_t *node = malloc(sizeof(b_slist_t));
- if (node == NULL) {
- l = NULL;
- return l;
- }
- node->data = data;
- node->next = NULL;
- if (l == NULL)
- l = node;
- else {
- b_slist_t *tmp;
- for (tmp = l; tmp->next != NULL; tmp = tmp->next);
- tmp->next = node;
- }
- return l;
-}
-
-
-void
-b_slist_free_full(b_slist_t *l, b_free_func_t free_func)
-{
- while (l != NULL) {
- b_slist_t *tmp = l->next;
- free_func(l->data);
- free(l);
- l = tmp;
- }
-}
-
-
-void
-b_slist_free(b_slist_t *l)
-{
- while (l != NULL) {
- b_slist_t *tmp = l->next;
- free(l);
- l = tmp;
- }
-}
-
-
-unsigned int
-b_slist_length(b_slist_t *l)
-{
- unsigned int i;
- b_slist_t *tmp;
- for (tmp = l, i = 0; tmp != NULL; tmp = tmp->next, i++);
- return i;
-}
diff --git a/src/utils/strings.c b/src/utils/strings.c
deleted file mode 100644
index 40174a1..0000000
--- a/src/utils/strings.c
+++ /dev/null
@@ -1,283 +0,0 @@
-/*
- * blogc: A blog compiler.
- * Copyright (C) 2014-2015 Rafael G. Martins <rafael@rafaelmartins.eng.br>
- *
- * This program can be distributed under the terms of the BSD License.
- * See the file LICENSE.
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif /* HAVE_CONFIG_H */
-
-#include <ctype.h>
-#include <string.h>
-#include <stdarg.h>
-#include <stdbool.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include "utils.h"
-
-
-char*
-b_strdup(const char *s)
-{
- if (s == NULL)
- return NULL;
- size_t l = strlen(s);
- char *tmp = malloc(l + 1);
- if (tmp == NULL)
- return NULL;
- memcpy(tmp, s, l + 1);
- return tmp;
-}
-
-
-char*
-b_strndup(const char *s, size_t n)
-{
- if (s == NULL)
- return NULL;
- size_t l = strnlen(s, n);
- char *tmp = malloc(l + 1);
- if (tmp == NULL)
- return NULL;
- memcpy(tmp, s, l);
- tmp[l] = '\0';
- return tmp;
-}
-
-
-char*
-b_strdup_vprintf(const char *format, va_list ap)
-{
- va_list ap2;
- va_copy(ap2, ap);
- int l = vsnprintf(NULL, 0, format, ap2);
- va_end(ap2);
- if (l < 0)
- return NULL;
- char *tmp = malloc(l + 1);
- if (!tmp)
- return NULL;
- int l2 = vsnprintf(tmp, l + 1, format, ap);
- if (l2 < 0) {
- free(tmp);
- return NULL;
- }
- return tmp;
-}
-
-
-char*
-b_strdup_printf(const char *format, ...)
-{
- va_list ap;
- va_start(ap, format);
- char *tmp = b_strdup_vprintf(format, ap);
- va_end(ap);
- return tmp;
-}
-
-
-bool
-b_str_starts_with(const char *str, const char *prefix)
-{
- int str_l = strlen(str);
- int str_lp = strlen(prefix);
- if (str_lp > str_l)
- return false;
- return strncmp(str, prefix, str_lp) == 0;
-}
-
-
-bool
-b_str_ends_with(const char *str, const char *suffix)
-{
- int str_l = strlen(str);
- int str_ls = strlen(suffix);
- if (str_ls > str_l)
- return false;
- return strcmp(str + str_l - str_ls, suffix) == 0;
-}
-
-
-char*
-b_str_strip(char *str)
-{
- if (str == NULL)
- return str;
- int i;
- size_t str_len = strlen(str);
- for (i = str_len - 1; i >= 0; i--) {
- if (!isspace(str[i])) {
- str[i + 1] = '\0';
- break;
- }
- }
- str_len = strlen(str);
- for (i = 0; i < str_len; i++) {
- if (!isspace(str[i])) {
- str = str + i;
- break;
- }
- }
- return str;
-}
-
-
-char**
-b_str_split(const char *str, char c, unsigned int max_pieces)
-{
- if (!str)
- return NULL;
- char **rv = b_malloc(sizeof(char*));
- unsigned int i, start = 0, count = 0;
- for (i = 0; i < strlen(str) + 1; i++) {
- if (str[0] == '\0')
- break;
- if ((str[i] == c && (!max_pieces || count + 1 < max_pieces)) || str[i] == '\0') {
- rv = b_realloc(rv, (count + 1) * sizeof(char*));
- rv[count] = b_malloc(i - start + 1);
- memcpy(rv[count], str + start, i - start);
- rv[count++][i - start] = '\0';
- start = i + 1;
- }
- }
- rv = b_realloc(rv, (count + 1) * sizeof(char*));
- rv[count] = NULL;
- return rv;
-}
-
-
-char*
-b_str_replace(const char *str, const char search, const char *replace)
-{
- char **pieces = b_str_split(str, search, 0);
- if (pieces == NULL)
- return NULL;
- char* rv = b_strv_join((const char**) pieces, replace);
- b_strv_free(pieces);
- return rv;
-}
-
-
-void
-b_strv_free(char **strv)
-{
- if (strv == NULL)
- return;
- unsigned int i;
- for (i = 0; strv[i] != NULL; i++)
- free(strv[i]);
- free(strv);
-}
-
-
-char*
-b_strv_join(const char **strv, const char *separator)
-{
- if (strv == NULL)
- return NULL;
- unsigned int i = 0;
- b_string_t *str = b_string_new();
- for (i = 0; strv[i] != NULL; i++) {
- str = b_string_append(str, strv[i]);
- if (strv[i+1] != NULL)
- str = b_string_append(str, separator);
- }
- return b_string_free(str, false);
-}
-
-
-unsigned int
-b_strv_length(char **strv)
-{
- if (!strv)
- return 0;
- unsigned int i;
- for (i = 0; strv[i] != NULL; i++);
- return i;
-}
-
-
-b_string_t*
-b_string_new(void)
-{
- b_string_t* rv = b_malloc(sizeof(b_string_t));
- rv->str = NULL;
- rv->len = 0;
- rv->allocated_len = 0;
-
- // initialize with empty string
- rv = b_string_append(rv, "");
-
- return rv;
-}
-
-
-char*
-b_string_free(b_string_t *str, bool free_str)
-{
- char *rv = NULL;
- if (free_str)
- free(str->str);
- else
- rv = str->str;
- free(str);
- return rv;
-}
-
-
-b_string_t*
-b_string_append_len(b_string_t *str, const char *suffix, size_t len)
-{
- if (suffix == NULL)
- return str;
- size_t old_len = str->len;
- str->len += len;
- if (str->len + 1 > str->allocated_len) {
- str->allocated_len = (((str->len + 1) / B_STRING_CHUNK_SIZE) + 1) * B_STRING_CHUNK_SIZE;
- str->str = b_realloc(str->str, str->allocated_len);
- }
- memcpy(str->str + old_len, suffix, len);
- str->str[str->len] = '\0';
- return str;
-}
-
-
-b_string_t*
-b_string_append(b_string_t *str, const char *suffix)
-{
- if (suffix == NULL)
- return str;
- return b_string_append_len(str, suffix, strlen(suffix));
-}
-
-
-b_string_t*
-b_string_append_c(b_string_t *str, char c)
-{
- size_t old_len = str->len;
- str->len += 1;
- if (str->len + 1 > str->allocated_len) {
- str->allocated_len = (((str->len + 1) / B_STRING_CHUNK_SIZE) + 1) * B_STRING_CHUNK_SIZE;
- str->str = b_realloc(str->str, str->allocated_len);
- }
- str->str[old_len] = c;
- str->str[str->len] = '\0';
- return str;
-}
-
-
-b_string_t*
-b_string_append_printf(b_string_t *str, const char *format, ...)
-{
- va_list ap;
- va_start(ap, format);
- char *tmp = b_strdup_vprintf(format, ap);
- va_end(ap);
- str = b_string_append(str, tmp);
- free(tmp);
- return str;
-}
diff --git a/src/utils/trie.c b/src/utils/trie.c
deleted file mode 100644
index 72a62f6..0000000
--- a/src/utils/trie.c
+++ /dev/null
@@ -1,199 +0,0 @@
-/*
- * blogc: A blog compiler.
- * Copyright (C) 2014-2015 Rafael G. Martins <rafael@rafaelmartins.eng.br>
- *
- * This program can be distributed under the terms of the BSD License.
- * See the file LICENSE.
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif /* HAVE_CONFIG_H */
-
-#include <stdlib.h>
-#include "utils.h"
-
-
-b_trie_t*
-b_trie_new(b_free_func_t free_func)
-{
- b_trie_t *trie = b_malloc(sizeof(b_trie_t));
- trie->root = NULL;
- trie->free_func = free_func;
- return trie;
-}
-
-
-static void
-b_trie_free_node(b_trie_t *trie, b_trie_node_t *node)
-{
- if (node == NULL)
- return;
- if (node->data != NULL && trie->free_func != NULL)
- trie->free_func(node->data);
- b_trie_free_node(trie, node->next);
- b_trie_free_node(trie, node->child);
- free(node);
-}
-
-
-void
-b_trie_free(b_trie_t *trie)
-{
- if (trie == NULL)
- return;
- b_trie_free_node(trie, trie->root);
- free(trie);
-}
-
-
-void
-b_trie_insert(b_trie_t *trie, const char *key, void *data)
-{
- if (data == NULL || key == NULL)
- return;
-
- b_trie_node_t *parent = NULL;
- b_trie_node_t *previous;
- b_trie_node_t *current;
- b_trie_node_t *tmp;
-
- while (1) {
-
- if (trie->root == NULL || (parent != NULL && parent->child == NULL)) {
- current = b_malloc(sizeof(b_trie_node_t));
- current->key = *key;
- current->data = NULL;
- current->next = NULL;
- current->child = NULL;
- if (trie->root == NULL)
- trie->root = current;
- else
- parent->child = current;
- parent = current;
- goto clean;
- }
-
- tmp = parent == NULL ? trie->root : parent->child;
- previous = NULL;
-
- while (tmp != NULL && tmp->key != *key) {
- previous = tmp;
- tmp = tmp->next;
- }
-
- parent = tmp;
-
- if (previous == NULL || parent != NULL)
- goto clean;
-
- current = b_malloc(sizeof(b_trie_node_t));
- current->key = *key;
- current->data = NULL;
- current->next = NULL;
- current->child = NULL;
- previous->next = current;
- parent = current;
-
-clean:
- if (*key == '\0') {
- if (parent->data != NULL && trie->free_func != NULL)
- trie->free_func(parent->data);
- parent->data = data;
- break;
- }
- key++;
- }
-}
-
-
-void*
-b_trie_lookup(b_trie_t *trie, const char *key)
-{
- if (trie->root == NULL || key == NULL)
- return NULL;
-
- b_trie_node_t *parent = trie->root;
- b_trie_node_t *tmp;
- while (1) {
- for (tmp = parent; tmp != NULL; tmp = tmp->next) {
-
- if (tmp->key == *key) {
- if (tmp->key == '\0')
- return tmp->data;
- parent = tmp->child;
- break;
- }
- }
- if (tmp == NULL)
- return NULL;
-
- if (*key == '\0')
- break;
- key++;
- }
- return NULL;
-}
-
-
-static void
-b_trie_size_node(b_trie_node_t *node, unsigned int *count)
-{
- if (node == NULL)
- return;
-
- if (node->key == '\0')
- (*count)++;
-
- b_trie_size_node(node->next, count);
- b_trie_size_node(node->child, count);
-}
-
-
-unsigned int
-b_trie_size(b_trie_t *trie)
-{
- if (trie == NULL)
- return 0;
-
- unsigned int count = 0;
- b_trie_size_node(trie->root, &count);
- return count;
-}
-
-
-static void
-b_trie_foreach_node(b_trie_node_t *node, b_string_t *str, void (*func)(const char *key, void *data))
-{
- if (node == NULL)
- return;
-
- if (node->key == '\0') {
- func(str->str, node->data);
- b_string_free(str, true);
- }
-
- if (node->child != NULL) {
- b_string_t *child = b_string_new();
- child = b_string_append(child, str->str);
- child = b_string_append_c(child, node->key);
- b_trie_foreach_node(node->child, child, func);
- }
-
- if (node->next != NULL)
- b_trie_foreach_node(node->next, str, func);
-
- if (node->child != NULL && node->next == NULL)
- b_string_free(str, true);
-}
-
-
-void
-b_trie_foreach(b_trie_t *trie, void (*func)(const char *key, void *data))
-{
- if (trie->root == NULL)
- return;
-
- b_string_t *str = b_string_new();
- b_trie_foreach_node(trie->root, str, func);
-}
diff --git a/src/utils/utils.h b/src/utils/utils.h
deleted file mode 100644
index 5a1505b..0000000
--- a/src/utils/utils.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * blogc: A blog compiler.
- * Copyright (C) 2014-2015 Rafael G. Martins <rafael@rafaelmartins.eng.br>
- *
- * This program can be distributed under the terms of the BSD License.
- * See the file LICENSE.
- */
-
-#ifndef _UTILS_UTILS_H
-#define _UTILS_UTILS_H
-
-#include <stdbool.h>
-#include <stdlib.h>
-#include <stdarg.h>
-
-#define B_STRING_CHUNK_SIZE 128
-
-typedef void (*b_free_func_t) (void *ptr);
-
-typedef struct _b_slist_t {
- struct _b_slist_t *next;
- void *data;
-} b_slist_t;
-
-typedef struct _b_string_t {
- char *str;
- size_t len;
- size_t allocated_len;
-} b_string_t;
-
-typedef struct _b_trie_node_t {
- char key;
- void *data;
- struct _b_trie_node_t *next, *child;
-} b_trie_node_t;
-
-typedef struct _b_trie_t {
- b_trie_node_t *root;
- b_free_func_t free_func;
-} b_trie_t;
-
-b_slist_t* b_slist_append(b_slist_t *l, void *data);
-void b_slist_free_full(b_slist_t *l, b_free_func_t free_func);
-void b_slist_free(b_slist_t *l);
-unsigned int b_slist_length(b_slist_t *l);
-
-char* b_strdup(const char *s);
-char* b_strndup(const char *s, size_t n);
-char* b_strdup_vprintf(const char *format, va_list ap);
-char* b_strdup_printf(const char *format, ...);
-bool b_str_starts_with(const char *str, const char *prefix);
-bool b_str_ends_with(const char *str, const char *suffix);
-char* b_str_strip(char *str);
-char** b_str_split(const char *str, char c, unsigned int max_pieces);
-char* b_str_replace(const char *str, const char search, const char *replace);
-void b_strv_free(char **strv);
-char* b_strv_join(const char **strv, const char *separator);
-unsigned int b_strv_length(char **strv);
-
-b_string_t* b_string_new(void);
-char* b_string_free(b_string_t *str, bool free_str);
-b_string_t* b_string_append_len(b_string_t *str, const char *suffix, size_t len);
-b_string_t* b_string_append(b_string_t *str, const char *suffix);
-b_string_t* b_string_append_c(b_string_t *str, char c);
-b_string_t* b_string_append_printf(b_string_t *str, const char *format, ...);
-
-b_trie_t* b_trie_new(b_free_func_t free_func);
-void b_trie_free(b_trie_t *trie);
-void b_trie_insert(b_trie_t *trie, const char *key, void *data);
-void* b_trie_lookup(b_trie_t *trie, const char *key);
-unsigned int b_trie_size(b_trie_t *trie);
-void b_trie_foreach(b_trie_t *trie, void (*func)(const char *key, void *data));
-
-void* b_malloc(size_t size);
-void* b_realloc(void *ptr, size_t size);
-
-#endif /* _UTILS_UTILS_H */
diff --git a/tests/check_content_parser.c b/tests/check_content_parser.c
index dc3485e..545a1c4 100644
--- a/tests/check_content_parser.c
+++ b/tests/check_content_parser.c
@@ -16,7 +16,7 @@
#include <cmocka.h>
#include <string.h>
#include "../src/content-parser.h"
-#include "../src/utils/utils.h"
+#include <squareball.h>
static void
diff --git a/tests/check_error.c b/tests/check_error.c
index 17e1c40..ea339d6 100644
--- a/tests/check_error.c
+++ b/tests/check_error.c
@@ -16,7 +16,7 @@
#include <cmocka.h>
#include <string.h>
#include "../src/error.h"
-#include "../src/utils/utils.h"
+#include <squareball.h>
static void
diff --git a/tests/check_loader.c b/tests/check_loader.c
index f5be3e7..243b7d5 100644
--- a/tests/check_loader.c
+++ b/tests/check_loader.c
@@ -18,7 +18,7 @@
#include <stdio.h>
#include "../src/template-parser.h"
#include "../src/loader.h"
-#include "../src/utils/utils.h"
+#include <squareball.h>
static void
@@ -80,11 +80,11 @@ test_template_parse_from_file(void **state)
{
blogc_error_t *err = NULL;
will_return(__wrap_blogc_file_get_contents, "bola");
- will_return(__wrap_blogc_file_get_contents, b_strdup("{{ BOLA }}\n"));
- b_slist_t *l = blogc_template_parse_from_file("bola", &err);
+ will_return(__wrap_blogc_file_get_contents, sb_strdup("{{ BOLA }}\n"));
+ sb_slist_t *l = blogc_template_parse_from_file("bola", &err);
assert_null(err);
assert_non_null(l);
- assert_int_equal(b_slist_length(l), 2);
+ assert_int_equal(sb_slist_length(l), 2);
blogc_template_free_stmts(l);
}
@@ -95,7 +95,7 @@ test_template_parse_from_file_null(void **state)
blogc_error_t *err = NULL;
will_return(__wrap_blogc_file_get_contents, "bola");
will_return(__wrap_blogc_file_get_contents, NULL);
- b_slist_t *l = blogc_template_parse_from_file("bola", &err);
+ sb_slist_t *l = blogc_template_parse_from_file("bola", &err);
assert_null(err);
assert_null(l);
}
@@ -106,20 +106,20 @@ test_source_parse_from_file(void **state)
{
blogc_error_t *err = NULL;
will_return(__wrap_blogc_file_get_contents, "bola.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 123\n"
"--------\n"
"bola"));
- b_trie_t *t = blogc_source_parse_from_file("bola.txt", &err);
+ sb_trie_t *t = blogc_source_parse_from_file("bola.txt", &err);
assert_null(err);
assert_non_null(t);
- assert_int_equal(b_trie_size(t), 5);
- assert_string_equal(b_trie_lookup(t, "ASD"), "123");
- assert_string_equal(b_trie_lookup(t, "FILENAME"), "bola");
- assert_string_equal(b_trie_lookup(t, "EXCERPT"), "<p>bola</p>\n");
- assert_string_equal(b_trie_lookup(t, "CONTENT"), "<p>bola</p>\n");
- assert_string_equal(b_trie_lookup(t, "RAW_CONTENT"), "bola");
- b_trie_free(t);
+ assert_int_equal(sb_trie_size(t), 5);
+ assert_string_equal(sb_trie_lookup(t, "ASD"), "123");
+ assert_string_equal(sb_trie_lookup(t, "FILENAME"), "bola");
+ assert_string_equal(sb_trie_lookup(t, "EXCERPT"), "<p>bola</p>\n");
+ assert_string_equal(sb_trie_lookup(t, "CONTENT"), "<p>bola</p>\n");
+ assert_string_equal(sb_trie_lookup(t, "RAW_CONTENT"), "bola");
+ sb_trie_free(t);
}
@@ -129,7 +129,7 @@ test_source_parse_from_file_null(void **state)
blogc_error_t *err = NULL;
will_return(__wrap_blogc_file_get_contents, "bola.txt");
will_return(__wrap_blogc_file_get_contents, NULL);
- b_trie_t *t = blogc_source_parse_from_file("bola.txt", &err);
+ sb_trie_t *t = blogc_source_parse_from_file("bola.txt", &err);
assert_null(err);
assert_null(t);
}
@@ -139,41 +139,41 @@ static void
test_source_parse_from_files(void **state)
{
will_return(__wrap_blogc_file_get_contents, "bola1.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 123\n"
"DATE: 2001-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola2.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 456\n"
"DATE: 2002-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola3.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 789\n"
"DATE: 2003-02-03 04:05:06\n"
"--------\n"
"bola"));
blogc_error_t *err = NULL;
- b_slist_t *s = NULL;
- s = b_slist_append(s, b_strdup("bola1.txt"));
- s = b_slist_append(s, b_strdup("bola2.txt"));
- s = b_slist_append(s, b_strdup("bola3.txt"));
- b_trie_t *c = b_trie_new(free);
- b_slist_t *t = blogc_source_parse_from_files(c, s, &err);
+ sb_slist_t *s = NULL;
+ s = sb_slist_append(s, sb_strdup("bola1.txt"));
+ s = sb_slist_append(s, sb_strdup("bola2.txt"));
+ s = sb_slist_append(s, sb_strdup("bola3.txt"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_slist_t *t = blogc_source_parse_from_files(c, s, &err);
assert_null(err);
assert_non_null(t);
- assert_int_equal(b_slist_length(t), 3); // it is enough, no need to look at the items
- assert_int_equal(b_trie_size(c), 4);
- assert_string_equal(b_trie_lookup(c, "FILENAME_FIRST"), "bola1");
- assert_string_equal(b_trie_lookup(c, "FILENAME_LAST"), "bola3");
- assert_string_equal(b_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06");
- assert_string_equal(b_trie_lookup(c, "DATE_LAST"), "2003-02-03 04:05:06");
- b_trie_free(c);
- b_slist_free_full(s, free);
- b_slist_free_full(t, (b_free_func_t) b_trie_free);
+ assert_int_equal(sb_slist_length(t), 3); // it is enough, no need to look at the items
+ assert_int_equal(sb_trie_size(c), 4);
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_FIRST"), "bola1");
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_LAST"), "bola3");
+ assert_string_equal(sb_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "DATE_LAST"), "2003-02-03 04:05:06");
+ sb_trie_free(c);
+ sb_slist_free_full(s, free);
+ sb_slist_free_full(t, (sb_free_func_t) sb_trie_free);
}
@@ -181,45 +181,45 @@ static void
test_source_parse_from_files_filter_by_tag(void **state)
{
will_return(__wrap_blogc_file_get_contents, "bola1.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 123\n"
"DATE: 2001-02-03 04:05:06\n"
"TAGS: chunda\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola2.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 456\n"
"DATE: 2002-02-03 04:05:06\n"
"TAGS: bola, chunda\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola3.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 789\n"
"DATE: 2003-02-03 04:05:06\n"
"--------\n"
"bola"));
blogc_error_t *err = NULL;
- b_slist_t *s = NULL;
- s = b_slist_append(s, b_strdup("bola1.txt"));
- s = b_slist_append(s, b_strdup("bola2.txt"));
- s = b_slist_append(s, b_strdup("bola3.txt"));
- b_trie_t *c = b_trie_new(free);
- b_trie_insert(c, "FILTER_TAG", b_strdup("chunda"));
- b_slist_t *t = blogc_source_parse_from_files(c, s, &err);
+ sb_slist_t *s = NULL;
+ s = sb_slist_append(s, sb_strdup("bola1.txt"));
+ s = sb_slist_append(s, sb_strdup("bola2.txt"));
+ s = sb_slist_append(s, sb_strdup("bola3.txt"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_trie_insert(c, "FILTER_TAG", sb_strdup("chunda"));
+ sb_slist_t *t = blogc_source_parse_from_files(c, s, &err);
assert_null(err);
assert_non_null(t);
- assert_int_equal(b_slist_length(t), 2); // it is enough, no need to look at the items
- assert_int_equal(b_trie_size(c), 5);
- assert_string_equal(b_trie_lookup(c, "FILENAME_FIRST"), "bola1");
- assert_string_equal(b_trie_lookup(c, "FILENAME_LAST"), "bola2");
- assert_string_equal(b_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06");
- assert_string_equal(b_trie_lookup(c, "DATE_LAST"), "2002-02-03 04:05:06");
- assert_string_equal(b_trie_lookup(c, "FILTER_TAG"), "chunda");
- b_trie_free(c);
- b_slist_free_full(s, free);
- b_slist_free_full(t, (b_free_func_t) b_trie_free);
+ assert_int_equal(sb_slist_length(t), 2); // it is enough, no need to look at the items
+ assert_int_equal(sb_trie_size(c), 5);
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_FIRST"), "bola1");
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_LAST"), "bola2");
+ assert_string_equal(sb_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "DATE_LAST"), "2002-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_TAG"), "chunda");
+ sb_trie_free(c);
+ sb_slist_free_full(s, free);
+ sb_slist_free_full(t, (sb_free_func_t) sb_trie_free);
}
@@ -227,77 +227,77 @@ static void
test_source_parse_from_files_filter_by_page(void **state)
{
will_return(__wrap_blogc_file_get_contents, "bola1.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 123\n"
"DATE: 2001-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola2.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 456\n"
"DATE: 2002-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola3.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 789\n"
"DATE: 2003-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola4.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 7891\n"
"DATE: 2004-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola5.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 7892\n"
"DATE: 2005-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola6.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 7893\n"
"DATE: 2006-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola7.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 7894\n"
"DATE: 2007-02-03 04:05:06\n"
"--------\n"
"bola"));
blogc_error_t *err = NULL;
- b_slist_t *s = NULL;
- s = b_slist_append(s, b_strdup("bola1.txt"));
- s = b_slist_append(s, b_strdup("bola2.txt"));
- s = b_slist_append(s, b_strdup("bola3.txt"));
- s = b_slist_append(s, b_strdup("bola4.txt"));
- s = b_slist_append(s, b_strdup("bola5.txt"));
- s = b_slist_append(s, b_strdup("bola6.txt"));
- s = b_slist_append(s, b_strdup("bola7.txt"));
- b_trie_t *c = b_trie_new(free);
- b_trie_insert(c, "FILTER_PAGE", b_strdup("1"));
- b_trie_insert(c, "FILTER_PER_PAGE", b_strdup("2"));
- b_slist_t *t = blogc_source_parse_from_files(c, s, &err);
+ sb_slist_t *s = NULL;
+ s = sb_slist_append(s, sb_strdup("bola1.txt"));
+ s = sb_slist_append(s, sb_strdup("bola2.txt"));
+ s = sb_slist_append(s, sb_strdup("bola3.txt"));
+ s = sb_slist_append(s, sb_strdup("bola4.txt"));
+ s = sb_slist_append(s, sb_strdup("bola5.txt"));
+ s = sb_slist_append(s, sb_strdup("bola6.txt"));
+ s = sb_slist_append(s, sb_strdup("bola7.txt"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_trie_insert(c, "FILTER_PAGE", sb_strdup("1"));
+ sb_trie_insert(c, "FILTER_PER_PAGE", sb_strdup("2"));
+ sb_slist_t *t = blogc_source_parse_from_files(c, s, &err);
assert_null(err);
assert_non_null(t);
- assert_int_equal(b_slist_length(t), 2); // it is enough, no need to look at the items
- assert_int_equal(b_trie_size(c), 10);
- assert_string_equal(b_trie_lookup(c, "FILENAME_FIRST"), "bola1");
- assert_string_equal(b_trie_lookup(c, "FILENAME_LAST"), "bola2");
- assert_string_equal(b_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06");
- assert_string_equal(b_trie_lookup(c, "DATE_LAST"), "2002-02-03 04:05:06");
- assert_string_equal(b_trie_lookup(c, "FILTER_PAGE"), "1");
- assert_string_equal(b_trie_lookup(c, "FILTER_PER_PAGE"), "2");
- assert_string_equal(b_trie_lookup(c, "CURRENT_PAGE"), "1");
- assert_string_equal(b_trie_lookup(c, "NEXT_PAGE"), "2");
- assert_string_equal(b_trie_lookup(c, "FIRST_PAGE"), "1");
- assert_string_equal(b_trie_lookup(c, "LAST_PAGE"), "4");
- b_trie_free(c);
- b_slist_free_full(s, free);
- b_slist_free_full(t, (b_free_func_t) b_trie_free);
+ assert_int_equal(sb_slist_length(t), 2); // it is enough, no need to look at the items
+ assert_int_equal(sb_trie_size(c), 10);
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_FIRST"), "bola1");
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_LAST"), "bola2");
+ assert_string_equal(sb_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "DATE_LAST"), "2002-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_PAGE"), "1");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_PER_PAGE"), "2");
+ assert_string_equal(sb_trie_lookup(c, "CURRENT_PAGE"), "1");
+ assert_string_equal(sb_trie_lookup(c, "NEXT_PAGE"), "2");
+ assert_string_equal(sb_trie_lookup(c, "FIRST_PAGE"), "1");
+ assert_string_equal(sb_trie_lookup(c, "LAST_PAGE"), "4");
+ sb_trie_free(c);
+ sb_slist_free_full(s, free);
+ sb_slist_free_full(t, (sb_free_func_t) sb_trie_free);
}
@@ -305,78 +305,78 @@ static void
test_source_parse_from_files_filter_by_page2(void **state)
{
will_return(__wrap_blogc_file_get_contents, "bola1.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 123\n"
"DATE: 2001-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola2.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 456\n"
"DATE: 2002-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola3.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 789\n"
"DATE: 2003-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola4.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 7891\n"
"DATE: 2004-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola5.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 7892\n"
"DATE: 2005-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola6.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 7893\n"
"DATE: 2006-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola7.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 7894\n"
"DATE: 2007-02-03 04:05:06\n"
"--------\n"
"bola"));
blogc_error_t *err = NULL;
- b_slist_t *s = NULL;
- s = b_slist_append(s, b_strdup("bola1.txt"));
- s = b_slist_append(s, b_strdup("bola2.txt"));
- s = b_slist_append(s, b_strdup("bola3.txt"));
- s = b_slist_append(s, b_strdup("bola4.txt"));
- s = b_slist_append(s, b_strdup("bola5.txt"));
- s = b_slist_append(s, b_strdup("bola6.txt"));
- s = b_slist_append(s, b_strdup("bola7.txt"));
- b_trie_t *c = b_trie_new(free);
- b_trie_insert(c, "FILTER_PAGE", b_strdup("3"));
- b_trie_insert(c, "FILTER_PER_PAGE", b_strdup("2"));
- b_slist_t *t = blogc_source_parse_from_files(c, s, &err);
+ sb_slist_t *s = NULL;
+ s = sb_slist_append(s, sb_strdup("bola1.txt"));
+ s = sb_slist_append(s, sb_strdup("bola2.txt"));
+ s = sb_slist_append(s, sb_strdup("bola3.txt"));
+ s = sb_slist_append(s, sb_strdup("bola4.txt"));
+ s = sb_slist_append(s, sb_strdup("bola5.txt"));
+ s = sb_slist_append(s, sb_strdup("bola6.txt"));
+ s = sb_slist_append(s, sb_strdup("bola7.txt"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_trie_insert(c, "FILTER_PAGE", sb_strdup("3"));
+ sb_trie_insert(c, "FILTER_PER_PAGE", sb_strdup("2"));
+ sb_slist_t *t = blogc_source_parse_from_files(c, s, &err);
assert_null(err);
assert_non_null(t);
- assert_int_equal(b_slist_length(t), 2); // it is enough, no need to look at the items
- assert_int_equal(b_trie_size(c), 11);
- assert_string_equal(b_trie_lookup(c, "FILENAME_FIRST"), "bola5");
- assert_string_equal(b_trie_lookup(c, "FILENAME_LAST"), "bola6");
- assert_string_equal(b_trie_lookup(c, "DATE_FIRST"), "2005-02-03 04:05:06");
- assert_string_equal(b_trie_lookup(c, "DATE_LAST"), "2006-02-03 04:05:06");
- assert_string_equal(b_trie_lookup(c, "FILTER_PAGE"), "3");
- assert_string_equal(b_trie_lookup(c, "FILTER_PER_PAGE"), "2");
- assert_string_equal(b_trie_lookup(c, "CURRENT_PAGE"), "3");
- assert_string_equal(b_trie_lookup(c, "PREVIOUS_PAGE"), "2");
- assert_string_equal(b_trie_lookup(c, "NEXT_PAGE"), "4");
- assert_string_equal(b_trie_lookup(c, "FIRST_PAGE"), "1");
- assert_string_equal(b_trie_lookup(c, "LAST_PAGE"), "4");
- b_trie_free(c);
- b_slist_free_full(s, free);
- b_slist_free_full(t, (b_free_func_t) b_trie_free);
+ assert_int_equal(sb_slist_length(t), 2); // it is enough, no need to look at the items
+ assert_int_equal(sb_trie_size(c), 11);
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_FIRST"), "bola5");
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_LAST"), "bola6");
+ assert_string_equal(sb_trie_lookup(c, "DATE_FIRST"), "2005-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "DATE_LAST"), "2006-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_PAGE"), "3");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_PER_PAGE"), "2");
+ assert_string_equal(sb_trie_lookup(c, "CURRENT_PAGE"), "3");
+ assert_string_equal(sb_trie_lookup(c, "PREVIOUS_PAGE"), "2");
+ assert_string_equal(sb_trie_lookup(c, "NEXT_PAGE"), "4");
+ assert_string_equal(sb_trie_lookup(c, "FIRST_PAGE"), "1");
+ assert_string_equal(sb_trie_lookup(c, "LAST_PAGE"), "4");
+ sb_trie_free(c);
+ sb_slist_free_full(s, free);
+ sb_slist_free_full(t, (sb_free_func_t) sb_trie_free);
}
@@ -384,77 +384,77 @@ static void
test_source_parse_from_files_filter_by_page3(void **state)
{
will_return(__wrap_blogc_file_get_contents, "bola1.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 123\n"
"DATE: 2001-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola2.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 456\n"
"DATE: 2002-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola3.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 789\n"
"DATE: 2003-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola4.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 7891\n"
"DATE: 2004-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola5.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 7892\n"
"DATE: 2005-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola6.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 7893\n"
"DATE: 2006-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola7.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 7894\n"
"DATE: 2007-02-03 04:05:06\n"
"--------\n"
"bola"));
blogc_error_t *err = NULL;
- b_slist_t *s = NULL;
- s = b_slist_append(s, b_strdup("bola1.txt"));
- s = b_slist_append(s, b_strdup("bola2.txt"));
- s = b_slist_append(s, b_strdup("bola3.txt"));
- s = b_slist_append(s, b_strdup("bola4.txt"));
- s = b_slist_append(s, b_strdup("bola5.txt"));
- s = b_slist_append(s, b_strdup("bola6.txt"));
- s = b_slist_append(s, b_strdup("bola7.txt"));
- b_trie_t *c = b_trie_new(free);
- b_trie_insert(c, "FILTER_PAGE", b_strdup("1"));
- b_trie_insert(c, "FILTER_PER_PAGE", b_strdup("2"));
- b_slist_t *t = blogc_source_parse_from_files(c, s, &err);
+ sb_slist_t *s = NULL;
+ s = sb_slist_append(s, sb_strdup("bola1.txt"));
+ s = sb_slist_append(s, sb_strdup("bola2.txt"));
+ s = sb_slist_append(s, sb_strdup("bola3.txt"));
+ s = sb_slist_append(s, sb_strdup("bola4.txt"));
+ s = sb_slist_append(s, sb_strdup("bola5.txt"));
+ s = sb_slist_append(s, sb_strdup("bola6.txt"));
+ s = sb_slist_append(s, sb_strdup("bola7.txt"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_trie_insert(c, "FILTER_PAGE", sb_strdup("1"));
+ sb_trie_insert(c, "FILTER_PER_PAGE", sb_strdup("2"));
+ sb_slist_t *t = blogc_source_parse_from_files(c, s, &err);
assert_null(err);
assert_non_null(t);
- assert_int_equal(b_slist_length(t), 2); // it is enough, no need to look at the items
- assert_int_equal(b_trie_size(c), 10);
- assert_string_equal(b_trie_lookup(c, "FILENAME_FIRST"), "bola1");
- assert_string_equal(b_trie_lookup(c, "FILENAME_LAST"), "bola2");
- assert_string_equal(b_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06");
- assert_string_equal(b_trie_lookup(c, "DATE_LAST"), "2002-02-03 04:05:06");
- assert_string_equal(b_trie_lookup(c, "FILTER_PAGE"), "1");
- assert_string_equal(b_trie_lookup(c, "FILTER_PER_PAGE"), "2");
- assert_string_equal(b_trie_lookup(c, "CURRENT_PAGE"), "1");
- assert_string_equal(b_trie_lookup(c, "NEXT_PAGE"), "2");
- assert_string_equal(b_trie_lookup(c, "FIRST_PAGE"), "1");
- assert_string_equal(b_trie_lookup(c, "LAST_PAGE"), "4");
- b_trie_free(c);
- b_slist_free_full(s, free);
- b_slist_free_full(t, (b_free_func_t) b_trie_free);
+ assert_int_equal(sb_slist_length(t), 2); // it is enough, no need to look at the items
+ assert_int_equal(sb_trie_size(c), 10);
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_FIRST"), "bola1");
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_LAST"), "bola2");
+ assert_string_equal(sb_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "DATE_LAST"), "2002-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_PAGE"), "1");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_PER_PAGE"), "2");
+ assert_string_equal(sb_trie_lookup(c, "CURRENT_PAGE"), "1");
+ assert_string_equal(sb_trie_lookup(c, "NEXT_PAGE"), "2");
+ assert_string_equal(sb_trie_lookup(c, "FIRST_PAGE"), "1");
+ assert_string_equal(sb_trie_lookup(c, "LAST_PAGE"), "4");
+ sb_trie_free(c);
+ sb_slist_free_full(s, free);
+ sb_slist_free_full(t, (sb_free_func_t) sb_trie_free);
}
@@ -462,84 +462,84 @@ static void
test_source_parse_from_files_filter_by_page_and_tag(void **state)
{
will_return(__wrap_blogc_file_get_contents, "bola1.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 123\n"
"DATE: 2001-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola2.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 456\n"
"DATE: 2002-02-03 04:05:06\n"
"TAGS: chunda\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola3.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 789\n"
"DATE: 2003-02-03 04:05:06\n"
"TAGS: chunda, bola\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola4.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 7891\n"
"DATE: 2004-02-03 04:05:06\n"
"TAGS: bola\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola5.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 7892\n"
"DATE: 2005-02-03 04:05:06\n"
"TAGS: chunda\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola6.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 7893\n"
"DATE: 2006-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola7.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 7894\n"
"DATE: 2007-02-03 04:05:06\n"
"TAGS: yay, chunda\n"
"--------\n"
"bola"));
blogc_error_t *err = NULL;
- b_slist_t *s = NULL;
- s = b_slist_append(s, b_strdup("bola1.txt"));
- s = b_slist_append(s, b_strdup("bola2.txt"));
- s = b_slist_append(s, b_strdup("bola3.txt"));
- s = b_slist_append(s, b_strdup("bola4.txt"));
- s = b_slist_append(s, b_strdup("bola5.txt"));
- s = b_slist_append(s, b_strdup("bola6.txt"));
- s = b_slist_append(s, b_strdup("bola7.txt"));
- b_trie_t *c = b_trie_new(free);
- b_trie_insert(c, "FILTER_TAG", b_strdup("chunda"));
- b_trie_insert(c, "FILTER_PAGE", b_strdup("2"));
- b_trie_insert(c, "FILTER_PER_PAGE", b_strdup("2"));
- b_slist_t *t = blogc_source_parse_from_files(c, s, &err);
+ sb_slist_t *s = NULL;
+ s = sb_slist_append(s, sb_strdup("bola1.txt"));
+ s = sb_slist_append(s, sb_strdup("bola2.txt"));
+ s = sb_slist_append(s, sb_strdup("bola3.txt"));
+ s = sb_slist_append(s, sb_strdup("bola4.txt"));
+ s = sb_slist_append(s, sb_strdup("bola5.txt"));
+ s = sb_slist_append(s, sb_strdup("bola6.txt"));
+ s = sb_slist_append(s, sb_strdup("bola7.txt"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_trie_insert(c, "FILTER_TAG", sb_strdup("chunda"));
+ sb_trie_insert(c, "FILTER_PAGE", sb_strdup("2"));
+ sb_trie_insert(c, "FILTER_PER_PAGE", sb_strdup("2"));
+ sb_slist_t *t = blogc_source_parse_from_files(c, s, &err);
assert_null(err);
assert_non_null(t);
- assert_int_equal(b_slist_length(t), 2); // it is enough, no need to look at the items
- assert_int_equal(b_trie_size(c), 11);
- assert_string_equal(b_trie_lookup(c, "FILENAME_FIRST"), "bola5");
- assert_string_equal(b_trie_lookup(c, "FILENAME_LAST"), "bola7");
- assert_string_equal(b_trie_lookup(c, "DATE_FIRST"), "2005-02-03 04:05:06");
- assert_string_equal(b_trie_lookup(c, "DATE_LAST"), "2007-02-03 04:05:06");
- assert_string_equal(b_trie_lookup(c, "FILTER_TAG"), "chunda");
- assert_string_equal(b_trie_lookup(c, "FILTER_PAGE"), "2");
- assert_string_equal(b_trie_lookup(c, "FILTER_PER_PAGE"), "2");
- assert_string_equal(b_trie_lookup(c, "CURRENT_PAGE"), "2");
- assert_string_equal(b_trie_lookup(c, "PREVIOUS_PAGE"), "1");
- assert_string_equal(b_trie_lookup(c, "FIRST_PAGE"), "1");
- assert_string_equal(b_trie_lookup(c, "LAST_PAGE"), "2");
- b_trie_free(c);
- b_slist_free_full(s, free);
- b_slist_free_full(t, (b_free_func_t) b_trie_free);
+ assert_int_equal(sb_slist_length(t), 2); // it is enough, no need to look at the items
+ assert_int_equal(sb_trie_size(c), 11);
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_FIRST"), "bola5");
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_LAST"), "bola7");
+ assert_string_equal(sb_trie_lookup(c, "DATE_FIRST"), "2005-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "DATE_LAST"), "2007-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_TAG"), "chunda");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_PAGE"), "2");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_PER_PAGE"), "2");
+ assert_string_equal(sb_trie_lookup(c, "CURRENT_PAGE"), "2");
+ assert_string_equal(sb_trie_lookup(c, "PREVIOUS_PAGE"), "1");
+ assert_string_equal(sb_trie_lookup(c, "FIRST_PAGE"), "1");
+ assert_string_equal(sb_trie_lookup(c, "LAST_PAGE"), "2");
+ sb_trie_free(c);
+ sb_slist_free_full(s, free);
+ sb_slist_free_full(t, (sb_free_func_t) sb_trie_free);
}
@@ -547,77 +547,77 @@ static void
test_source_parse_from_files_filter_by_page_invalid(void **state)
{
will_return(__wrap_blogc_file_get_contents, "bola1.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 123\n"
"DATE: 2001-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola2.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 456\n"
"DATE: 2002-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola3.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 789\n"
"DATE: 2003-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola4.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 7891\n"
"DATE: 2004-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola5.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 7892\n"
"DATE: 2005-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola6.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 7893\n"
"DATE: 2006-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola7.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 7894\n"
"DATE: 2007-02-03 04:05:06\n"
"--------\n"
"bola"));
blogc_error_t *err = NULL;
- b_slist_t *s = NULL;
- s = b_slist_append(s, b_strdup("bola1.txt"));
- s = b_slist_append(s, b_strdup("bola2.txt"));
- s = b_slist_append(s, b_strdup("bola3.txt"));
- s = b_slist_append(s, b_strdup("bola4.txt"));
- s = b_slist_append(s, b_strdup("bola5.txt"));
- s = b_slist_append(s, b_strdup("bola6.txt"));
- s = b_slist_append(s, b_strdup("bola7.txt"));
- b_trie_t *c = b_trie_new(free);
- b_trie_insert(c, "FILTER_PAGE", b_strdup("-1"));
- b_trie_insert(c, "FILTER_PER_PAGE", b_strdup("2"));
- b_slist_t *t = blogc_source_parse_from_files(c, s, &err);
+ sb_slist_t *s = NULL;
+ s = sb_slist_append(s, sb_strdup("bola1.txt"));
+ s = sb_slist_append(s, sb_strdup("bola2.txt"));
+ s = sb_slist_append(s, sb_strdup("bola3.txt"));
+ s = sb_slist_append(s, sb_strdup("bola4.txt"));
+ s = sb_slist_append(s, sb_strdup("bola5.txt"));
+ s = sb_slist_append(s, sb_strdup("bola6.txt"));
+ s = sb_slist_append(s, sb_strdup("bola7.txt"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_trie_insert(c, "FILTER_PAGE", sb_strdup("-1"));
+ sb_trie_insert(c, "FILTER_PER_PAGE", sb_strdup("2"));
+ sb_slist_t *t = blogc_source_parse_from_files(c, s, &err);
assert_null(err);
assert_non_null(t);
- assert_int_equal(b_slist_length(t), 2); // it is enough, no need to look at the items
- assert_int_equal(b_trie_size(c), 10);
- assert_string_equal(b_trie_lookup(c, "FILENAME_FIRST"), "bola1");
- assert_string_equal(b_trie_lookup(c, "FILENAME_LAST"), "bola2");
- assert_string_equal(b_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06");
- assert_string_equal(b_trie_lookup(c, "DATE_LAST"), "2002-02-03 04:05:06");
- assert_string_equal(b_trie_lookup(c, "FILTER_PAGE"), "-1");
- assert_string_equal(b_trie_lookup(c, "FILTER_PER_PAGE"), "2");
- assert_string_equal(b_trie_lookup(c, "CURRENT_PAGE"), "1");
- assert_string_equal(b_trie_lookup(c, "NEXT_PAGE"), "2");
- assert_string_equal(b_trie_lookup(c, "FIRST_PAGE"), "1");
- assert_string_equal(b_trie_lookup(c, "LAST_PAGE"), "4");
- b_trie_free(c);
- b_slist_free_full(s, free);
- b_slist_free_full(t, (b_free_func_t) b_trie_free);
+ assert_int_equal(sb_slist_length(t), 2); // it is enough, no need to look at the items
+ assert_int_equal(sb_trie_size(c), 10);
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_FIRST"), "bola1");
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_LAST"), "bola2");
+ assert_string_equal(sb_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "DATE_LAST"), "2002-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_PAGE"), "-1");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_PER_PAGE"), "2");
+ assert_string_equal(sb_trie_lookup(c, "CURRENT_PAGE"), "1");
+ assert_string_equal(sb_trie_lookup(c, "NEXT_PAGE"), "2");
+ assert_string_equal(sb_trie_lookup(c, "FIRST_PAGE"), "1");
+ assert_string_equal(sb_trie_lookup(c, "LAST_PAGE"), "4");
+ sb_trie_free(c);
+ sb_slist_free_full(s, free);
+ sb_slist_free_full(t, (sb_free_func_t) sb_trie_free);
}
@@ -625,64 +625,64 @@ static void
test_source_parse_from_files_filter_by_page_invalid2(void **state)
{
will_return(__wrap_blogc_file_get_contents, "bola1.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 123\n"
"DATE: 2001-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola2.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 456\n"
"DATE: 2002-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola3.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 789\n"
"DATE: 2003-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola4.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 7891\n"
"DATE: 2004-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola5.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 7892\n"
"DATE: 2005-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola6.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 7893\n"
"DATE: 2006-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola7.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 7894\n"
"DATE: 2007-02-03 04:05:06\n"
"--------\n"
"bola"));
blogc_error_t *err = NULL;
- b_slist_t *s = NULL;
- s = b_slist_append(s, b_strdup("bola1.txt"));
- s = b_slist_append(s, b_strdup("bola2.txt"));
- s = b_slist_append(s, b_strdup("bola3.txt"));
- s = b_slist_append(s, b_strdup("bola4.txt"));
- s = b_slist_append(s, b_strdup("bola5.txt"));
- s = b_slist_append(s, b_strdup("bola6.txt"));
- s = b_slist_append(s, b_strdup("bola7.txt"));
- b_trie_t *c = b_trie_new(free);
- b_trie_insert(c, "FILTER_PAGE", b_strdup("5"));
- b_trie_insert(c, "FILTER_PER_PAGE", b_strdup("2"));
- b_slist_t *t = blogc_source_parse_from_files(c, s, &err);
+ sb_slist_t *s = NULL;
+ s = sb_slist_append(s, sb_strdup("bola1.txt"));
+ s = sb_slist_append(s, sb_strdup("bola2.txt"));
+ s = sb_slist_append(s, sb_strdup("bola3.txt"));
+ s = sb_slist_append(s, sb_strdup("bola4.txt"));
+ s = sb_slist_append(s, sb_strdup("bola5.txt"));
+ s = sb_slist_append(s, sb_strdup("bola6.txt"));
+ s = sb_slist_append(s, sb_strdup("bola7.txt"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_trie_insert(c, "FILTER_PAGE", sb_strdup("5"));
+ sb_trie_insert(c, "FILTER_PER_PAGE", sb_strdup("2"));
+ sb_slist_t *t = blogc_source_parse_from_files(c, s, &err);
assert_null(err);
assert_null(t);
- b_trie_free(c);
- b_slist_free_full(s, free);
+ sb_trie_free(c);
+ sb_slist_free_full(s, free);
}
@@ -695,39 +695,39 @@ test_source_parse_from_files_without_all_dates(void **state)
"file, but not for all source files. This means that you may get wrong "
"values for 'DATE_FIRST' and 'DATE_LAST' variables.\n");
will_return(__wrap_blogc_file_get_contents, "bola1.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 123\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola2.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 456\n"
"DATE: 2002-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola3.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 789\n"
"DATE: 2003-02-03 04:05:06\n"
"--------\n"
"bola"));
blogc_error_t *err = NULL;
- b_slist_t *s = NULL;
- s = b_slist_append(s, b_strdup("bola1.txt"));
- s = b_slist_append(s, b_strdup("bola2.txt"));
- s = b_slist_append(s, b_strdup("bola3.txt"));
- b_trie_t *c = b_trie_new(free);
- b_slist_t *t = blogc_source_parse_from_files(c, s, &err);
+ sb_slist_t *s = NULL;
+ s = sb_slist_append(s, sb_strdup("bola1.txt"));
+ s = sb_slist_append(s, sb_strdup("bola2.txt"));
+ s = sb_slist_append(s, sb_strdup("bola3.txt"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_slist_t *t = blogc_source_parse_from_files(c, s, &err);
assert_null(err);
assert_non_null(t);
- assert_int_equal(b_slist_length(t), 3); // it is enough, no need to look at the items
- assert_int_equal(b_trie_size(c), 3);
- assert_string_equal(b_trie_lookup(c, "FILENAME_FIRST"), "bola1");
- assert_string_equal(b_trie_lookup(c, "FILENAME_LAST"), "bola3");
- assert_string_equal(b_trie_lookup(c, "DATE_LAST"), "2003-02-03 04:05:06");
- b_trie_free(c);
- b_slist_free_full(s, free);
- b_slist_free_full(t, (b_free_func_t) b_trie_free);
+ assert_int_equal(sb_slist_length(t), 3); // it is enough, no need to look at the items
+ assert_int_equal(sb_trie_size(c), 3);
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_FIRST"), "bola1");
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_LAST"), "bola3");
+ assert_string_equal(sb_trie_lookup(c, "DATE_LAST"), "2003-02-03 04:05:06");
+ sb_trie_free(c);
+ sb_slist_free_full(s, free);
+ sb_slist_free_full(t, (sb_free_func_t) sb_trie_free);
}
@@ -735,16 +735,16 @@ static void
test_source_parse_from_files_null(void **state)
{
blogc_error_t *err = NULL;
- b_slist_t *s = NULL;
- b_trie_t *c = b_trie_new(free);
- b_slist_t *t = blogc_source_parse_from_files(c, s, &err);
+ sb_slist_t *s = NULL;
+ sb_trie_t *c = sb_trie_new(free);
+ sb_slist_t *t = blogc_source_parse_from_files(c, s, &err);
assert_null(err);
assert_null(t);
- assert_int_equal(b_slist_length(t), 0);
- assert_int_equal(b_trie_size(c), 0);
- b_trie_free(c);
- b_slist_free_full(s, free);
- b_slist_free_full(t, (b_free_func_t) b_trie_free);
+ assert_int_equal(sb_slist_length(t), 0);
+ assert_int_equal(sb_trie_size(c), 0);
+ sb_trie_free(c);
+ sb_slist_free_full(s, free);
+ sb_slist_free_full(t, (sb_free_func_t) sb_trie_free);
}
diff --git a/tests/check_renderer.c b/tests/check_renderer.c
index cb8f8f1..802b159 100644
--- a/tests/check_renderer.c
+++ b/tests/check_renderer.c
@@ -19,10 +19,10 @@
#include "../src/renderer.h"
#include "../src/source-parser.h"
#include "../src/template-parser.h"
-#include "../src/utils/utils.h"
+#include <squareball.h>
-static b_slist_t*
+static sb_slist_t*
create_sources(unsigned int count)
{
const char *s[] = {
@@ -46,12 +46,12 @@ create_sources(unsigned int count)
};
assert_false(count > 3);
blogc_error_t *err = NULL;
- b_slist_t *l = NULL;
+ sb_slist_t *l = NULL;
for (unsigned int i = 0; i < count; i++) {
- l = b_slist_append(l, blogc_source_parse(s[i], strlen(s[i]), &err));
+ l = sb_slist_append(l, blogc_source_parse(s[i], strlen(s[i]), &err));
assert_null(err);
}
- assert_int_equal(b_slist_length(l), count);
+ assert_int_equal(sb_slist_length(l), count);
return l;
}
@@ -76,10 +76,10 @@ test_render_entry(void **state)
"{% if GUDA > \"zxd\" %}LOL3{% endif %}\n"
"{% if GUDA <= \"zxc\" %}LOL4{% endif %}\n";
blogc_error_t *err = NULL;
- b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- b_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, false);
assert_string_equal(out,
@@ -99,7 +99,7 @@ test_render_entry(void **state)
"\n"
"LOL4\n");
blogc_template_free_stmts(l);
- b_slist_free_full(s, (b_free_func_t) b_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -119,10 +119,10 @@ test_render_listing(void **state)
"bola: {% ifdef BOLA %}{{ BOLA }}{% endif %}\n"
"{% endblock %}\n";
blogc_error_t *err = NULL;
- b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- b_slist_t *s = create_sources(3);
+ sb_slist_t *s = create_sources(3);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, true);
assert_string_equal(out,
@@ -140,7 +140,7 @@ test_render_listing(void **state)
"bola: asd3\n"
"\n");
blogc_template_free_stmts(l);
- b_slist_free_full(s, (b_free_func_t) b_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -160,7 +160,7 @@ test_render_listing_empty(void **state)
"bola: {% ifdef BOLA %}{{ BOLA }}{% endif %}\n"
"{% endblock %}\n";
blogc_error_t *err = NULL;
- b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
char *out = blogc_render(l, NULL, NULL, true);
@@ -187,10 +187,10 @@ test_render_ifdef(void **state)
"{% endif %}\n"
"{% endblock %}\n";
blogc_error_t *err = NULL;
- b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- b_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, false);
assert_string_equal(out,
@@ -198,7 +198,7 @@ test_render_ifdef(void **state)
"\n"
"\n");
blogc_template_free_stmts(l);
- b_slist_free_full(s, (b_free_func_t) b_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -216,10 +216,10 @@ test_render_ifdef2(void **state)
"{% endif %}\n"
"{% endblock %}\n";
blogc_error_t *err = NULL;
- b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- b_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, false);
assert_string_equal(out,
@@ -229,7 +229,7 @@ test_render_ifdef2(void **state)
"\n"
"\n");
blogc_template_free_stmts(l);
- b_slist_free_full(s, (b_free_func_t) b_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -247,10 +247,10 @@ test_render_ifdef3(void **state)
"{% endif %}\n"
"{% endblock %}\n";
blogc_error_t *err = NULL;
- b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- b_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, false);
assert_string_equal(out,
@@ -262,7 +262,7 @@ test_render_ifdef3(void **state)
"\n"
"\n");
blogc_template_free_stmts(l);
- b_slist_free_full(s, (b_free_func_t) b_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -280,10 +280,10 @@ test_render_ifndef(void **state)
"{% endif %}\n"
"{% endblock %}\n";
blogc_error_t *err = NULL;
- b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- b_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, false);
assert_string_equal(out,
@@ -295,7 +295,7 @@ test_render_ifndef(void **state)
"\n"
"\n");
blogc_template_free_stmts(l);
- b_slist_free_full(s, (b_free_func_t) b_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -314,10 +314,10 @@ test_render_if_eq(void **state)
"{% endif %}\n"
"{% endblock %}\n";
blogc_error_t *err = NULL;
- b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- b_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, false);
assert_string_equal(out,
@@ -330,7 +330,7 @@ test_render_if_eq(void **state)
"\n"
"\n");
blogc_template_free_stmts(l);
- b_slist_free_full(s, (b_free_func_t) b_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -349,10 +349,10 @@ test_render_if_neq(void **state)
"{% endif %}\n"
"{% endblock %}\n";
blogc_error_t *err = NULL;
- b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- b_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, false);
assert_string_equal(out,
@@ -365,7 +365,7 @@ test_render_if_neq(void **state)
"\n"
"\n");
blogc_template_free_stmts(l);
- b_slist_free_full(s, (b_free_func_t) b_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -384,10 +384,10 @@ test_render_if_lt(void **state)
"{% endif %}\n"
"{% endblock %}\n";
blogc_error_t *err = NULL;
- b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- b_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, false);
assert_string_equal(out,
@@ -400,7 +400,7 @@ test_render_if_lt(void **state)
"\n"
"\n");
blogc_template_free_stmts(l);
- b_slist_free_full(s, (b_free_func_t) b_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -419,10 +419,10 @@ test_render_if_gt(void **state)
"{% endif %}\n"
"{% endblock %}\n";
blogc_error_t *err = NULL;
- b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- b_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, false);
assert_string_equal(out,
@@ -435,7 +435,7 @@ test_render_if_gt(void **state)
"\n"
"\n");
blogc_template_free_stmts(l);
- b_slist_free_full(s, (b_free_func_t) b_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -456,10 +456,10 @@ test_render_if_lt_eq(void **state)
"{% endif %}\n"
"{% endblock %}\n";
blogc_error_t *err = NULL;
- b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- b_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, false);
assert_string_equal(out,
@@ -474,7 +474,7 @@ test_render_if_lt_eq(void **state)
"\n"
"\n");
blogc_template_free_stmts(l);
- b_slist_free_full(s, (b_free_func_t) b_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -495,10 +495,10 @@ test_render_if_gt_eq(void **state)
"{% endif %}\n"
"{% endblock %}\n";
blogc_error_t *err = NULL;
- b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- b_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, false);
assert_string_equal(out,
@@ -513,7 +513,7 @@ test_render_if_gt_eq(void **state)
"\n"
"\n");
blogc_template_free_stmts(l);
- b_slist_free_full(s, (b_free_func_t) b_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -533,21 +533,21 @@ test_render_outside_block(void **state)
"{{ BOLA }}\n"
"{% ifndef CHUNDA %}lol{% endif %}\n";
blogc_error_t *err = NULL;
- b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- b_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
- b_trie_t *c = b_trie_new(free);
- b_trie_insert(c, "GUDA", b_strdup("asd"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_trie_insert(c, "GUDA", sb_strdup("asd"));
char *out = blogc_render(l, s, c, false);
assert_string_equal(out,
"bola\n"
"\n"
"lol\n");
- b_trie_free(c);
+ sb_trie_free(c);
blogc_template_free_stmts(l);
- b_slist_free_full(s, (b_free_func_t) b_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -566,14 +566,14 @@ test_render_prefer_local_variable(void **state)
"{% endif %}\n"
"{% endblock %}\n";
blogc_error_t *err = NULL;
- b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- b_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
- b_trie_t *c = b_trie_new(free);
- b_trie_insert(c, "GUDA", b_strdup("hehe"));
- b_trie_insert(c, "LOL", b_strdup("hmm"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_trie_insert(c, "GUDA", sb_strdup("hehe"));
+ sb_trie_insert(c, "LOL", sb_strdup("hmm"));
char *out = blogc_render(l, s, c, false);
assert_string_equal(out,
"\n"
@@ -584,9 +584,9 @@ test_render_prefer_local_variable(void **state)
"\n"
"\n"
"\n");
- b_trie_free(c);
+ sb_trie_free(c);
blogc_template_free_stmts(l);
- b_slist_free_full(s, (b_free_func_t) b_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -602,12 +602,12 @@ test_render_respect_variable_scope(void **state)
"{% ifdef BOLA %}{{ BOLA }}{% endif %}\n"
"{% endblock %}\n";
blogc_error_t *err = NULL;
- b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- b_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
- b_trie_t *c = b_trie_new(free);
+ sb_trie_t *c = sb_trie_new(free);
char *out = blogc_render(l, s, c, false);
assert_string_equal(out,
"\n"
@@ -616,9 +616,9 @@ test_render_respect_variable_scope(void **state)
"\n"
"asd\n"
"\n");
- b_trie_free(c);
+ sb_trie_free(c);
blogc_template_free_stmts(l);
- b_slist_free_full(s, (b_free_func_t) b_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -626,112 +626,112 @@ test_render_respect_variable_scope(void **state)
static void
test_get_variable(void **state)
{
- b_trie_t *g = b_trie_new(free);
- b_trie_insert(g, "NAME", b_strdup("bola"));
- b_trie_insert(g, "TITLE", b_strdup("bola2"));
- b_trie_t *l = b_trie_new(free);
- b_trie_insert(l, "NAME", b_strdup("chunda"));
- b_trie_insert(l, "TITLE", b_strdup("chunda2"));
+ sb_trie_t *g = sb_trie_new(free);
+ sb_trie_insert(g, "NAME", sb_strdup("bola"));
+ sb_trie_insert(g, "TITLE", sb_strdup("bola2"));
+ sb_trie_t *l = sb_trie_new(free);
+ sb_trie_insert(l, "NAME", sb_strdup("chunda"));
+ sb_trie_insert(l, "TITLE", sb_strdup("chunda2"));
assert_string_equal(blogc_get_variable("NAME", g, l), "chunda");
assert_string_equal(blogc_get_variable("TITLE", g, l), "chunda2");
assert_null(blogc_get_variable("BOLA", g, l));
- b_trie_free(g);
- b_trie_free(l);
+ sb_trie_free(g);
+ sb_trie_free(l);
}
static void
test_get_variable_only_local(void **state)
{
- b_trie_t *g = NULL;
- b_trie_t *l = b_trie_new(free);
- b_trie_insert(l, "NAME", b_strdup("chunda"));
- b_trie_insert(l, "TITLE", b_strdup("chunda2"));
+ sb_trie_t *g = NULL;
+ sb_trie_t *l = sb_trie_new(free);
+ sb_trie_insert(l, "NAME", sb_strdup("chunda"));
+ sb_trie_insert(l, "TITLE", sb_strdup("chunda2"));
assert_string_equal(blogc_get_variable("NAME", g, l), "chunda");
assert_string_equal(blogc_get_variable("TITLE", g, l), "chunda2");
assert_null(blogc_get_variable("BOLA", g, l));
- b_trie_free(l);
+ sb_trie_free(l);
}
static void
test_get_variable_only_global(void **state)
{
- b_trie_t *g = b_trie_new(free);
- b_trie_insert(g, "NAME", b_strdup("bola"));
- b_trie_insert(g, "TITLE", b_strdup("bola2"));
- b_trie_t *l = NULL;
+ sb_trie_t *g = sb_trie_new(free);
+ sb_trie_insert(g, "NAME", sb_strdup("bola"));
+ sb_trie_insert(g, "TITLE", sb_strdup("bola2"));
+ sb_trie_t *l = NULL;
assert_string_equal(blogc_get_variable("NAME", g, l), "bola");
assert_string_equal(blogc_get_variable("TITLE", g, l), "bola2");
assert_null(blogc_get_variable("BOLA", g, l));
- b_trie_free(g);
+ sb_trie_free(g);
}
static void
test_format_date(void **state)
{
- b_trie_t *g = b_trie_new(free);
- b_trie_insert(g, "DATE_FORMAT", b_strdup("%H -- %M"));
- b_trie_t *l = b_trie_new(free);
- b_trie_insert(l, "DATE_FORMAT", b_strdup("%R"));
+ sb_trie_t *g = sb_trie_new(free);
+ sb_trie_insert(g, "DATE_FORMAT", sb_strdup("%H -- %M"));
+ sb_trie_t *l = sb_trie_new(free);
+ sb_trie_insert(l, "DATE_FORMAT", sb_strdup("%R"));
char *date = blogc_format_date("2015-01-02 03:04:05", g, l);
assert_string_equal(date, "03:04");
free(date);
- b_trie_free(g);
- b_trie_free(l);
+ sb_trie_free(g);
+ sb_trie_free(l);
}
static void
test_format_date_with_global_format(void **state)
{
- b_trie_t *g = b_trie_new(free);
- b_trie_insert(g, "DATE_FORMAT", b_strdup("%H -- %M"));
- b_trie_t *l = b_trie_new(free);
+ sb_trie_t *g = sb_trie_new(free);
+ sb_trie_insert(g, "DATE_FORMAT", sb_strdup("%H -- %M"));
+ sb_trie_t *l = sb_trie_new(free);
char *date = blogc_format_date("2015-01-02 03:04:05", g, l);
assert_string_equal(date, "03 -- 04");
free(date);
- b_trie_free(g);
- b_trie_free(l);
+ sb_trie_free(g);
+ sb_trie_free(l);
}
static void
test_format_date_without_format(void **state)
{
- b_trie_t *g = b_trie_new(free);
- b_trie_t *l = b_trie_new(free);
+ sb_trie_t *g = sb_trie_new(free);
+ sb_trie_t *l = sb_trie_new(free);
char *date = blogc_format_date("2015-01-02 03:04:05", g, l);
assert_string_equal(date, "2015-01-02 03:04:05");
free(date);
- b_trie_free(g);
- b_trie_free(l);
+ sb_trie_free(g);
+ sb_trie_free(l);
}
static void
test_format_date_without_date(void **state)
{
- b_trie_t *g = b_trie_new(free);
- b_trie_t *l = b_trie_new(free);
+ sb_trie_t *g = sb_trie_new(free);
+ sb_trie_t *l = sb_trie_new(free);
char *date = blogc_format_date(NULL, g, l);
assert_null(date);
free(date);
- b_trie_free(g);
- b_trie_free(l);
+ sb_trie_free(g);
+ sb_trie_free(l);
}
static void
test_format_variable(void **state)
{
- b_trie_t *g = b_trie_new(free);
- b_trie_insert(g, "NAME", b_strdup("bola"));
- b_trie_insert(g, "TITLE", b_strdup("bola2"));
- b_trie_t *l = b_trie_new(free);
- b_trie_insert(l, "NAME", b_strdup("chunda"));
- b_trie_insert(l, "TITLE", b_strdup("chunda2"));
+ sb_trie_t *g = sb_trie_new(free);
+ sb_trie_insert(g, "NAME", sb_strdup("bola"));
+ sb_trie_insert(g, "TITLE", sb_strdup("bola2"));
+ sb_trie_t *l = sb_trie_new(free);
+ sb_trie_insert(l, "NAME", sb_strdup("chunda"));
+ sb_trie_insert(l, "TITLE", sb_strdup("chunda2"));
char *tmp = blogc_format_variable("NAME", g, l);
assert_string_equal(tmp, "chunda");
free(tmp);
@@ -739,24 +739,24 @@ test_format_variable(void **state)
assert_string_equal(tmp, "chunda2");
free(tmp);
assert_null(blogc_format_variable("BOLA", g, l));
- b_trie_free(g);
- b_trie_free(l);
+ sb_trie_free(g);
+ sb_trie_free(l);
}
static void
test_format_variable_with_date(void **state)
{
- b_trie_t *g = b_trie_new(free);
- b_trie_insert(g, "DATE", b_strdup("2010-11-12 13:14:15"));
- b_trie_insert(g, "DATE_FORMAT", b_strdup("%R"));
- b_trie_t *l = b_trie_new(free);
- b_trie_insert(l, "DATE", b_strdup("2011-12-13 14:15:16"));
+ sb_trie_t *g = sb_trie_new(free);
+ sb_trie_insert(g, "DATE", sb_strdup("2010-11-12 13:14:15"));
+ sb_trie_insert(g, "DATE_FORMAT", sb_strdup("%R"));
+ sb_trie_t *l = sb_trie_new(free);
+ sb_trie_insert(l, "DATE", sb_strdup("2011-12-13 14:15:16"));
char *tmp = blogc_format_variable("DATE_FORMATTED", g, l);
assert_string_equal(tmp, "14:15");
free(tmp);
- b_trie_free(g);
- b_trie_free(l);
+ sb_trie_free(g);
+ sb_trie_free(l);
}
diff --git a/tests/check_source_parser.c b/tests/check_source_parser.c
index 4d8518e..686a228 100644
--- a/tests/check_source_parser.c
+++ b/tests/check_source_parser.c
@@ -17,7 +17,7 @@
#include <string.h>
#include "../src/source-parser.h"
#include "../src/error.h"
-#include "../src/utils/utils.h"
+#include <squareball.h>
static void
@@ -31,23 +31,23 @@ test_source_parse(void **state)
"\n"
"bola\n";
blogc_error_t *err = NULL;
- b_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(source);
- assert_int_equal(b_trie_size(source), 5);
- assert_string_equal(b_trie_lookup(source, "VAR1"), "asd asd");
- assert_string_equal(b_trie_lookup(source, "VAR2"), "123chunda");
- assert_string_equal(b_trie_lookup(source, "EXCERPT"),
+ assert_int_equal(sb_trie_size(source), 5);
+ assert_string_equal(sb_trie_lookup(source, "VAR1"), "asd asd");
+ assert_string_equal(sb_trie_lookup(source, "VAR2"), "123chunda");
+ assert_string_equal(sb_trie_lookup(source, "EXCERPT"),
"<h1 id=\"this-is-a-test\">This is a test</h1>\n"
"<p>bola</p>\n");
- assert_string_equal(b_trie_lookup(source, "CONTENT"),
+ assert_string_equal(sb_trie_lookup(source, "CONTENT"),
"<h1 id=\"this-is-a-test\">This is a test</h1>\n"
"<p>bola</p>\n");
- assert_string_equal(b_trie_lookup(source, "RAW_CONTENT"),
+ assert_string_equal(sb_trie_lookup(source, "RAW_CONTENT"),
"# This is a test\n"
"\n"
"bola\n");
- b_trie_free(source);
+ sb_trie_free(source);
}
@@ -62,23 +62,23 @@ test_source_parse_crlf(void **state)
"\r\n"
"bola\r\n";
blogc_error_t *err = NULL;
- b_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(source);
- assert_int_equal(b_trie_size(source), 5);
- assert_string_equal(b_trie_lookup(source, "VAR1"), "asd asd");
- assert_string_equal(b_trie_lookup(source, "VAR2"), "123chunda");
- assert_string_equal(b_trie_lookup(source, "EXCERPT"),
+ assert_int_equal(sb_trie_size(source), 5);
+ assert_string_equal(sb_trie_lookup(source, "VAR1"), "asd asd");
+ assert_string_equal(sb_trie_lookup(source, "VAR2"), "123chunda");
+ assert_string_equal(sb_trie_lookup(source, "EXCERPT"),
"<h1 id=\"this-is-a-test\">This is a test</h1>\r\n"
"<p>bola</p>\r\n");
- assert_string_equal(b_trie_lookup(source, "CONTENT"),
+ assert_string_equal(sb_trie_lookup(source, "CONTENT"),
"<h1 id=\"this-is-a-test\">This is a test</h1>\r\n"
"<p>bola</p>\r\n");
- assert_string_equal(b_trie_lookup(source, "RAW_CONTENT"),
+ assert_string_equal(sb_trie_lookup(source, "RAW_CONTENT"),
"# This is a test\r\n"
"\r\n"
"bola\r\n");
- b_trie_free(source);
+ sb_trie_free(source);
}
@@ -95,23 +95,23 @@ test_source_parse_with_spaces(void **state)
"\n"
"bola\n";
blogc_error_t *err = NULL;
- b_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(source);
- assert_int_equal(b_trie_size(source), 5);
- assert_string_equal(b_trie_lookup(source, "VAR1"), "chunda");
- assert_string_equal(b_trie_lookup(source, "BOLA"), "guda");
- assert_string_equal(b_trie_lookup(source, "EXCERPT"),
+ assert_int_equal(sb_trie_size(source), 5);
+ assert_string_equal(sb_trie_lookup(source, "VAR1"), "chunda");
+ assert_string_equal(sb_trie_lookup(source, "BOLA"), "guda");
+ assert_string_equal(sb_trie_lookup(source, "EXCERPT"),
"<h1 id=\"this-is-a-test\">This is a test</h1>\n"
"<p>bola</p>\n");
- assert_string_equal(b_trie_lookup(source, "CONTENT"),
+ assert_string_equal(sb_trie_lookup(source, "CONTENT"),
"<h1 id=\"this-is-a-test\">This is a test</h1>\n"
"<p>bola</p>\n");
- assert_string_equal(b_trie_lookup(source, "RAW_CONTENT"),
+ assert_string_equal(sb_trie_lookup(source, "RAW_CONTENT"),
"# This is a test\n"
"\n"
"bola\n");
- b_trie_free(source);
+ sb_trie_free(source);
}
@@ -131,21 +131,21 @@ test_source_parse_with_excerpt(void **state)
"guda\n"
"yay";
blogc_error_t *err = NULL;
- b_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(source);
- assert_int_equal(b_trie_size(source), 5);
- assert_string_equal(b_trie_lookup(source, "VAR1"), "asd asd");
- assert_string_equal(b_trie_lookup(source, "VAR2"), "123chunda");
- assert_string_equal(b_trie_lookup(source, "EXCERPT"),
+ assert_int_equal(sb_trie_size(source), 5);
+ assert_string_equal(sb_trie_lookup(source, "VAR1"), "asd asd");
+ assert_string_equal(sb_trie_lookup(source, "VAR2"), "123chunda");
+ assert_string_equal(sb_trie_lookup(source, "EXCERPT"),
"<h1 id=\"this-is-a-test\">This is a test</h1>\n"
"<p>bola</p>\n");
- assert_string_equal(b_trie_lookup(source, "CONTENT"),
+ assert_string_equal(sb_trie_lookup(source, "CONTENT"),
"<h1 id=\"this-is-a-test\">This is a test</h1>\n"
"<p>bola</p>\n"
"<p>guda\n"
"yay</p>\n");
- assert_string_equal(b_trie_lookup(source, "RAW_CONTENT"),
+ assert_string_equal(sb_trie_lookup(source, "RAW_CONTENT"),
"# This is a test\n"
"\n"
"bola\n"
@@ -154,7 +154,7 @@ test_source_parse_with_excerpt(void **state)
"\n"
"guda\n"
"yay");
- b_trie_free(source);
+ sb_trie_free(source);
}
@@ -163,13 +163,13 @@ test_source_parse_config_empty(void **state)
{
const char *a = "";
blogc_error_t *err = NULL;
- b_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
assert_string_equal(err->msg, "Your source file is empty.");
blogc_error_free(err);
- b_trie_free(source);
+ sb_trie_free(source);
}
@@ -178,14 +178,14 @@ test_source_parse_config_invalid_key(void **state)
{
const char *a = "bola: guda";
blogc_error_t *err = NULL;
- b_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_non_null(err);
assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
assert_string_equal(err->msg,
"Can't find a configuration key or the content separator.\n"
"Error occurred near line 1, position 1: bola: guda");
blogc_error_free(err);
- b_trie_free(source);
+ sb_trie_free(source);
}
@@ -194,14 +194,14 @@ test_source_parse_config_no_key(void **state)
{
const char *a = "BOLa";
blogc_error_t *err = NULL;
- b_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_non_null(err);
assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
assert_string_equal(err->msg,
"Invalid configuration key.\n"
"Error occurred near line 1, position 4: BOLa");
blogc_error_free(err);
- b_trie_free(source);
+ sb_trie_free(source);
}
@@ -210,14 +210,14 @@ test_source_parse_config_no_key2(void **state)
{
const char *a = "BOLA";
blogc_error_t *err = NULL;
- b_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_non_null(err);
assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
assert_string_equal(err->msg,
"Your last configuration key is missing ':' and the value\n"
"Error occurred near line 1, position 5: BOLA");
blogc_error_free(err);
- b_trie_free(source);
+ sb_trie_free(source);
}
@@ -226,7 +226,7 @@ test_source_parse_config_no_value(void **state)
{
const char *a = "BOLA:\r\n";
blogc_error_t *err = NULL;
- b_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
@@ -234,7 +234,7 @@ test_source_parse_config_no_value(void **state)
"Configuration value not provided for 'BOLA'.\n"
"Error occurred near line 1, position 6: BOLA:");
blogc_error_free(err);
- b_trie_free(source);
+ sb_trie_free(source);
}
@@ -243,7 +243,7 @@ test_source_parse_config_no_value2(void **state)
{
const char *a = "BOLA:";
blogc_error_t *err = NULL;
- b_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
@@ -251,7 +251,7 @@ test_source_parse_config_no_value2(void **state)
"Configuration value not provided for 'BOLA'.\n"
"Error occurred near line 1, position 6: BOLA:");
blogc_error_free(err);
- b_trie_free(source);
+ sb_trie_free(source);
}
@@ -260,7 +260,7 @@ test_source_parse_config_reserved_name(void **state)
{
const char *a = "FILENAME: asd\r\n";
blogc_error_t *err = NULL;
- b_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
@@ -268,7 +268,7 @@ test_source_parse_config_reserved_name(void **state)
"'FILENAME' variable is forbidden in source files. It will be set "
"for you by the compiler.");
blogc_error_free(err);
- b_trie_free(source);
+ sb_trie_free(source);
}
@@ -277,7 +277,7 @@ test_source_parse_config_reserved_name2(void **state)
{
const char *a = "CONTENT: asd\r\n";
blogc_error_t *err = NULL;
- b_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
@@ -285,7 +285,7 @@ test_source_parse_config_reserved_name2(void **state)
"'CONTENT' variable is forbidden in source files. It will be set "
"for you by the compiler.");
blogc_error_free(err);
- b_trie_free(source);
+ sb_trie_free(source);
}
@@ -294,7 +294,7 @@ test_source_parse_config_reserved_name3(void **state)
{
const char *a = "DATE_FORMATTED: asd\r\n";
blogc_error_t *err = NULL;
- b_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
@@ -302,7 +302,7 @@ test_source_parse_config_reserved_name3(void **state)
"'DATE_FORMATTED' variable is forbidden in source files. It will be set "
"for you by the compiler.");
blogc_error_free(err);
- b_trie_free(source);
+ sb_trie_free(source);
}
@@ -311,7 +311,7 @@ test_source_parse_config_reserved_name4(void **state)
{
const char *a = "DATE_FIRST_FORMATTED: asd\r\n";
blogc_error_t *err = NULL;
- b_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
@@ -319,7 +319,7 @@ test_source_parse_config_reserved_name4(void **state)
"'DATE_FIRST_FORMATTED' variable is forbidden in source files. It will be set "
"for you by the compiler.");
blogc_error_free(err);
- b_trie_free(source);
+ sb_trie_free(source);
}
@@ -328,7 +328,7 @@ test_source_parse_config_reserved_name5(void **state)
{
const char *a = "DATE_LAST_FORMATTED: asd\r\n";
blogc_error_t *err = NULL;
- b_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
@@ -336,7 +336,7 @@ test_source_parse_config_reserved_name5(void **state)
"'DATE_LAST_FORMATTED' variable is forbidden in source files. It will be set "
"for you by the compiler.");
blogc_error_free(err);
- b_trie_free(source);
+ sb_trie_free(source);
}
@@ -345,7 +345,7 @@ test_source_parse_config_reserved_name6(void **state)
{
const char *a = "PAGE_FIRST: asd\r\n";
blogc_error_t *err = NULL;
- b_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
@@ -353,7 +353,7 @@ test_source_parse_config_reserved_name6(void **state)
"'PAGE_FIRST' variable is forbidden in source files. It will be set "
"for you by the compiler.");
blogc_error_free(err);
- b_trie_free(source);
+ sb_trie_free(source);
}
@@ -362,7 +362,7 @@ test_source_parse_config_reserved_name7(void **state)
{
const char *a = "PAGE_PREVIOUS: asd\r\n";
blogc_error_t *err = NULL;
- b_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
@@ -370,7 +370,7 @@ test_source_parse_config_reserved_name7(void **state)
"'PAGE_PREVIOUS' variable is forbidden in source files. It will be set "
"for you by the compiler.");
blogc_error_free(err);
- b_trie_free(source);
+ sb_trie_free(source);
}
@@ -379,7 +379,7 @@ test_source_parse_config_reserved_name8(void **state)
{
const char *a = "PAGE_CURRENT: asd\r\n";
blogc_error_t *err = NULL;
- b_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
@@ -387,7 +387,7 @@ test_source_parse_config_reserved_name8(void **state)
"'PAGE_CURRENT' variable is forbidden in source files. It will be set "
"for you by the compiler.");
blogc_error_free(err);
- b_trie_free(source);
+ sb_trie_free(source);
}
@@ -396,7 +396,7 @@ test_source_parse_config_reserved_name9(void **state)
{
const char *a = "PAGE_NEXT: asd\r\n";
blogc_error_t *err = NULL;
- b_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
@@ -404,7 +404,7 @@ test_source_parse_config_reserved_name9(void **state)
"'PAGE_NEXT' variable is forbidden in source files. It will be set "
"for you by the compiler.");
blogc_error_free(err);
- b_trie_free(source);
+ sb_trie_free(source);
}
@@ -413,7 +413,7 @@ test_source_parse_config_reserved_name10(void **state)
{
const char *a = "PAGE_LAST: asd\r\n";
blogc_error_t *err = NULL;
- b_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
@@ -421,7 +421,7 @@ test_source_parse_config_reserved_name10(void **state)
"'PAGE_LAST' variable is forbidden in source files. It will be set "
"for you by the compiler.");
blogc_error_free(err);
- b_trie_free(source);
+ sb_trie_free(source);
}
@@ -430,7 +430,7 @@ test_source_parse_config_reserved_name11(void **state)
{
const char *a = "BLOGC_VERSION: 1.0\r\n";
blogc_error_t *err = NULL;
- b_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
@@ -438,7 +438,7 @@ test_source_parse_config_reserved_name11(void **state)
"'BLOGC_VERSION' variable is forbidden in source files. It will be set "
"for you by the compiler.");
blogc_error_free(err);
- b_trie_free(source);
+ sb_trie_free(source);
}
@@ -447,7 +447,7 @@ test_source_parse_config_value_no_line_ending(void **state)
{
const char *a = "BOLA: asd";
blogc_error_t *err = NULL;
- b_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
@@ -455,7 +455,7 @@ test_source_parse_config_value_no_line_ending(void **state)
"No line ending after the configuration value for 'BOLA'.\n"
"Error occurred near line 1, position 10: BOLA: asd");
blogc_error_free(err);
- b_trie_free(source);
+ sb_trie_free(source);
}
@@ -464,7 +464,7 @@ test_source_parse_invalid_separator(void **state)
{
const char *a = "BOLA: asd\n---#";
blogc_error_t *err = NULL;
- b_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
@@ -472,7 +472,7 @@ test_source_parse_invalid_separator(void **state)
"Invalid content separator. Must be more than one '-' characters.\n"
"Error occurred near line 2, position 4: ---#");
blogc_error_free(err);
- b_trie_free(source);
+ sb_trie_free(source);
}
diff --git a/tests/check_template_parser.c b/tests/check_template_parser.c
index b712f22..0e42976 100644
--- a/tests/check_template_parser.c
+++ b/tests/check_template_parser.c
@@ -17,11 +17,11 @@
#include <string.h>
#include "../src/template-parser.h"
#include "../src/error.h"
-#include "../src/utils/utils.h"
+#include <squareball.h>
static void
-blogc_assert_template_stmt(b_slist_t *l, const char *value,
+blogc_assert_template_stmt(sb_slist_t *l, const char *value,
const blogc_template_stmt_type_t type)
{
blogc_template_stmt_t *stmt = l->data;
@@ -34,7 +34,7 @@ blogc_assert_template_stmt(b_slist_t *l, const char *value,
static void
-blogc_assert_template_if_stmt(b_slist_t *l, const char *variable,
+blogc_assert_template_if_stmt(sb_slist_t *l, const char *variable,
blogc_template_stmt_operator_t operator, const char *operand)
{
blogc_template_stmt_t *stmt = l->data;
@@ -63,7 +63,7 @@ test_template_parse(void **state)
"{% block listing_once %}asd{% endblock %}\n"
"{% if BOLA == \"1\\\"0\" %}aee{% endif %}";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(stmts);
blogc_assert_template_stmt(stmts, "Test\n\n ",
@@ -80,7 +80,7 @@ test_template_parse(void **state)
BLOGC_TEMPLATE_ENDIF_STMT);
blogc_assert_template_stmt(stmts->next->next->next->next->next->next, "\n",
BLOGC_TEMPLATE_CONTENT_STMT);
- b_slist_t *tmp = stmts->next->next->next->next->next->next->next;
+ sb_slist_t *tmp = stmts->next->next->next->next->next->next->next;
blogc_assert_template_stmt(tmp, "BOLA", BLOGC_TEMPLATE_IFNDEF_STMT);
blogc_assert_template_stmt(tmp->next, "\nbolao\n", BLOGC_TEMPLATE_CONTENT_STMT);
blogc_assert_template_stmt(tmp->next->next, NULL, BLOGC_TEMPLATE_ENDIF_STMT);
@@ -133,7 +133,7 @@ test_template_parse_crlf(void **state)
"{% block listing_once %}asd{% endblock %}\r\n"
"{% if BOLA == \"1\\\"0\" %}aee{% endif %}";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(stmts);
blogc_assert_template_stmt(stmts, "Test\r\n\r\n ",
@@ -150,7 +150,7 @@ test_template_parse_crlf(void **state)
BLOGC_TEMPLATE_ENDIF_STMT);
blogc_assert_template_stmt(stmts->next->next->next->next->next->next, "\r\n",
BLOGC_TEMPLATE_CONTENT_STMT);
- b_slist_t *tmp = stmts->next->next->next->next->next->next->next;
+ sb_slist_t *tmp = stmts->next->next->next->next->next->next->next;
blogc_assert_template_stmt(tmp, "BOLA", BLOGC_TEMPLATE_IFNDEF_STMT);
blogc_assert_template_stmt(tmp->next, "\r\nbolao\r\n", BLOGC_TEMPLATE_CONTENT_STMT);
blogc_assert_template_stmt(tmp->next->next, NULL, BLOGC_TEMPLATE_ENDIF_STMT);
@@ -212,7 +212,7 @@ test_template_parse_html(void **state)
" </body>\n"
"</html>\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(stmts);
blogc_assert_template_stmt(stmts, "<html>\n <head>\n ",
@@ -231,7 +231,7 @@ test_template_parse_html(void **state)
"\n ", BLOGC_TEMPLATE_CONTENT_STMT);
blogc_assert_template_stmt(stmts->next->next->next->next->next->next->next,
"listing_once", BLOGC_TEMPLATE_BLOCK_STMT);
- b_slist_t *tmp = stmts->next->next->next->next->next->next->next->next;
+ sb_slist_t *tmp = stmts->next->next->next->next->next->next->next->next;
blogc_assert_template_stmt(tmp,
"\n <title>My cool blog - Main page</title>\n ",
BLOGC_TEMPLATE_CONTENT_STMT);
@@ -322,7 +322,7 @@ test_template_parse_ifdef_and_var_outside_block(void **state)
"{{ BOLA }}\n"
"{% ifndef CHUNDA %}{{ CHUNDA }}{% endif %}\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(stmts);
blogc_assert_template_stmt(stmts, "GUDA", BLOGC_TEMPLATE_IFDEF_STMT);
@@ -338,7 +338,7 @@ test_template_parse_ifdef_and_var_outside_block(void **state)
BLOGC_TEMPLATE_CONTENT_STMT);
blogc_assert_template_stmt(stmts->next->next->next->next->next->next,
"CHUNDA", BLOGC_TEMPLATE_IFNDEF_STMT);
- b_slist_t *tmp = stmts->next->next->next->next->next->next->next;
+ sb_slist_t *tmp = stmts->next->next->next->next->next->next->next;
blogc_assert_template_stmt(tmp, "CHUNDA", BLOGC_TEMPLATE_VARIABLE_STMT);
blogc_assert_template_stmt(tmp->next, NULL, BLOGC_TEMPLATE_ENDIF_STMT);
blogc_assert_template_stmt(tmp->next->next, "\n",
@@ -353,7 +353,7 @@ test_template_parse_invalid_block_start(void **state)
{
const char *a = "{% ASD %}\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(stmts);
assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
@@ -371,7 +371,7 @@ test_template_parse_invalid_block_nested(void **state)
"{% block entry %}\n"
"{% block listing %}\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(stmts);
assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
@@ -387,7 +387,7 @@ test_template_parse_invalid_block_not_open(void **state)
{
const char *a = "{% endblock %}\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(stmts);
assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
@@ -403,7 +403,7 @@ test_template_parse_invalid_endif_not_open(void **state)
{
const char *a = "{% block listing %}{% endif %}{% endblock %}\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(stmts);
assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
@@ -420,7 +420,7 @@ test_template_parse_invalid_block_name(void **state)
{
const char *a = "{% chunda %}\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(stmts);
assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
@@ -437,7 +437,7 @@ test_template_parse_invalid_block_type_start(void **state)
{
const char *a = "{% block ENTRY %}\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(stmts);
assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
@@ -453,7 +453,7 @@ test_template_parse_invalid_block_type(void **state)
{
const char *a = "{% block chunda %}\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(stmts);
assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
@@ -469,7 +469,7 @@ test_template_parse_invalid_ifdef_start(void **state)
{
const char *a = "{% block entry %}{% ifdef guda %}\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(stmts);
assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
@@ -486,7 +486,7 @@ test_template_parse_invalid_ifdef_variable(void **state)
{
const char *a = "{% block entry %}{% ifdef BoLA %}\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(stmts);
assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
@@ -503,7 +503,7 @@ test_template_parse_invalid_if_operator(void **state)
{
const char *a = "{% block entry %}{% if BOLA = \"asd\" %}\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(stmts);
assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
@@ -520,7 +520,7 @@ test_template_parse_invalid_if_operand(void **state)
{
const char *a = "{% block entry %}{% if BOLA == asd %}\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(stmts);
assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
@@ -537,7 +537,7 @@ test_template_parse_invalid_if_operand2(void **state)
{
const char *a = "{% block entry %}{% if BOLA == \"asd %}\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(stmts);
assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
@@ -554,7 +554,7 @@ test_template_parse_invalid_block_end(void **state)
{
const char *a = "{% block entry }}\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(stmts);
assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
@@ -570,7 +570,7 @@ test_template_parse_invalid_variable_name(void **state)
{
const char *a = "{% block entry %}{{ bola }}{% endblock %}\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(stmts);
assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
@@ -587,7 +587,7 @@ test_template_parse_invalid_variable_name2(void **state)
{
const char *a = "{% block entry %}{{ Bola }}{% endblock %}\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(stmts);
assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
@@ -604,7 +604,7 @@ test_template_parse_invalid_variable_end(void **state)
{
const char *a = "{% block entry %}{{ BOLA %}{% endblock %}\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(stmts);
assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
@@ -621,7 +621,7 @@ test_template_parse_invalid_close(void **state)
{
const char *a = "{% block entry %%\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(stmts);
assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
@@ -637,7 +637,7 @@ test_template_parse_invalid_close2(void **state)
{
const char *a = "{% block entry %}{{ BOLA }%{% endblock %}\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(stmts);
assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
@@ -654,7 +654,7 @@ test_template_parse_invalid_if_not_closed(void **state)
{
const char *a = "{% block entry %}{% ifdef BOLA %}{% endblock %}\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(stmts);
assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
@@ -669,7 +669,7 @@ test_template_parse_invalid_block_not_closed(void **state)
{
const char *a = "{% block entry %}\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(stmts);
assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
diff --git a/tests/check_utils.c b/tests/check_utils.c
deleted file mode 100644
index a42c75a..0000000
--- a/tests/check_utils.c
+++ /dev/null
@@ -1,824 +0,0 @@
-/*
- * blogc: A blog compiler.
- * Copyright (C) 2014-2015 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 <stdlib.h>
-
-#include "../src/utils/utils.h"
-
-
-static void
-test_slist_append(void **state)
-{
- b_slist_t *l = NULL;
- l = b_slist_append(l, (void*) b_strdup("bola"));
- assert_non_null(l);
- assert_string_equal(l->data, "bola");
- assert_null(l->next);
- l = b_slist_append(l, (void*) b_strdup("guda"));
- assert_non_null(l);
- assert_string_equal(l->data, "bola");
- assert_non_null(l->next);
- assert_string_equal(l->next->data, "guda");
- assert_null(l->next->next);
- b_slist_free_full(l, free);
-}
-
-
-static void
-test_slist_free(void **state)
-{
- b_slist_t *l = NULL;
- char *t1 = b_strdup("bola");
- char *t2 = b_strdup("guda");
- char *t3 = b_strdup("chunda");
- l = b_slist_append(l, (void*) t1);
- l = b_slist_append(l, (void*) t2);
- l = b_slist_append(l, (void*) t3);
- b_slist_free(l);
- assert_string_equal(t1, "bola");
- assert_string_equal(t2, "guda");
- assert_string_equal(t3, "chunda");
- free(t1);
- free(t2);
- free(t3);
-}
-
-
-static void
-test_slist_length(void **state)
-{
- b_slist_t *l = NULL;
- l = b_slist_append(l, (void*) b_strdup("bola"));
- l = b_slist_append(l, (void*) b_strdup("guda"));
- l = b_slist_append(l, (void*) b_strdup("chunda"));
- assert_int_equal(b_slist_length(l), 3);
- b_slist_free_full(l, free);
-}
-
-
-static void
-test_strdup(void **state)
-{
- char *str = b_strdup("bola");
- assert_string_equal(str, "bola");
- free(str);
- str = b_strdup(NULL);
- assert_null(str);
-}
-
-
-static void
-test_strndup(void **state)
-{
- char *str = b_strndup("bolaguda", 4);
- assert_string_equal(str, "bola");
- free(str);
- str = b_strndup("bolaguda", 30);
- assert_string_equal(str, "bolaguda");
- free(str);
- str = b_strndup("bolaguda", 8);
- assert_string_equal(str, "bolaguda");
- free(str);
- str = b_strdup(NULL);
- assert_null(str);
-}
-
-
-static void
-test_strdup_printf(void **state)
-{
- char *str = b_strdup_printf("bola");
- assert_string_equal(str, "bola");
- free(str);
- str = b_strdup_printf("bola, %s", "guda");
- assert_string_equal(str, "bola, guda");
- free(str);
-}
-
-
-static void
-test_str_starts_with(void **state)
-{
- assert_true(b_str_starts_with("bolaguda", "bola"));
- assert_true(b_str_starts_with("bola", "bola"));
- assert_false(b_str_starts_with("gudabola", "bola"));
- assert_false(b_str_starts_with("guda", "bola"));
- assert_false(b_str_starts_with("bola", "bolaguda"));
-}
-
-
-static void
-test_str_ends_with(void **state)
-{
- assert_true(b_str_ends_with("bolaguda", "guda"));
- assert_true(b_str_ends_with("bola", "bola"));
- assert_false(b_str_ends_with("gudabola", "guda"));
- assert_false(b_str_ends_with("guda", "bola"));
- assert_false(b_str_ends_with("bola", "gudabola"));
-}
-
-
-static void
-test_str_strip(void **state)
-{
- char *str = b_strdup(" \tbola\n \t");
- assert_string_equal(b_str_strip(str), "bola");
- free(str);
- str = b_strdup("guda");
- assert_string_equal(b_str_strip(str), "guda");
- free(str);
- assert_null(b_str_strip(NULL));
-}
-
-
-static void
-test_str_split(void **state)
-{
- char **strv = b_str_split("bola:guda:chunda", ':', 0);
- assert_string_equal(strv[0], "bola");
- assert_string_equal(strv[1], "guda");
- assert_string_equal(strv[2], "chunda");
- assert_null(strv[3]);
- b_strv_free(strv);
- strv = b_str_split("bola:guda:chunda", ':', 2);
- assert_string_equal(strv[0], "bola");
- assert_string_equal(strv[1], "guda:chunda");
- assert_null(strv[2]);
- b_strv_free(strv);
- strv = b_str_split("bola:guda:chunda", ':', 1);
- assert_string_equal(strv[0], "bola:guda:chunda");
- assert_null(strv[1]);
- b_strv_free(strv);
- strv = b_str_split("", ':', 1);
- assert_null(strv[0]);
- b_strv_free(strv);
- assert_null(b_str_split(NULL, ':', 0));
-}
-
-
-static void
-test_str_replace(void **state)
-{
- char *str = b_str_replace("bolao", 'o', "zaz");
- assert_string_equal(str, "bzazlazaz");
- free(str);
- str = b_str_replace("bolao", 'b', "zaz");
- assert_string_equal(str, "zazolao");
- free(str);
-}
-
-
-static void
-test_strv_join(void **state)
-{
- const char *pieces[] = {"guda","bola", "chunda", NULL};
- char *str = b_strv_join(pieces, ":");
- assert_string_equal(str, "guda:bola:chunda");
- free(str);
- const char *pieces2[] = {NULL};
- str = b_strv_join(pieces2, ":");
- assert_string_equal(str, "");
- free(str);
- assert_null(b_strv_join(NULL, ":"));
-}
-
-
-static void
-test_strv_length(void **state)
-{
- char *pieces[] = {"guda","bola", "chunda", NULL};
- assert_int_equal(b_strv_length(pieces), 3);
- char *pieces2[] = {NULL};
- assert_int_equal(b_strv_length(pieces2), 0);
- assert_int_equal(b_strv_length(NULL), 0);
-}
-
-
-static void
-test_string_new(void **state)
-{
- b_string_t *str = b_string_new();
- assert_non_null(str);
- assert_string_equal(str->str, "");
- assert_int_equal(str->len, 0);
- assert_int_equal(str->allocated_len, B_STRING_CHUNK_SIZE);
- assert_null(b_string_free(str, true));
-}
-
-
-static void
-test_string_free(void **state)
-{
- b_string_t *str = b_string_new();
- free(str->str);
- str->str = b_strdup("bola");
- str->len = 4;
- str->allocated_len = B_STRING_CHUNK_SIZE;
- char *tmp = b_string_free(str, false);
- assert_string_equal(tmp, "bola");
- free(tmp);
-}
-
-
-static void
-test_string_append_len(void **state)
-{
- b_string_t *str = b_string_new();
- str = b_string_append_len(str, "guda", 4);
- assert_non_null(str);
- assert_string_equal(str->str, "guda");
- assert_int_equal(str->len, 4);
- assert_int_equal(str->allocated_len, B_STRING_CHUNK_SIZE);
- assert_null(b_string_free(str, true));
- str = b_string_new();
- str = b_string_append_len(str, "guda", 4);
- str = b_string_append_len(str, "bola", 4);
- assert_non_null(str);
- assert_string_equal(str->str, "gudabola");
- assert_int_equal(str->len, 8);
- assert_int_equal(str->allocated_len, B_STRING_CHUNK_SIZE);
- assert_null(b_string_free(str, true));
- str = b_string_new();
- str = b_string_append_len(str, "guda", 3);
- str = b_string_append_len(str, "bola", 4);
- assert_non_null(str);
- assert_string_equal(str->str, "gudbola");
- assert_int_equal(str->len, 7);
- assert_int_equal(str->allocated_len, B_STRING_CHUNK_SIZE);
- assert_null(b_string_free(str, true));
- str = b_string_new();
- str = b_string_append_len(str, "guda", 4);
- str = b_string_append_len(str,
- "cwlwmwxxmvjnwtidmjehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjidzkcw"
- "nnqhxhneolbwqlctcxmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtaxjiwa"
- "xfhfyzymtffusoqywaruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqvevaz"
- "dxrewtgapkompnviiyielanoyowgqhssntyvcvqqtfjmkphywbkvzfyttaalttywhqcec"
- "hgrwzaglzogwjvqncjzodaqsblcbpcdpxmrtctzginvtkckhqvdplgjvbzrnarcxjrsbc"
- "sbfvpylgjznsuhxcxoqbpxowmsrgwimxjgyzwwmryqvstwzkglgeezelvpvkwefqdatnd"
- "dxntikgoqlidfnmdhxzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvwsrnr"
- "ftzfeyasjpxoevyptpdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsfnwtg"
- "okxhegoifakimxbbafkeannglvsxprqzfekdinssqymtfexf", 600);
- str = b_string_append_len(str, NULL, 0);
- str = b_string_append_len(str,
- "cwlwmwxxmvjnwtidmjehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjidzkcw"
- "nnqhxhneolbwqlctcxmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtaxjiwa"
- "xfhfyzymtffusoqywaruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqvevaz"
- "dxrewtgapkompnviiyielanoyowgqhssntyvcvqqtfjmkphywbkvzfyttaalttywhqcec"
- "hgrwzaglzogwjvqncjzodaqsblcbpcdpxmrtctzginvtkckhqvdplgjvbzrnarcxjrsbc"
- "sbfvpylgjznsuhxcxoqbpxowmsrgwimxjgyzwwmryqvstwzkglgeezelvpvkwefqdatnd"
- "dxntikgoqlidfnmdhxzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvwsrnr"
- "ftzfeyasjpxoevyptpdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsfnwtg"
- "okxhegoifakimxbbafkeannglvsxprqzfekdinssqymtfexf", 600);
- assert_non_null(str);
- assert_string_equal(str->str,
- "gudacwlwmwxxmvjnwtidmjehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjid"
- "zkcwnnqhxhneolbwqlctcxmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtax"
- "jiwaxfhfyzymtffusoqywaruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqv"
- "evazdxrewtgapkompnviiyielanoyowgqhssntyvcvqqtfjmkphywbkvzfyttaalttywh"
- "qcechgrwzaglzogwjvqncjzodaqsblcbpcdpxmrtctzginvtkckhqvdplgjvbzrnarcxj"
- "rsbcsbfvpylgjznsuhxcxoqbpxowmsrgwimxjgyzwwmryqvstwzkglgeezelvpvkwefqd"
- "atnddxntikgoqlidfnmdhxzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvw"
- "srnrftzfeyasjpxoevyptpdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsf"
- "nwtgokxhegoifakimxbbafkeannglvsxprqzfekdinssqymtfexfcwlwmwxxmvjnwtidm"
- "jehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjidzkcwnnqhxhneolbwqlctc"
- "xmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtaxjiwaxfhfyzymtffusoqyw"
- "aruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqvevazdxrewtgapkompnvii"
- "yielanoyowgqhssntyvcvqqtfjmkphywbkvzfyttaalttywhqcechgrwzaglzogwjvqnc"
- "jzodaqsblcbpcdpxmrtctzginvtkckhqvdplgjvbzrnarcxjrsbcsbfvpylgjznsuhxcx"
- "oqbpxowmsrgwimxjgyzwwmryqvstwzkglgeezelvpvkwefqdatnddxntikgoqlidfnmdh"
- "xzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvwsrnrftzfeyasjpxoevypt"
- "pdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsfnwtgokxhegoifakimxbba"
- "fkeannglvsxprqzfekdinssqymtfexf");
- assert_int_equal(str->len, 1204);
- assert_int_equal(str->allocated_len, B_STRING_CHUNK_SIZE * 10);
- assert_null(b_string_free(str, true));
-}
-
-
-static void
-test_string_append(void **state)
-{
- b_string_t *str = b_string_new();
- str = b_string_append(str, "guda");
- assert_non_null(str);
- assert_string_equal(str->str, "guda");
- assert_int_equal(str->len, 4);
- assert_int_equal(str->allocated_len, B_STRING_CHUNK_SIZE);
- assert_null(b_string_free(str, true));
- str = b_string_new();
- str = b_string_append(str, "guda");
- str = b_string_append(str, "bola");
- assert_non_null(str);
- assert_string_equal(str->str, "gudabola");
- assert_int_equal(str->len, 8);
- assert_int_equal(str->allocated_len, B_STRING_CHUNK_SIZE);
- assert_null(b_string_free(str, true));
- str = b_string_new();
- str = b_string_append(str, "guda");
- str = b_string_append(str,
- "cwlwmwxxmvjnwtidmjehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjidzkcw"
- "nnqhxhneolbwqlctcxmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtaxjiwa"
- "xfhfyzymtffusoqywaruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqvevaz"
- "dxrewtgapkompnviiyielanoyowgqhssntyvcvqqtfjmkphywbkvzfyttaalttywhqcec"
- "hgrwzaglzogwjvqncjzodaqsblcbpcdpxmrtctzginvtkckhqvdplgjvbzrnarcxjrsbc"
- "sbfvpylgjznsuhxcxoqbpxowmsrgwimxjgyzwwmryqvstwzkglgeezelvpvkwefqdatnd"
- "dxntikgoqlidfnmdhxzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvwsrnr"
- "ftzfeyasjpxoevyptpdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsfnwtg"
- "okxhegoifakimxbbafkeannglvsxprqzfekdinssqymtfexf");
- str = b_string_append(str, NULL);
- str = b_string_append(str,
- "cwlwmwxxmvjnwtidmjehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjidzkcw"
- "nnqhxhneolbwqlctcxmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtaxjiwa"
- "xfhfyzymtffusoqywaruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqvevaz"
- "dxrewtgapkompnviiyielanoyowgqhssntyvcvqqtfjmkphywbkvzfyttaalttywhqcec"
- "hgrwzaglzogwjvqncjzodaqsblcbpcdpxmrtctzginvtkckhqvdplgjvbzrnarcxjrsbc"
- "sbfvpylgjznsuhxcxoqbpxowmsrgwimxjgyzwwmryqvstwzkglgeezelvpvkwefqdatnd"
- "dxntikgoqlidfnmdhxzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvwsrnr"
- "ftzfeyasjpxoevyptpdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsfnwtg"
- "okxhegoifakimxbbafkeannglvsxprqzfekdinssqymtfexf");
- assert_non_null(str);
- assert_string_equal(str->str,
- "gudacwlwmwxxmvjnwtidmjehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjid"
- "zkcwnnqhxhneolbwqlctcxmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtax"
- "jiwaxfhfyzymtffusoqywaruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqv"
- "evazdxrewtgapkompnviiyielanoyowgqhssntyvcvqqtfjmkphywbkvzfyttaalttywh"
- "qcechgrwzaglzogwjvqncjzodaqsblcbpcdpxmrtctzginvtkckhqvdplgjvbzrnarcxj"
- "rsbcsbfvpylgjznsuhxcxoqbpxowmsrgwimxjgyzwwmryqvstwzkglgeezelvpvkwefqd"
- "atnddxntikgoqlidfnmdhxzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvw"
- "srnrftzfeyasjpxoevyptpdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsf"
- "nwtgokxhegoifakimxbbafkeannglvsxprqzfekdinssqymtfexfcwlwmwxxmvjnwtidm"
- "jehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjidzkcwnnqhxhneolbwqlctc"
- "xmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtaxjiwaxfhfyzymtffusoqyw"
- "aruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqvevazdxrewtgapkompnvii"
- "yielanoyowgqhssntyvcvqqtfjmkphywbkvzfyttaalttywhqcechgrwzaglzogwjvqnc"
- "jzodaqsblcbpcdpxmrtctzginvtkckhqvdplgjvbzrnarcxjrsbcsbfvpylgjznsuhxcx"
- "oqbpxowmsrgwimxjgyzwwmryqvstwzkglgeezelvpvkwefqdatnddxntikgoqlidfnmdh"
- "xzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvwsrnrftzfeyasjpxoevypt"
- "pdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsfnwtgokxhegoifakimxbba"
- "fkeannglvsxprqzfekdinssqymtfexf");
- assert_int_equal(str->len, 1204);
- assert_int_equal(str->allocated_len, B_STRING_CHUNK_SIZE * 10);
- assert_null(b_string_free(str, true));
-}
-
-
-static void
-test_string_append_c(void **state)
-{
- b_string_t *str = b_string_new();
- str = b_string_append_len(str, "guda", 4);
- for (int i = 0; i < 600; i++)
- str = b_string_append_c(str, 'c');
- assert_non_null(str);
- assert_string_equal(str->str,
- "gudaccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"
- "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"
- "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"
- "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"
- "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"
- "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"
- "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"
- "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"
- "cccccccccccccccccccccccccccccccccccccccccccccccccccc");
- assert_int_equal(str->len, 604);
- assert_int_equal(str->allocated_len, B_STRING_CHUNK_SIZE * 5);
- assert_null(b_string_free(str, true));
-}
-
-
-static void
-test_string_append_printf(void **state)
-{
- b_string_t *str = b_string_new();
- str = b_string_append_printf(str, "guda: %s %d", "bola", 1);
- assert_non_null(str);
- assert_string_equal(str->str, "guda: bola 1");
- assert_int_equal(str->len, 12);
- assert_int_equal(str->allocated_len, B_STRING_CHUNK_SIZE);
- assert_null(b_string_free(str, true));
-}
-
-
-static void
-test_trie_new(void **state)
-{
- b_trie_t *trie = b_trie_new(free);
- assert_non_null(trie);
- assert_null(trie->root);
- assert_true(trie->free_func == free);
- b_trie_free(trie);
-}
-
-
-static void
-test_trie_insert(void **state)
-{
- b_trie_t *trie = b_trie_new(free);
-
- b_trie_insert(trie, "bola", b_strdup("guda"));
- assert_true(trie->root->key == 'b');
- assert_null(trie->root->data);
- assert_true(trie->root->child->key == 'o');
- assert_null(trie->root->child->data);
- assert_true(trie->root->child->child->key == 'l');
- assert_null(trie->root->child->child->data);
- assert_true(trie->root->child->child->child->key == 'a');
- assert_null(trie->root->child->child->child->data);
- assert_true(trie->root->child->child->child->child->key == '\0');
- assert_string_equal(trie->root->child->child->child->child->data, "guda");
-
-
- b_trie_insert(trie, "chu", b_strdup("nda"));
- assert_true(trie->root->key == 'b');
- assert_null(trie->root->data);
- assert_true(trie->root->child->key == 'o');
- assert_null(trie->root->child->data);
- assert_true(trie->root->child->child->key == 'l');
- assert_null(trie->root->child->child->data);
- assert_true(trie->root->child->child->child->key == 'a');
- assert_null(trie->root->child->child->child->data);
- assert_true(trie->root->child->child->child->child->key == '\0');
- assert_string_equal(trie->root->child->child->child->child->data, "guda");
-
- assert_true(trie->root->next->key == 'c');
- assert_null(trie->root->next->data);
- assert_true(trie->root->next->child->key == 'h');
- assert_null(trie->root->next->child->data);
- assert_true(trie->root->next->child->child->key == 'u');
- assert_null(trie->root->next->child->child->data);
- assert_true(trie->root->next->child->child->child->key == '\0');
- assert_string_equal(trie->root->next->child->child->child->data, "nda");
-
-
- b_trie_insert(trie, "bote", b_strdup("aba"));
- assert_true(trie->root->key == 'b');
- assert_null(trie->root->data);
- assert_true(trie->root->child->key == 'o');
- assert_null(trie->root->child->data);
- assert_true(trie->root->child->child->key == 'l');
- assert_null(trie->root->child->child->data);
- assert_true(trie->root->child->child->child->key == 'a');
- assert_null(trie->root->child->child->child->data);
- assert_true(trie->root->child->child->child->child->key == '\0');
- assert_string_equal(trie->root->child->child->child->child->data, "guda");
-
- assert_true(trie->root->next->key == 'c');
- assert_null(trie->root->next->data);
- assert_true(trie->root->next->child->key == 'h');
- assert_null(trie->root->next->child->data);
- assert_true(trie->root->next->child->child->key == 'u');
- assert_null(trie->root->next->child->child->data);
- assert_true(trie->root->next->child->child->child->key == '\0');
- assert_string_equal(trie->root->next->child->child->child->data, "nda");
-
- assert_true(trie->root->child->child->next->key == 't');
- assert_null(trie->root->child->child->next->data);
- assert_true(trie->root->child->child->next->child->key == 'e');
- assert_null(trie->root->child->child->next->child->data);
- assert_true(trie->root->child->child->next->child->child->key == '\0');
- assert_string_equal(trie->root->child->child->next->child->child->data, "aba");
-
-
- b_trie_insert(trie, "bo", b_strdup("haha"));
- assert_true(trie->root->key == 'b');
- assert_null(trie->root->data);
- assert_true(trie->root->child->key == 'o');
- assert_null(trie->root->child->data);
- assert_true(trie->root->child->child->key == 'l');
- assert_null(trie->root->child->child->data);
- assert_true(trie->root->child->child->child->key == 'a');
- assert_null(trie->root->child->child->child->data);
- assert_true(trie->root->child->child->child->child->key == '\0');
- assert_string_equal(trie->root->child->child->child->child->data, "guda");
-
- assert_true(trie->root->next->key == 'c');
- assert_null(trie->root->next->data);
- assert_true(trie->root->next->child->key == 'h');
- assert_null(trie->root->next->child->data);
- assert_true(trie->root->next->child->child->key == 'u');
- assert_null(trie->root->next->child->child->data);
- assert_true(trie->root->next->child->child->child->key == '\0');
- assert_string_equal(trie->root->next->child->child->child->data, "nda");
-
- assert_true(trie->root->child->child->next->key == 't');
- assert_null(trie->root->child->child->next->data);
- assert_true(trie->root->child->child->next->child->key == 'e');
- assert_null(trie->root->child->child->next->child->data);
- assert_true(trie->root->child->child->next->child->child->key == '\0');
- assert_string_equal(trie->root->child->child->next->child->child->data, "aba");
-
- assert_true(trie->root->child->child->next->next->key == '\0');
- assert_string_equal(trie->root->child->child->next->next->data, "haha");
-
- b_trie_free(trie);
-
-
- trie = b_trie_new(free);
-
- b_trie_insert(trie, "chu", b_strdup("nda"));
- assert_true(trie->root->key == 'c');
- assert_null(trie->root->data);
- assert_true(trie->root->child->key == 'h');
- assert_null(trie->root->child->data);
- assert_true(trie->root->child->child->key == 'u');
- assert_null(trie->root->child->child->data);
- assert_true(trie->root->child->child->child->key == '\0');
- assert_string_equal(trie->root->child->child->child->data, "nda");
-
-
- b_trie_insert(trie, "bola", b_strdup("guda"));
- assert_true(trie->root->key == 'c');
- assert_null(trie->root->data);
- assert_true(trie->root->child->key == 'h');
- assert_null(trie->root->child->data);
- assert_true(trie->root->child->child->key == 'u');
- assert_null(trie->root->child->child->data);
- assert_true(trie->root->child->child->child->key == '\0');
- assert_string_equal(trie->root->child->child->child->data, "nda");
-
- assert_true(trie->root->next->key == 'b');
- assert_null(trie->root->next->data);
- assert_true(trie->root->next->child->key == 'o');
- assert_null(trie->root->next->child->data);
- assert_true(trie->root->next->child->child->key == 'l');
- assert_null(trie->root->next->child->child->data);
- assert_true(trie->root->next->child->child->child->key == 'a');
- assert_null(trie->root->next->child->child->child->data);
- assert_true(trie->root->next->child->child->child->child->key == '\0');
- assert_string_equal(trie->root->next->child->child->child->child->data, "guda");
-
-
- b_trie_insert(trie, "bote", b_strdup("aba"));
- assert_true(trie->root->key == 'c');
- assert_null(trie->root->data);
- assert_true(trie->root->child->key == 'h');
- assert_null(trie->root->child->data);
- assert_true(trie->root->child->child->key == 'u');
- assert_null(trie->root->child->child->data);
- assert_true(trie->root->child->child->child->key == '\0');
- assert_string_equal(trie->root->child->child->child->data, "nda");
-
- assert_true(trie->root->next->key == 'b');
- assert_null(trie->root->next->data);
- assert_true(trie->root->next->child->key == 'o');
- assert_null(trie->root->next->child->data);
- assert_true(trie->root->next->child->child->key == 'l');
- assert_null(trie->root->next->child->child->data);
- assert_true(trie->root->next->child->child->child->key == 'a');
- assert_null(trie->root->next->child->child->child->data);
- assert_true(trie->root->next->child->child->child->child->key == '\0');
- assert_string_equal(trie->root->next->child->child->child->child->data, "guda");
-
- assert_true(trie->root->next->child->child->next->key == 't');
- assert_null(trie->root->next->child->child->next->data);
- assert_true(trie->root->next->child->child->next->child->key == 'e');
- assert_null(trie->root->next->child->child->next->child->data);
- assert_true(trie->root->next->child->child->next->child->child->key == '\0');
- assert_string_equal(trie->root->next->child->child->next->child->child->data, "aba");
-
-
- b_trie_insert(trie, "bo", b_strdup("haha"));
- assert_true(trie->root->key == 'c');
- assert_null(trie->root->data);
- assert_true(trie->root->child->key == 'h');
- assert_null(trie->root->child->data);
- assert_true(trie->root->child->child->key == 'u');
- assert_null(trie->root->child->child->data);
- assert_true(trie->root->child->child->child->key == '\0');
- assert_string_equal(trie->root->child->child->child->data, "nda");
-
- assert_true(trie->root->next->key == 'b');
- assert_null(trie->root->next->data);
- assert_true(trie->root->next->child->key == 'o');
- assert_null(trie->root->next->child->data);
- assert_true(trie->root->next->child->child->key == 'l');
- assert_null(trie->root->next->child->child->data);
- assert_true(trie->root->next->child->child->child->key == 'a');
- assert_null(trie->root->next->child->child->child->data);
- assert_true(trie->root->next->child->child->child->child->key == '\0');
- assert_string_equal(trie->root->next->child->child->child->child->data, "guda");
-
- assert_true(trie->root->next->child->child->next->key == 't');
- assert_null(trie->root->next->child->child->next->data);
- assert_true(trie->root->next->child->child->next->child->key == 'e');
- assert_null(trie->root->next->child->child->next->child->data);
- assert_true(trie->root->next->child->child->next->child->child->key == '\0');
- assert_string_equal(trie->root->next->child->child->next->child->child->data, "aba");
-
- assert_true(trie->root->next->child->child->next->next->key == '\0');
- assert_string_equal(trie->root->next->child->child->next->next->data, "haha");
-
- b_trie_free(trie);
-}
-
-
-static void
-test_trie_insert_duplicated(void **state)
-{
- b_trie_t *trie = b_trie_new(free);
-
- b_trie_insert(trie, "bola", b_strdup("guda"));
- assert_true(trie->root->key == 'b');
- assert_null(trie->root->data);
- assert_true(trie->root->child->key == 'o');
- assert_null(trie->root->child->data);
- assert_true(trie->root->child->child->key == 'l');
- assert_null(trie->root->child->child->data);
- assert_true(trie->root->child->child->child->key == 'a');
- assert_null(trie->root->child->child->child->data);
- assert_true(trie->root->child->child->child->child->key == '\0');
- assert_string_equal(trie->root->child->child->child->child->data, "guda");
-
- b_trie_insert(trie, "bola", b_strdup("asdf"));
- assert_true(trie->root->key == 'b');
- assert_null(trie->root->data);
- assert_true(trie->root->child->key == 'o');
- assert_null(trie->root->child->data);
- assert_true(trie->root->child->child->key == 'l');
- assert_null(trie->root->child->child->data);
- assert_true(trie->root->child->child->child->key == 'a');
- assert_null(trie->root->child->child->child->data);
- assert_true(trie->root->child->child->child->child->key == '\0');
- assert_string_equal(trie->root->child->child->child->child->data, "asdf");
-
- b_trie_free(trie);
-}
-
-
-static void
-test_trie_keep_data(void **state)
-{
- b_trie_t *trie = b_trie_new(NULL);
-
- char *t1 = "guda";
- char *t2 = "nda";
- char *t3 = "aba";
- char *t4 = "haha";
-
- b_trie_insert(trie, "bola", t1);
- b_trie_insert(trie, "chu", t2);
- b_trie_insert(trie, "bote", t3);
- b_trie_insert(trie, "bo", t4);
-
- b_trie_free(trie);
-
- assert_string_equal(t1, "guda");
- assert_string_equal(t2, "nda");
- assert_string_equal(t3, "aba");
- assert_string_equal(t4, "haha");
-}
-
-
-static void
-test_trie_lookup(void **state)
-{
- b_trie_t *trie = b_trie_new(free);
-
- b_trie_insert(trie, "bola", b_strdup("guda"));
- b_trie_insert(trie, "chu", b_strdup("nda"));
- b_trie_insert(trie, "bote", b_strdup("aba"));
- b_trie_insert(trie, "bo", b_strdup("haha"));
-
- assert_string_equal(b_trie_lookup(trie, "bola"), "guda");
- assert_string_equal(b_trie_lookup(trie, "chu"), "nda");
- assert_string_equal(b_trie_lookup(trie, "bote"), "aba");
- assert_string_equal(b_trie_lookup(trie, "bo"), "haha");
-
- assert_null(b_trie_lookup(trie, "arcoiro"));
-
- b_trie_free(trie);
-
- trie = b_trie_new(free);
-
- b_trie_insert(trie, "chu", b_strdup("nda"));
- b_trie_insert(trie, "bola", b_strdup("guda"));
- b_trie_insert(trie, "bote", b_strdup("aba"));
- b_trie_insert(trie, "bo", b_strdup("haha"));
- b_trie_insert(trie, "copa", b_strdup("bu"));
- b_trie_insert(trie, "b", b_strdup("c"));
- b_trie_insert(trie, "test", b_strdup("asd"));
-
- assert_string_equal(b_trie_lookup(trie, "bola"), "guda");
- assert_string_equal(b_trie_lookup(trie, "chu"), "nda");
- assert_string_equal(b_trie_lookup(trie, "bote"), "aba");
- assert_string_equal(b_trie_lookup(trie, "bo"), "haha");
-
- assert_null(b_trie_lookup(trie, "arcoiro"));
-
- b_trie_free(trie);
-}
-
-
-static void
-test_trie_size(void **state)
-{
- b_trie_t *trie = b_trie_new(free);
-
- b_trie_insert(trie, "bola", b_strdup("guda"));
- b_trie_insert(trie, "chu", b_strdup("nda"));
- b_trie_insert(trie, "bote", b_strdup("aba"));
- b_trie_insert(trie, "bo", b_strdup("haha"));
-
- assert_int_equal(b_trie_size(trie), 4);
- assert_int_equal(b_trie_size(NULL), 0);
-
- b_trie_free(trie);
-
- trie = b_trie_new(free);
-
- b_trie_insert(trie, "chu", b_strdup("nda"));
- b_trie_insert(trie, "bola", b_strdup("guda"));
- b_trie_insert(trie, "bote", b_strdup("aba"));
- b_trie_insert(trie, "bo", b_strdup("haha"));
- b_trie_insert(trie, "copa", b_strdup("bu"));
- b_trie_insert(trie, "b", b_strdup("c"));
- b_trie_insert(trie, "test", b_strdup("asd"));
-
- assert_int_equal(b_trie_size(trie), 7);
- assert_int_equal(b_trie_size(NULL), 0);
-
- b_trie_free(trie);
-}
-
-
-static unsigned int counter;
-static char *expected_keys[] = {"chu", "copa", "bola", "bote", "bo", "b", "test"};
-static char *expected_datas[] = {"nda", "bu", "guda", "aba", "haha", "c", "asd"};
-
-static void
-mock_foreach(const char *key, void *data)
-{
- assert_string_equal(key, expected_keys[counter]);
- assert_string_equal((char*) data, expected_datas[counter++]);
-}
-
-
-static void
-test_trie_foreach(void **state)
-{
- b_trie_t *trie = b_trie_new(free);
-
- b_trie_insert(trie, "chu", b_strdup("nda"));
- b_trie_insert(trie, "bola", b_strdup("guda"));
- b_trie_insert(trie, "bote", b_strdup("aba"));
- b_trie_insert(trie, "bo", b_strdup("haha"));
- b_trie_insert(trie, "copa", b_strdup("bu"));
- b_trie_insert(trie, "b", b_strdup("c"));
- b_trie_insert(trie, "test", b_strdup("asd"));
-
- counter = 0;
- b_trie_foreach(trie, mock_foreach);
-
- b_trie_free(trie);
-}
-
-
-int
-main(void)
-{
- const UnitTest tests[] = {
-
- // slist
- unit_test(test_slist_append),
- unit_test(test_slist_free),
- unit_test(test_slist_length),
-
- // strings
- unit_test(test_strdup),
- unit_test(test_strndup),
- unit_test(test_strdup_printf),
- unit_test(test_str_starts_with),
- unit_test(test_str_ends_with),
- unit_test(test_str_strip),
- unit_test(test_str_split),
- unit_test(test_str_replace),
- unit_test(test_strv_join),
- unit_test(test_strv_length),
- unit_test(test_string_new),
- unit_test(test_string_free),
- unit_test(test_string_append_len),
- unit_test(test_string_append),
- unit_test(test_string_append_c),
- unit_test(test_string_append_printf),
-
- // trie
- unit_test(test_trie_new),
- unit_test(test_trie_insert),
- unit_test(test_trie_insert_duplicated),
- unit_test(test_trie_keep_data),
- unit_test(test_trie_lookup),
- unit_test(test_trie_size),
- unit_test(test_trie_foreach),
- };
- return run_tests(tests);
-}