diff --git a/libc3/buf_parse.c b/libc3/buf_parse.c
index 56d54cd..2378d77 100644
--- a/libc3/buf_parse.c
+++ b/libc3/buf_parse.c
@@ -438,7 +438,7 @@ sw buf_parse_fn (s_buf *buf, s_fn *dest)
goto restore;
result += r;
fn_init(&tmp);
- if ((r = buf_parse_fn_pattern(buf, &tmp.pattern)) < 0) {
+ if ((r = buf_parse_fn_pattern(buf, &tmp.pattern)) <= 0) {
warnx("buf_parse_fn: invalid pattern");
goto restore;
}
@@ -452,6 +452,7 @@ sw buf_parse_fn (s_buf *buf, s_fn *dest)
warnx("buf_parse_fn: invalid program");
goto restore;
}
+ result += r;
*dest = tmp;
r = result;
goto clean;
diff --git a/test/buf_parse_test.c b/test/buf_parse_test.c
index a7c6d05..22b5932 100644
--- a/test/buf_parse_test.c
+++ b/test/buf_parse_test.c
@@ -18,6 +18,7 @@
#include "../libc3/buf.h"
#include "../libc3/buf_parse.h"
#include "../libc3/call.h"
+#include "../libc3/fn.h"
#include "../libc3/list.h"
#include "../libc3/str.h"
#include "../libc3/integer.h"
@@ -150,6 +151,18 @@
test_context(NULL); \
} while (0)
+#define BUF_PARSE_TEST_FN(test) \
+ do { \
+ s_buf buf; \
+ s_fn dest; \
+ test_context("buf_parse_fn(" # test ")"); \
+ buf_init_1(&buf, (test)); \
+ TEST_EQ(buf_parse_fn(&buf, &dest), strlen(test)); \
+ fn_clean(&dest); \
+ buf_clean(&buf); \
+ test_context(NULL); \
+ } while (0)
+
#define BUF_PARSE_TEST_IDENT(test, expected) \
do { \
s_buf buf; \
@@ -568,6 +581,7 @@ void buf_parse_test_digit_oct ();
void buf_parse_test_digit_dec ();
void buf_parse_test_f32 ();
void buf_parse_test_f64 ();
+void buf_parse_test_fn ();
void buf_parse_test_integer ();
void buf_parse_test_integer_dec ();
void buf_parse_test_integer_hex ();
@@ -594,6 +608,7 @@ void buf_parse_test ()
buf_parse_test_character();
buf_parse_test_f32();
buf_parse_test_f64();
+ buf_parse_test_fn();
buf_parse_test_integer_bin();
buf_parse_test_integer_dec();
buf_parse_test_integer_hex();
@@ -804,6 +819,13 @@ void buf_parse_test_f64()
{
}
+void buf_parse_test_fn ()
+{
+ BUF_PARSE_TEST_FN("fn () { [] }");
+ BUF_PARSE_TEST_FN("fn (x) { x }");
+ BUF_PARSE_TEST_FN("fn (x, y) { x }");
+}
+
void buf_parse_test_ident ()
{
BUF_PARSE_TEST_NOT_IDENT("0");
diff --git a/test/tag_test.c b/test/tag_test.c
index 626917b..bf228c0 100644
--- a/test/tag_test.c
+++ b/test/tag_test.c
@@ -26,9 +26,11 @@
void tag_test ();
void tag_test_hash_u64 ();
+void tag_test_init_1 ();
void tag_test ()
{
+ tag_test_init_1();
tag_test_hash_u64();
}
@@ -45,3 +47,14 @@ void tag_test_hash_u64 ()
tag_clean(&a);
tag_clean(&b);
}
+
+void tag_test_init_1 ()
+{
+ s_tag a;
+ TEST_ASSERT(tag_init_1(&a, "fn () { [] }"));
+ tag_clean(&a);
+ TEST_ASSERT(tag_init_1(&a, "fn (x) { x }"));
+ tag_clean(&a);
+ TEST_ASSERT(tag_init_1(&a, "fn (x, y) { x }"));
+ tag_clean(&a);
+}