diff --git a/.ic3_history b/.ic3_history
index 9cae032..adeaf15 100644
--- a/.ic3_history
+++ b/.ic3_history
@@ -31,3 +31,8 @@ to_list(%{a: 1, b: 2})
Map.to_list(%{a: 1, b: 2})
"\libc3/window/cairo/quartz/demo/c3_window_cairo_quartz_demo.app/Contents/img/flaps.png b/libc3/window/cairo/quartz/demo/c3_window_cairo_quartz_demo.app/Contents/img/flaps.png
"\U+1FAB0"
+1 + 10000000000000000000000000000
+Map.map
+Map.to_list
+%{name: "Quentin", id: 1000}
+make
diff --git a/c3s/buf_readline.c b/c3s/buf_readline.c
index 43ecae4..cb7edcc 100644
--- a/c3s/buf_readline.c
+++ b/c3s/buf_readline.c
@@ -17,30 +17,19 @@
#include <unistd.h>
#include "../libc3/c3.h"
-typedef struct buf_readline {
- s_buf buf;
-} s_buf_readline;
-
sw buf_readline_refill_fgets (s_buf *buf);
void buf_readline_close (s_buf *buf)
{
assert(buf);
buf->refill = NULL;
- free(buf->user_ptr);
buf->user_ptr = NULL;
}
s_buf * buf_readline_open_r (s_buf *buf)
{
- s_buf_readline *buf_readline;
assert(buf);
- buf_readline = malloc(sizeof(s_buf_readline));
- if (! buf_readline)
- errx(1, "buf_readline_open_r: out of memory");
- buf_init_1(&buf_readline->buf, "");
buf->refill = buf_readline_refill_fgets;
- buf->user_ptr = buf_readline;
return buf;
}
diff --git a/ic3/buf_linenoise.c b/ic3/buf_linenoise.c
index bb9251b..12d959b 100644
--- a/ic3/buf_linenoise.c
+++ b/ic3/buf_linenoise.c
@@ -46,9 +46,11 @@ s_buf * buf_linenoise_open_r (s_buf *buf, const s8 *prompt,
s_buf_linenoise *buf_linenoise;
assert(buf);
buf_linenoise = malloc(sizeof(s_buf_linenoise));
- if (! buf_linenoise)
- errx(1, "buf_linenoise_open_r: out of memory");
- buf_init_1(&buf_linenoise->buf, "");
+ if (! buf_linenoise) {
+ warn("buf_linenoise_open_r: malloc");
+ return NULL;
+ }
+ buf_init(&buf_linenoise->buf, false, 1, "");
buf_linenoise->eof = false;
if (isatty(STDIN_FILENO))
buf->refill = buf_linenoise_refill_linenoise;
diff --git a/libc3/array.c b/libc3/array.c
index bf15b5b..0d3e345 100644
--- a/libc3/array.c
+++ b/libc3/array.c
@@ -188,15 +188,13 @@ s_array * array_init_1 (s_array *array, s8 *p)
s_buf buf;
sw r;
s_array tmp;
- buf_init_1(&buf, p);
+ buf_init_1(&buf, false, p);
if ((r = buf_parse_array(&buf, &tmp)) != (sw) strlen(p)) {
warnx("array_init_1: buf_parse_array(%s) => %ld != %ld", p, r, strlen(p));
if (r > 0)
array_clean(&tmp);
- buf_clean(&buf);
return NULL;
}
- buf_clean(&buf);
if (! env_eval_array(&g_c3_env, &tmp, array)) {
warnx("array_init_1: env_eval_array");
array_clean(&tmp);
diff --git a/libc3/buf.c b/libc3/buf.c
index bf7526a..d767e12 100644
--- a/libc3/buf.c
+++ b/libc3/buf.c
@@ -23,8 +23,7 @@
void buf_clean (s_buf *buf)
{
assert(buf);
- if (buf->free)
- free(buf->ptr.p);
+ free(buf->ptr.p);
}
void buf_delete (s_buf *buf)
@@ -179,13 +178,13 @@ sw buf_ignore_spaces_but_newline (s_buf *buf)
return result;
}
-s_buf * buf_init (s_buf *buf, bool free, uw size, s8 *p)
+s_buf * buf_init (s_buf *buf, bool p_free, uw size, s8 *p)
{
assert(buf);
assert((!size || p) && (size || !p));
buf->column = 0;
buf->flush = NULL;
- buf->free = free;
+ buf->free = p_free;
buf->line = -1;
buf->ptr.ps8 = p;
buf->refill = NULL;
@@ -197,23 +196,21 @@ s_buf * buf_init (s_buf *buf, bool free, uw size, s8 *p)
return buf;
}
-s_buf * buf_init_str (s_buf *buf, const s_str *str)
+s_buf * buf_init_1 (s_buf *buf, bool p_free, s8 *p)
{
assert(buf);
- assert(str);
- buf_init_alloc(buf, str->size);
- memcpy(buf->ptr.p, str->ptr.p, str->size);
- buf->wpos = str->size;
- return buf;
+ assert(p);
+ return buf_init(buf, p_free, strlen(p), p);
}
-s_buf * buf_init_1 (s_buf *buf, const s8 *p)
+s_buf * buf_init_1_copy (s_buf *buf, const s8 *p)
{
uw size;
assert(buf);
assert(p);
size = strlen(p);
- buf_init_alloc(buf, size);
+ if (! buf_init_alloc(buf, size))
+ return NULL;
memcpy(buf->ptr.p, p, size);
buf->wpos = size;
return buf;
@@ -231,13 +228,28 @@ s_buf * buf_init_alloc (s_buf *buf, uw size)
return buf_init(buf, true, size, p);
}
-s_buf * buf_new (bool free, uw size, s8 *p)
+s_buf * buf_init_str (s_buf *buf, bool p_free, s_str *p)
+{
+ return buf_init(buf, p_free, p->size, (s8 *) p->ptr.ps8);
+}
+
+s_buf * buf_init_str_copy (s_buf *buf, const s_str *str)
+{
+ assert(buf);
+ assert(str);
+ buf_init_alloc(buf, str->size);
+ memcpy(buf->ptr.p, str->ptr.p, str->size);
+ buf->wpos = str->size;
+ return buf;
+}
+
+s_buf * buf_new (bool p_free, uw size, s8 *p)
{
s_buf *buf;
buf = malloc(sizeof(s_buf));
if (! buf)
err(1, "out of memory");
- buf_init(buf, free, size, p);
+ buf_init(buf, p_free, size, p);
return buf;
}
@@ -769,11 +781,11 @@ sw buf_str_to_hex (s_buf *buf, const s_str *src)
s_str * buf_to_str (const s_buf *buf, s_str *str)
{
- void *free;
+ void *p_free;
assert(buf);
assert(str);
- free = buf->free ? buf->ptr.p : NULL;
- return str_init(str, free, buf->size, buf->ptr.p);
+ p_free = buf->free ? buf->ptr.p : NULL;
+ return str_init(str, p_free, buf->size, buf->ptr.p);
}
sw buf_u8_to_hex (s_buf *buf, const u8 *x)
diff --git a/libc3/buf.h b/libc3/buf.h
index aadac1c..1559765 100644
--- a/libc3/buf.h
+++ b/libc3/buf.h
@@ -29,18 +29,20 @@
/* Stack-allocation compatible functions, call buf_clean after use. */
void buf_clean (s_buf *buf);
-s_buf * buf_init (s_buf *buf, bool free, uw size, s8 *p);
-s_buf * buf_init_1 (s_buf *buf, const s8 *p);
+s_buf * buf_init (s_buf *buf, bool p_free, uw size, s8 *p);
+s_buf * buf_init_1 (s_buf *buf, bool p_free, s8 *p);
s_buf * buf_init_alloc (s_buf *buf, uw size);
-s_buf * buf_init_str (s_buf *buf, const s_str *src);
+s_buf * buf_init_str (s_buf *buf, bool free, s_str *p);
+s_buf * buf_init_str_copy (s_buf *buf, const s_str *str);
/* Heap-allocation compatible functions, call buf_delete after use. */
void buf_delete (s_buf *buf);
s_buf * buf_new (bool free, uw size, s8 *p);
+s_buf * buf_new_1 (bool free, uw size, s8 *p);
s_buf * buf_new_alloc (uw bytes);
s_buf * buf_new_str (s_str *str);
-/* Modifiers */
+/* Operators. */
sw buf_f (s_buf *buf, const char *fmt, ...);
sw buf_flush (s_buf *buf);
sw buf_ignore (s_buf *buf, uw size);
diff --git a/libc3/call.c b/libc3/call.c
index 8e43d8c..6d666f6 100644
--- a/libc3/call.c
+++ b/libc3/call.c
@@ -195,10 +195,9 @@ s_call * call_init (s_call *call)
s_call * call_init_1 (s_call *call, const s8 *p)
{
s_buf buf;
- buf_init_1(&buf, p);
+ buf_init_1(&buf, false, (s8 *) p);
if (buf_parse_call(&buf, call) != (sw) strlen(p))
errx(1, "invalid call: %s", p);
- buf_clean(&buf);
return call;
}
diff --git a/libc3/file.c b/libc3/file.c
index 75795d4..82a8a60 100644
--- a/libc3/file.c
+++ b/libc3/file.c
@@ -95,6 +95,18 @@ sw file_copy_1 (const char *from, const char *to)
return -1;
}
+s_str * file_dirname (const s_str *path, s_str *dest)
+{
+ uw dirsep_pos;
+ assert(path);
+ assert(dest);
+ if (! str_rindex_character(path, '/', &dirsep_pos))
+ return str_init(dest, NULL, 1, ".");
+ if (! dirsep_pos)
+ return str_init(dest, NULL, 1, "/");
+ return str_init_slice(dest, path, 0, dirsep_pos);
+}
+
s_tag * file_mtime (const s_str *path, s_tag *dest)
{
struct stat sb;
@@ -132,7 +144,7 @@ s_str * file_search (const s_str *suffix, const s_sym *mode,
(r = buf_write_str(&buf, suffix)) < 0)
return NULL;
buf_read_to_str(&buf, &tmp);
- /* io_inspect_str(&tmp); */
+ io_inspect_str(&tmp);
file_access(&tmp, mode, &access);
if (access) {
*dest = tmp;
diff --git a/libc3/fn.c b/libc3/fn.c
index 688fccb..a3b4088 100644
--- a/libc3/fn.c
+++ b/libc3/fn.c
@@ -47,10 +47,9 @@ s_fn * fn_init_1 (s_fn *fn, s8 *p)
s_buf buf;
sw r;
assert(fn);
- buf_init_1(&buf, p);
+ buf_init_1(&buf, false, (s8 *) p);
if ((r = buf_parse_fn(&buf, fn)) != (sw) strlen(p))
errx(1, "fn_init_1: buf_parse_fn(%s) %ld != %lu", p, r, strlen(p));
- buf_clean(&buf);
return fn;
}
diff --git a/libc3/integer.c b/libc3/integer.c
index ae47cdf..174e008 100644
--- a/libc3/integer.c
+++ b/libc3/integer.c
@@ -232,9 +232,8 @@ s_integer * integer_init_1 (s_integer *i, const s8 *p)
s_buf buf;
assert(i);
assert(p);
- buf_init_1(&buf, p);
+ buf_init_1(&buf, false, (s8 *) p);
buf_parse_integer(&buf, i);
- buf_clean(&buf);
return i;
}
diff --git a/libc3/list.c b/libc3/list.c
index 6dd33a1..d359fa7 100644
--- a/libc3/list.c
+++ b/libc3/list.c
@@ -171,13 +171,11 @@ s_list * list_new_1 (const s8 *p)
{
s_buf buf;
s_list *list;
- buf_init_1(&buf, p);
+ buf_init_1(&buf, false, (s8 *) p);
if (buf_parse_list(&buf, &list) != (sw) strlen(p)) {
assert(! "invalid list");
- buf_clean(&buf);
return NULL;
}
- buf_clean(&buf);
return list;
}
diff --git a/libc3/map.c b/libc3/map.c
index c136e48..529e4e5 100644
--- a/libc3/map.c
+++ b/libc3/map.c
@@ -90,14 +90,12 @@ s_map * map_init_1 (s_map *map, const s8 *p)
sw r;
assert(map);
assert(p);
- buf_init_1(&buf, p);
+ buf_init_1(&buf, false, (s8 *) p);
if ((r = buf_parse_map(&buf, map)) != (sw) strlen(p)) {
assert(! "invalid map");
warnx("invalid map: \"%s\" (%ld)", p, r);
- buf_clean(&buf);
return NULL;
}
- buf_clean(&buf);
return map;
}
diff --git a/libc3/module.c b/libc3/module.c
index 5db56be..576ed02 100644
--- a/libc3/module.c
+++ b/libc3/module.c
@@ -91,7 +91,7 @@ s_str * module_path (const s_sym *module, const s_str *prefix,
sw r;
assert(dest);
assert(module);
- buf_init_str(&in, &module->str);
+ buf_init_str(&in, false, (s_str *) &module->str);
out_size = module_path_size(module, prefix);
buf_init_alloc(&out, out_size);
if ((r = buf_write_str(&out, prefix)) < 0)
@@ -131,7 +131,7 @@ sw module_path_size (const s_sym *module, const s_str *prefix)
sw result = 0;
assert(prefix);
assert(module);
- buf_init_str(&in, &module->str);
+ buf_init_str(&in, false, (s_str *) &module->str);
result += prefix->size;
result++;
while ((r = buf_read_character_utf8(&in, &c)) > 0) {
@@ -142,6 +142,5 @@ sw module_path_size (const s_sym *module, const s_str *prefix)
b = c;
}
result += strlen(FACTS_EXT);
- buf_clean(&in);
return result;
}
diff --git a/libc3/str.c b/libc3/str.c
index 61a3a70..125f858 100644
--- a/libc3/str.c
+++ b/libc3/str.c
@@ -166,6 +166,51 @@ s_str * str_init_f (s_str *str, const char *fmt, ...)
return str;
}
+s_str * str_init_slice (s_str *str, const s_str *src, sw start, sw end)
+{
+ s_buf buf;
+ assert(str);
+ assert(src);
+ buf_init(&buf, false, src->size, (s8 *) src->ptr.ps8);
+ if (! str_sw_pos_to_uw(start, src->size, &buf.rpos) ||
+ ! str_sw_pos_to_uw(end, src->size, &buf.wpos))
+ return NULL;
+ if (buf.rpos > buf.wpos) {
+ warnx("str_init_slice: invalid positions: %lu > %lu",
+ buf.rpos, buf.wpos);
+ assert(! "str_init_slice: invalid positions");
+ return NULL;
+ }
+ if (! buf_read_to_str(&buf, str))
+ return NULL;
+ return str;
+}
+
+uw * str_sw_pos_to_uw (sw pos, uw max_pos, uw *dest)
+{
+ assert(dest);
+ if (pos >= 0) {
+ if ((uw) pos > max_pos) {
+ warnx("str_sw_pos_to_uw: index out of bounds: %ld > %lu",
+ pos, max_pos);
+ assert(! "str_sw_pos_to_uw: index too large");
+ return NULL;
+ }
+ *dest = (uw) pos;
+ }
+ else {
+ if (max_pos > SW_MAX || pos >= (sw) -max_pos)
+ *dest = max_pos - pos;
+ else {
+ warnx("str_sw_pos_to_uw: index out of bounds: %ld < -%lu",
+ pos, max_pos);
+ assert(! "str_sw_pos_to_uw: index too low");
+ return NULL;
+ }
+ }
+ return dest;
+}
+
s_str * str_init_vf (s_str *str, const char *fmt, va_list ap)
{
int len;
@@ -363,6 +408,25 @@ sw str_read_character_utf8 (s_str *str, character *c)
return size;
}
+uw * str_rindex_character (const s_str *str, character c, uw *dest)
+{
+ uw i = 0;
+ sw result = -1;
+ s_str s;
+ character tmp;
+ s = *str;
+ while (str_read_character_utf8(&s, &tmp) > 0) {
+ if (c == tmp)
+ result = i;
+ i++;
+ }
+ if (result >= 0) {
+ *dest = result;
+ return dest;
+ }
+ return NULL;
+}
+
s_str * str_to_hex (const s_str *src, s_str *dest)
{
s_buf buf;
diff --git a/libc3/str.h b/libc3/str.h
index 5bf695e..f3ab4e8 100644
--- a/libc3/str.h
+++ b/libc3/str.h
@@ -35,6 +35,9 @@ s_str * str_init_copy (s_str *str, const s_str *src);
s_str * str_init_copy_1 (s_str *str, const s8 *p);
s_str * str_init_empty (s_str *str);
s_str * str_init_f (s_str *str, const char *fmt, ...);
+s_str * str_init_slice (s_str *str, const s_str *src, sw start, sw end);
+s_str * str_init_slice_utf8 (s_str *str, const s_str *src, sw start,
+ sw end);
s_str * str_init_vf (s_str *str, const char *fmt, va_list ap);
/* Constructors, call str_delete after use */
@@ -72,6 +75,9 @@ sw str_peek_u8 (const s_str *src, u8 *p);
sw str_peek_u16 (const s_str *src, u16 *p);
sw str_peek_u32 (const s_str *src, u32 *p);
sw str_peek_u64 (const s_str *src, u64 *p);
+uw * str_rindex_character (const s_str *str, character c,
+ uw *dest);
+uw * str_sw_pos_to_uw (sw pos, uw max_pos, uw *dest);
s_str * str_to_hex (const s_str *src, s_str *dest);
s_ident * str_to_ident (const s_str *src, s_ident *dest);
const s_sym * str_to_sym (const s_str *src);
diff --git a/libc3/sym.c b/libc3/sym.c
index cecdb79..ac6abfd 100644
--- a/libc3/sym.c
+++ b/libc3/sym.c
@@ -26,7 +26,7 @@ static s_sym_list * g_sym_list = NULL;
const s_sym * sym_1 (const s8 *p)
{
s_str stra;
- str_init_1(&stra, NULL, p);
+ str_init_copy_1(&stra, NULL, p);
return str_to_sym(&stra);
}
diff --git a/libc3/tag.c b/libc3/tag.c
index b25e390..dc4ea3b 100644
--- a/libc3/tag.c
+++ b/libc3/tag.c
@@ -427,18 +427,20 @@ s_tag * tag_init (s_tag *tag)
s_tag * tag_init_1 (s_tag *tag, const s8 *p)
{
s_buf buf;
+ uw len;
+ sw r;
assert(tag);
tag_init_void(tag);
if (! p)
return tag;
- buf_init_1(&buf, p);
- if (buf_parse_tag(&buf, tag) != (sw) strlen(p)) {
+ buf_init_1(&buf, false, (s8 *) p);
+ len = strlen(p);
+ r = buf_parse_tag(&buf, tag);
+ if (r < 0 || (uw) r != len) {
+ warnx("invalid tag: \"%s\", %lu != %ld", p, len, r);
assert(! "invalid tag");
- errx(1, "invalid tag");
- buf_clean(&buf);
return NULL;
}
- buf_clean(&buf);
return tag;
}
diff --git a/libc3/tuple.c b/libc3/tuple.c
index 021970f..3a18120 100644
--- a/libc3/tuple.c
+++ b/libc3/tuple.c
@@ -12,6 +12,7 @@
*/
#include <assert.h>
#include <stdlib.h>
+#include <string.h>
#include "buf.h"
#include "buf_inspect.h"
#include "buf_parse.h"
@@ -52,15 +53,19 @@ s_tuple * tuple_init (s_tuple *tuple, uw count)
s_tuple * tuple_init_1 (s_tuple *tuple, const s8 *p)
{
s_buf buf;
+ uw len;
+ sw r;
assert(tuple);
assert(p);
- buf_init_1(&buf, p);
- if (buf_parse_tuple(&buf, tuple) <= 0) {
- assert(! "invalid tuple");
- buf_clean(&buf);
+ len = strlen(p);
+ buf_init(&buf, false, len, (s8 *) p);
+ r = buf_parse_tuple(&buf, tuple);
+ if (r < 0 || (uw) r != len) {
+ warnx("tuple_init_1: invalid tuple: \"%s\", %lu != %ld",
+ p, len, r);
+ assert(! "tuple_init_1: invalid tuple");
return NULL;
}
- buf_clean(&buf);
return tuple;
}
diff --git a/libc3/types.h b/libc3/types.h
index c046b83..6f4b598 100644
--- a/libc3/types.h
+++ b/libc3/types.h
@@ -287,7 +287,7 @@ struct buf {
sw (*seek) (s_buf *buf, sw offset, u8 whence);
uw size;
void *user_ptr;
- u64 wpos;
+ uw wpos;
};
struct facts_spec_cursor {
diff --git a/test/buf_inspect_test.c b/test/buf_inspect_test.c
index 473a31a..9f004e9 100644
--- a/test/buf_inspect_test.c
+++ b/test/buf_inspect_test.c
@@ -18,13 +18,10 @@
#define BUF_INSPECT_TEST_ARRAY(test, expected) \
do { \
s8 b[1024]; \
- s_buf buf_test; \
s_buf buf_result; \
s_array tmp; \
test_context("buf_inspect_array(" # test ") -> " # expected); \
- buf_init_1(&buf_test, (test)); \
- buf_parse_array(&buf_test, &tmp); \
- buf_clean(&buf_test); \
+ array_init_1(&tmp, (test)); \
buf_init(&buf_result, false, sizeof(b), b); \
TEST_EQ(buf_inspect_array_size(&tmp), strlen(expected)); \
TEST_EQ(buf_inspect_array(&buf_result, &tmp), strlen(expected)); \
@@ -94,45 +91,33 @@
#define BUF_INSPECT_TEST_INTEGER(test, expected) \
do { \
s8 b[1024]; \
- s_buf buf_test; \
s_buf buf_result; \
s_integer i; \
test_context("buf_inspect_integer(" # test ") -> " # expected); \
- buf_init_1(&buf_test, (test)); \
- buf_parse_integer(&buf_test, &i); \
- buf_clean(&buf_test); \
+ integer_init_1(&i, (test)); \
buf_init(&buf_result, false, sizeof(b), b); \
TEST_EQ(buf_inspect_integer_size(&i), strlen(test)); \
TEST_EQ(buf_inspect_integer(&buf_result, &i), strlen(test)); \
- if (g_test_last_ok) \
- integer_clean(&i); \
+ integer_clean(&i); \
TEST_EQ(buf_result.wpos, strlen(test)); \
- if (g_test_last_ok) \
- TEST_STRNCMP(buf_result.ptr.ps8, (expected), buf_result.wpos); \
+ TEST_STRNCMP(buf_result.ptr.ps8, (expected), buf_result.wpos); \
buf_clean(&buf_result); \
} while (0)
#define BUF_INSPECT_TEST_LIST(test, expected) \
do { \
s_buf buf; \
- s_buf buf_test; \
s_list *list_test; \
test_context("buf_inspect_list(" # test ") -> " # expected); \
- buf_init_1(&buf_test, (test)); \
- if (buf_parse_list(&buf_test, &list_test) != strlen(test)) { \
- assert(! "BUF_INSPECT_TEST_LIST: buf_parse_list"); \
- errx(1, "BUF_INSPECT_TEST_LIST: buf_parse_list"); \
- } \
+ list_test = list_new_1(test); \
buf_init_alloc(&buf, 1024 * 1024); \
TEST_EQ(buf_inspect_list_size((const s_list **) &list_test), \
strlen(expected)); \
TEST_EQ(buf_inspect_list(&buf, (const s_list **) &list_test), \
strlen(expected)); \
TEST_EQ(buf.wpos, strlen(expected)); \
- if (g_test_last_ok) \
- TEST_STRNCMP(buf.ptr.p, (expected), buf.wpos); \
+ TEST_STRNCMP(buf.ptr.p, (expected), buf.wpos); \
list_delete_all(list_test); \
- buf_clean(&buf_test); \
buf_clean(&buf); \
test_context(NULL); \
} while (0)
diff --git a/test/buf_parse_test.c b/test/buf_parse_test.c
index 939b229..f09b9d0 100644
--- a/test/buf_parse_test.c
+++ b/test/buf_parse_test.c
@@ -23,10 +23,9 @@
s_buf buf; \
s_array dest; \
test_context("buf_parse_array(" # test ")"); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_EQ(buf_parse_array(&buf, &dest), strlen(test)); \
TEST_EQ(buf.rpos, strlen(test)); \
- buf_clean(&buf); \
array_clean(&dest); \
test_context(NULL); \
} while (0)
@@ -36,10 +35,9 @@
s_buf buf; \
bool dest = -1; \
test_context("buf_parse_bool(" # test ") -> " # expected); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_EQ(buf_parse_bool(&buf, &dest), strlen(test)); \
TEST_EQ(dest, (expected)); \
- buf_clean(&buf); \
test_context(NULL); \
} while (0)
@@ -48,10 +46,9 @@
s_buf buf; \
s_call dest; \
test_context("buf_parse_call(" # test ")"); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_EQ(buf_parse_call(&buf, &dest), strlen(test)); \
call_clean(&dest); \
- buf_clean(&buf); \
test_context(NULL); \
} while (0)
@@ -60,11 +57,10 @@
s_buf buf; \
s_call dest; \
test_context("buf_parse_call_op(" # test ")"); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
bzero(&dest, sizeof(s_call)); \
TEST_EQ(buf_parse_call_op(&buf, &dest), strlen(test)); \
call_clean(&dest); \
- buf_clean(&buf); \
test_context(NULL); \
} while (0)
@@ -73,10 +69,9 @@
s_buf buf; \
s_cfn dest; \
test_context("buf_parse_cfn(" # test ")"); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_EQ(buf_parse_cfn(&buf, &dest), strlen(test)); \
cfn_clean(&dest); \
- buf_clean(&buf); \
test_context(NULL); \
} while (0)
@@ -85,11 +80,10 @@
s_buf buf; \
character dest = -1; \
test_context("buf_parse_character(" # test ") -> " # expected); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_EQ(buf_parse_character(&buf, &dest), strlen(test)); \
TEST_EQ(buf.wpos, strlen(test)); \
TEST_EQ(dest, (expected)); \
- buf_clean(&buf); \
test_context(NULL); \
} while (0)
@@ -98,11 +92,10 @@
s_buf buf; \
character dest = -1; \
test_context("buf_parse_character(" # test ") -> -1"); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_EQ(buf_parse_character(&buf, &dest), -1); \
TEST_EQ(buf.rpos, 0); \
TEST_EQ(dest, -1); \
- buf_clean(&buf); \
test_context(NULL); \
} while (0)
@@ -111,11 +104,10 @@
s_buf buf; \
u8 dest = 0x80; \
test_context("buf_parse_digit_bin(" # test ") -> " # expected); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_EQ(buf_parse_digit_bin(&buf, &dest), 1); \
TEST_EQ(buf.rpos, 1); \
TEST_EQ(dest, (expected)); \
- buf_clean(&buf); \
test_context(NULL); \
} while (0)
@@ -124,11 +116,10 @@
s_buf buf; \
u8 dest = 0x80; \
test_context("buf_parse_digit_dec(" # test ") -> " # expected); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_EQ(buf_parse_digit_dec(&buf, &dest), 1); \
TEST_EQ(buf.rpos, 1); \
TEST_EQ(dest, (expected)); \
- buf_clean(&buf); \
test_context(NULL); \
} while (0)
@@ -137,11 +128,10 @@
s_buf buf; \
u8 dest = 0x80; \
test_context("buf_parse_digit_hex(" # test ") -> " # expected); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_EQ(buf_parse_digit_hex(&buf, &dest), 1); \
TEST_EQ(buf.rpos, 1); \
TEST_EQ(dest, (expected)); \
- buf_clean(&buf); \
test_context(NULL); \
} while (0)
@@ -150,11 +140,10 @@
s_buf buf; \
u8 dest = 0x80; \
test_context("buf_parse_digit_oct(" # test ") -> " # expected); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_EQ(buf_parse_digit_oct(&buf, &dest), 1); \
TEST_EQ(buf.rpos, 1); \
TEST_EQ(dest, (expected)); \
- buf_clean(&buf); \
test_context(NULL); \
} while (0)
@@ -163,23 +152,21 @@
s_buf buf; \
f32 dest = -1; \
test_context("buf_parse_f32(" # test ") -> " # expected1); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_EQ(buf_parse_f32(&buf, &dest), strlen(test)); \
TEST_FLOAT_EQ2(dest, (expected1), (expected2)); \
- buf_clean(&buf); \
test_context(NULL); \
} while (0)
-#define BUF_PARSE_TEST_F64(test, expected) \
- do { \
- s_buf buf; \
- f64 f64_tmp; \
- test_context("buf_parse_f64(" # test ") -> " # expected); \
- buf_init_1(&buf, (test)); \
- TEST_EQ(buf_parse_f64(&buf, &f64_tmp), strlen(test)); \
- TEST_DOUBLE_EQ(f64_tmp, (expected)); \
- buf_clean(&buf); \
- test_context(NULL); \
+#define BUF_PARSE_TEST_F64(test, expected) \
+ do { \
+ s_buf buf; \
+ f64 f64_tmp; \
+ test_context("buf_parse_f64(" # test ") -> " # expected); \
+ buf_init_1(&buf, false, (test)); \
+ TEST_EQ(buf_parse_f64(&buf, &f64_tmp), strlen(test)); \
+ TEST_DOUBLE_EQ(f64_tmp, (expected)); \
+ test_context(NULL); \
} while (0)
#define BUF_PARSE_TEST_FN(test) \
@@ -187,10 +174,9 @@
s_buf buf; \
s_fn dest; \
test_context("buf_parse_fn(" # test ")"); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_EQ(buf_parse_fn(&buf, &dest), strlen(test)); \
fn_clean(&dest); \
- buf_clean(&buf); \
test_context(NULL); \
} while (0)
@@ -199,14 +185,13 @@
s_buf buf; \
s_ident dest; \
test_context("buf_parse_ident(" # test ") -> " # expected); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_EQ(buf_parse_ident(&buf, &dest), strlen(test)); \
if (g_test_last_ok) \
TEST_EQ(dest.sym->str.size, strlen(expected)); \
if (g_test_last_ok) \
TEST_STRNCMP(dest.sym->str.ptr.p, (expected), \
dest.sym->str.size); \
- buf_clean(&buf); \
test_context(NULL); \
} while (0)
@@ -215,11 +200,10 @@
s_buf buf; \
s_integer i; \
test_context("buf_parse_integer(" # test ")"); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_EQ(buf_parse_integer(&buf, &i), strlen(test)); \
if (g_test_last_ok) \
integer_clean(&i); \
- buf_clean(&buf); \
test_context(NULL); \
} while (0)
@@ -228,10 +212,9 @@
s_buf buf; \
s_integer i; \
test_context("buf_parse_integer_unsigned_bin(" # test ")"); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_EQ(buf_parse_integer_unsigned_bin(&buf, &i), \
strlen(test)); \
- buf_clean(&buf); \
integer_clean(&i); \
test_context(NULL); \
} while (0)
@@ -241,10 +224,9 @@
s_buf buf; \
s_integer i; \
test_context("buf_parse_integer_unsigned_dec(" # test ")"); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_EQ(buf_parse_integer_unsigned_dec(&buf, &i), \
strlen(test)); \
- buf_clean(&buf); \
integer_clean(&i); \
test_context(NULL); \
} while (0)
@@ -254,10 +236,9 @@
s_buf buf; \
s_integer i; \
test_context("buf_parse_integer_unsigned_hex(" # test ")"); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_EQ(buf_parse_integer_unsigned_hex(&buf, &i), \
strlen(test)); \
- buf_clean(&buf); \
integer_clean(&i); \
test_context(NULL); \
} while (0)
@@ -267,10 +248,9 @@
s_buf buf; \
s_integer i; \
test_context("buf_parse_integer_unsigned_oct(" # test ")"); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_EQ(buf_parse_integer_unsigned_oct(&buf, &i), \
strlen(test)); \
- buf_clean(&buf); \
integer_clean(&i); \
test_context(NULL); \
} while (0)
@@ -280,23 +260,21 @@
s_buf buf; \
s_list *dest = NULL; \
test_context("buf_parse_list(" # test ")"); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_EQ(buf_parse_list(&buf, &dest), strlen(test)); \
- buf_clean(&buf); \
- list_delete_all(dest); \
+ list_delete_all(dest); \
test_context(NULL); \
} while (0)
#define BUF_PARSE_TEST_NOT_BOOL(test) \
do { \
s_buf buf; \
- bool dest = 2; \
+ bool dest = 2; \
test_context("buf_parse_bool(" # test ") -> 0"); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_EQ(buf_parse_bool(&buf, &dest), 0); \
TEST_EQ(buf.rpos, 0); \
- TEST_EQ(dest, 2); \
- buf_clean(&buf); \
+ TEST_EQ(dest, 2); \
test_context(NULL); \
} while (0)
@@ -306,10 +284,9 @@
s_call dest; \
bzero(&dest, sizeof(dest)); \
test_context("buf_parse_call(" # test ") -> 0"); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_EQ(buf_parse_call(&buf, &dest), 0); \
TEST_EQ(buf.rpos, 0); \
- buf_clean(&buf); \
test_context(NULL); \
} while (0)
@@ -319,10 +296,9 @@
s_cfn dest; \
bzero(&dest, sizeof(dest)); \
test_context("buf_parse_cfn(" # test ") -> 0"); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_EQ(buf_parse_cfn(&buf, &dest), 0); \
TEST_EQ(buf.rpos, 0); \
- buf_clean(&buf); \
test_context(NULL); \
} while (0)
@@ -331,11 +307,10 @@
s_buf buf; \
character dest = -1; \
test_context("buf_parse_character(" # test ") -> 0"); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_EQ(buf_parse_character(&buf, &dest), 0); \
TEST_EQ(buf.rpos, 0); \
TEST_EQ(dest, -1); \
- buf_clean(&buf); \
test_context(NULL); \
} while (0)
@@ -344,11 +319,10 @@
s_buf buf; \
u8 dest = 0; \
test_context("buf_parse_digit_bin(" # test ") -> 0"); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_EQ(buf_parse_digit_bin(&buf, &dest), 0); \
TEST_EQ(buf.rpos, 0); \
TEST_EQ(dest, 0); \
- buf_clean(&buf); \
test_context(NULL); \
} while (0)
@@ -357,11 +331,10 @@
s_buf buf; \
u8 dest = 0; \
test_context("buf_parse_digit_dec(" # test ") -> 0"); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_EQ(buf_parse_digit_dec(&buf, &dest), 0); \
TEST_EQ(buf.rpos, 0); \
TEST_EQ(dest, 0); \
- buf_clean(&buf); \
test_context(NULL); \
} while (0)
@@ -370,11 +343,10 @@
s_buf buf; \
u8 dest = 0; \
test_context("buf_parse_digit_hex(" # test ") -> 0"); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_EQ(buf_parse_digit_hex(&buf, &dest), 0); \
TEST_EQ(buf.rpos, 0); \
TEST_EQ(dest, 0); \
- buf_clean(&buf); \
test_context(NULL); \
} while (0)
@@ -383,11 +355,10 @@
s_buf buf; \
u8 dest = 0; \
test_context("buf_parse_digit_oct(" # test ") -> 0"); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_EQ(buf_parse_digit_oct(&buf, &dest), 0); \
TEST_EQ(buf.rpos, 0); \
TEST_EQ(dest, 0); \
- buf_clean(&buf); \
test_context(NULL); \
} while (0)
@@ -397,10 +368,9 @@
s_ident dest; \
bzero(&dest, sizeof(dest)); \
test_context("buf_parse_ident(" # test ") -> 0"); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_EQ(buf_parse_ident(&buf, &dest), 0); \
TEST_EQ(buf.rpos, 0); \
- buf_clean(&buf); \
test_context(NULL); \
} while (0)
@@ -409,10 +379,9 @@
s_buf buf; \
s_integer i; \
test_context("buf_parse_integer(" # test ") -> 0"); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_EQ(buf_parse_integer(&buf, &i), 0); \
TEST_EQ(buf.rpos, 0); \
- buf_clean(&buf); \
test_context(NULL); \
} while (0)
@@ -421,10 +390,9 @@
s_buf buf; \
s_integer i; \
test_context("buf_parse_integer_unsigned_bin(" # test ") -> 0"); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_EQ(buf_parse_integer_unsigned_bin(&buf, &i), 0); \
TEST_EQ(buf.rpos, 0); \
- buf_clean(&buf); \
test_context(NULL); \
} while (0)
@@ -433,10 +401,9 @@
s_buf buf; \
s_integer i; \
test_context("buf_parse_integer_unsigned_dec(" # test ") -> 0"); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_EQ(buf_parse_integer_unsigned_dec(&buf, &i), 0); \
TEST_EQ(buf.rpos, 0); \
- buf_clean(&buf); \
test_context(NULL); \
} while (0)
@@ -445,10 +412,9 @@
s_buf buf; \
s_integer i; \
test_context("buf_parse_integer_unsigned_hex(" # test ") -> 0"); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_EQ(buf_parse_integer_unsigned_hex(&buf, &i), 0); \
TEST_EQ(buf.rpos, 0); \
- buf_clean(&buf); \
test_context(NULL); \
} while (0)
@@ -457,10 +423,9 @@
s_buf buf; \
s_integer i; \
test_context("buf_parse_integer_unsigned_oct(" # test ") -> 0"); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_EQ(buf_parse_integer_unsigned_oct(&buf, &i), 0); \
TEST_EQ(buf.rpos, 0); \
- buf_clean(&buf); \
test_context(NULL); \
} while (0)
@@ -470,10 +435,9 @@
s_str dest; \
bzero(&dest, sizeof(dest)); \
test_context("buf_parse_str(" # test ") -> 0"); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_EQ(buf_parse_str(&buf, &dest), 0); \
TEST_EQ(buf.rpos, 0); \
- buf_clean(&buf); \
test_context(NULL); \
} while (0)
@@ -482,11 +446,10 @@
s_buf buf; \
u8 dest = 0; \
test_context("buf_parse_str_u8(" # test ") -> 0"); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_EQ(buf_parse_str_u8(&buf, &dest), 0); \
TEST_EQ(buf.rpos, 0); \
TEST_EQ(dest, 0); \
- buf_clean(&buf); \
test_context(NULL); \
} while (0)
@@ -495,10 +458,9 @@
s_buf buf; \
const s_sym *dest = NULL; \
test_context("buf_parse_sym(" # test ") -> 0"); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_EQ(buf_parse_sym(&buf, &dest), 0); \
TEST_EQ(buf.rpos, 0); \
- buf_clean(&buf); \
test_context(NULL); \
} while (0)
@@ -508,11 +470,10 @@
s_str dest; \
bzero(&dest, sizeof(dest)); \
test_context("buf_parse_str(" # test ") -> " # expected); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_EQ(buf_parse_str(&buf, &dest), strlen(test)); \
TEST_EQ(dest.size, strlen(expected)); \
TEST_STRNCMP(dest.ptr.p, (expected), dest.size); \
- buf_clean(&buf); \
str_clean(&dest); \
test_context(NULL); \
} while (0)
@@ -523,10 +484,9 @@
s_str dest; \
bzero(&dest, sizeof(dest)); \
test_context("buf_parse_str(" # test ") -> EOF"); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_EQ(buf_parse_str(&buf, &dest), -1); \
TEST_EQ(buf.rpos, 0); \
- buf_clean(&buf); \
test_context(NULL); \
} while (0)
@@ -535,10 +495,9 @@
s_buf buf; \
character dest = -1; \
test_context("buf_parse_str_character(" # test ") -> " # expected);\
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_EQ(buf_parse_str_character(&buf, &dest), strlen(test)); \
TEST_EQ(dest, (expected)); \
- buf_clean(&buf); \
test_context(NULL); \
} while (0)
@@ -547,13 +506,12 @@
s_buf buf; \
s_str dest; \
test_context("buf_parse_str(" # test ") -> " # expected); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_EQ(buf_parse_str(&buf, &dest), strlen(test)); \
if (g_test_last_ok) \
TEST_EQ(dest.size, n); \
if (g_test_last_ok) \
TEST_EQ(memcmp(dest.ptr.p, expected, n), 0); \
- buf_clean(&buf); \
str_clean(&dest); \
test_context(NULL); \
} while (0)
@@ -563,11 +521,10 @@
s_buf buf; \
u8 dest = 0x80; \
test_context("buf_parse_str_u8(" # test ") -> " # expected); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_EQ(buf_parse_str_u8(&buf, &dest), (size)); \
TEST_EQ(buf.rpos, (size)); \
TEST_EQ(dest, (expected)); \
- buf_clean(&buf); \
test_context(NULL); \
} while (0)
@@ -576,11 +533,10 @@
s_buf buf; \
u8 dest = 0x80; \
test_context("buf_parse_str_u8(" # test ") -> -1"); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_EQ(buf_parse_str_u8(&buf, &dest), -1); \
TEST_EQ(buf.rpos, 0); \
TEST_EQ(dest, 0x80); \
- buf_clean(&buf); \
test_context(NULL); \
} while (0)
@@ -589,7 +545,7 @@
s_buf buf; \
const s_sym *dest = NULL; \
test_context("buf_parse_sym(" # test ") -> " # expected); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_EQ(buf_parse_sym(&buf, &dest), strlen(test)); \
if (g_test_last_ok) \
TEST_ASSERT(dest); \
@@ -597,7 +553,6 @@
TEST_EQ(dest->str.size, strlen(expected)); \
if (g_test_last_ok) \
TEST_STRNCMP(dest->str.ptr.p, (expected), dest->str.size); \
- buf_clean(&buf); \
test_context(NULL); \
} while (0)
@@ -606,10 +561,9 @@
s_buf buf; \
const s_sym *dest = NULL; \
test_context("buf_parse_sym(" # test ") -> -1"); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_EQ(buf_parse_sym(&buf, &dest), -1); \
TEST_EQ(buf.rpos, 0); \
- buf_clean(&buf); \
test_context(NULL); \
} while (0)
@@ -619,9 +573,8 @@
s_tag dest; \
bzero(&dest, sizeof(dest)); \
test_context("buf_parse_tag(" # test ")"); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_EQ(buf_parse_tag(&buf, &dest), strlen(test)); \
- buf_clean(&buf); \
tag_clean(&dest); \
test_context(NULL); \
} while (0)
@@ -632,9 +585,8 @@
s_tuple dest; \
bzero(&dest, sizeof(dest)); \
test_context("buf_parse_tuple(" # test ")"); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_EQ(buf_parse_tuple(&buf, &dest), strlen(test)); \
- buf_clean(&buf); \
tuple_clean(&dest); \
test_context(NULL); \
} while (0)
diff --git a/test/buf_test.c b/test/buf_test.c
index 0b5607a..954e8d7 100644
--- a/test/buf_test.c
+++ b/test/buf_test.c
@@ -43,9 +43,8 @@
do { \
s_buf buf; \
test_context("buf_ignore(" # test ", " # count ")"); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_EQ(buf_ignore(&buf, (count)), expected); \
- buf_clean(&buf); \
test_context(NULL); \
} while (0)
@@ -53,10 +52,9 @@
do { \
s_buf buf; \
test_context("buf_peek_1(" # test ")"); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_EQ(buf_peek_1(&buf, (test)), strlen(test)); \
TEST_EQ(buf.rpos, 0); \
- buf_clean(&buf); \
test_context(NULL); \
} while (0)
@@ -65,7 +63,7 @@
character dest; \
s_buf buf; \
test_context("buf_peek_character_utf8(" # test ")"); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_EQ(buf_peek_character_utf8(&buf, &dest), (expected)); \
TEST_EQ(buf.rpos, 0); \
TEST_EQ(dest, (c)); \
@@ -77,10 +75,9 @@
do { \
s_buf buf; \
test_context("buf_read_1(" # test ")"); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_EQ(buf_read_1(&buf, (test)), strlen(test)); \
TEST_EQ(buf.rpos, strlen(test)); \
- buf_clean(&buf); \
test_context(NULL); \
} while (0)
@@ -88,9 +85,8 @@
do { \
s_buf buf; \
test_context("buf_read_1(" # data ", " # test ") -> " # result); \
- buf_init_1(&buf, (data)); \
+ buf_init_1(&buf, false, (data)); \
TEST_EQ(buf_read_1(&buf, (test)), (result)); \
- buf_clean(&buf); \
test_context(NULL); \
} while (0)
@@ -99,7 +95,7 @@
character c; \
s_buf buf; \
test_context("buf_read_character_utf8(" # test ") -> " # result); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_ASSERT(buf_read_character_utf8(&buf, &c) >= 0); \
TEST_EQ(c, result); \
buf_clean(&buf); \
@@ -111,7 +107,7 @@
character c; \
s_buf buf; \
test_context("buf_read_n(" # test ", " # n ") -> " # result); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_ASSERT(buf_read_n(&buf, &c) >= 0); \
TEST_EQ(c, result); \
} while (0)
@@ -121,10 +117,9 @@
s_buf buf; \
s_str result; \
test_context("buf_read_to_str(" # test ")"); \
- buf_init_1(&buf, (test)); \
+ buf_init_1(&buf, false, (test)); \
TEST_EQ(buf_read_to_str(&buf, &result), strlen(test)); \
TEST_EQ(buf.rpos, strlen(test)); \
- buf_clean(&buf); \
str_clean(&result); \
test_context(NULL); \
} while (0)
@@ -649,7 +644,7 @@ TEST_CASE(buf_read_u8)
{
s_buf buf;
u8 byte;
- buf_init_1(&buf, "ABCDEFGH");
+ buf_init_1(&buf, false, "ABCDEFGH");
TEST_EQ(buf_read_u8(&buf, &byte), 1);
TEST_EQ(byte, 'A');
TEST_EQ(buf_read_u8(&buf, &byte), 1);