Commit c412d7b1e503f033d98402e81e086db9d5e4ae0c

Thomas de Grivel 2023-06-10T11:58:43

wip tests

diff --git a/Makefile b/Makefile
index f6eb789..4ed70d7 100644
--- a/Makefile
+++ b/Makefile
@@ -143,6 +143,9 @@ test_ic3: build
 test_ic3_debug: debug
 	${MAKE} -C test test_ic3_debug
 
+test_libc3: test
+	${MAKE} -C test test_libc3
+
 .PHONY: all asan c3s cov clean clean_cov debug gcovr ic3 install libc3 libtommath license test test_asan test_cov test_debug test_gcovr test_ic3
 
 include config.mk
diff --git a/libc3/buf_inspect.c b/libc3/buf_inspect.c
index 11548cf..3d7a94d 100644
--- a/libc3/buf_inspect.c
+++ b/libc3/buf_inspect.c
@@ -176,15 +176,6 @@
   DEF_BUF_INSPECT_U_BASE(bits, hexadecimal)                            \
   DEF_BUF_INSPECT_U_BASE(bits, octal)
 
-sw buf_inspect_ident_reserved (s_buf *buf, const s_ident *ident);
-sw buf_inspect_ident_reserved_size (const s_ident *ident);
-sw buf_inspect_str_byte (s_buf *buf, const u8 *byte);
-static const sw buf_inspect_str_byte_size = 4;
-sw buf_inspect_str_reserved (s_buf *buf, const s_str *str);
-sw buf_inspect_str_reserved_size (const s_str *str);
-sw buf_inspect_sym_reserved (s_buf *buf, const s_sym *sym);
-sw buf_inspect_sym_reserved_size (const s_sym *sym);
-
 f_buf_inspect buf_inspect (e_tag_type type)
 {
   switch (type) {
@@ -1006,8 +997,10 @@ sw buf_inspect_str (s_buf *buf, const s_str *str)
   s_buf_save save;
   assert(buf);
   assert(str);
-  if (str_has_reserved_characters(str))
+  if (str_has_reserved_characters(str)) {
+    printf("\nstr_has_reserver_characters\n");
     return buf_inspect_str_reserved(buf, str);
+  }
   buf_save_init(buf, &save);
   if ((r = buf_write_u8(buf, '"')) <= 0)
     goto clean;
@@ -1069,7 +1062,7 @@ sw buf_inspect_str_character (s_buf *buf, const character *c)
   if (! str_character_is_reserved(*c))
     return buf_write_character_utf8(buf, *c);
   buf_save_init(buf, &save);
-  if ((r = buf_write_u8(buf, '\\')) != 1)
+  if ((r = buf_write_1(buf, "\\")) <= 0)
     goto restore;
   result += r;
   switch (*c) {
@@ -1222,7 +1215,7 @@ sw buf_inspect_str_reserved_size (const s_str *str)
 
 sw buf_inspect_str_size (const s_str *str)
 {
-  const sw quote_size = 1;
+  const sw quote_size = strlen("\"");
   sw size;
   if (str_has_reserved_characters(str))
     return buf_inspect_str_reserved_size(str);
diff --git a/libc3/buf_inspect.h b/libc3/buf_inspect.h
index 44711c8..6a06c29 100644
--- a/libc3/buf_inspect.h
+++ b/libc3/buf_inspect.h
@@ -81,6 +81,8 @@ sw buf_inspect_fn_clause (s_buf *buf, const s_fn *fn);
 sw buf_inspect_fn_pattern (s_buf *buf, const s_list *pattern);
 sw buf_inspect_fn_size (const s_fn *fn);
 sw buf_inspect_ident (s_buf *buf, const s_ident *ident);
+sw buf_inspect_ident_reserved (s_buf *buf, const s_ident *ident);
+sw buf_inspect_ident_reserved_size (const s_ident *ident);
 sw buf_inspect_ident_size (const s_ident *ident);
 sw buf_inspect_integer (s_buf *buf, const s_integer *x);
 sw buf_inspect_integer_size (const s_integer *x);
@@ -96,10 +98,16 @@ BUF_INSPECT_S_PROTOTYPES(32);
 BUF_INSPECT_S_PROTOTYPES(64);
 BUF_INSPECT_S_PROTOTYPES(w);
 sw buf_inspect_str (s_buf *buf, const s_str *str);
-sw buf_inspect_str_size (const s_str *str);
+sw buf_inspect_str_byte (s_buf *buf, const u8 *byte);
+static const sw buf_inspect_str_byte_size = 4;
 sw buf_inspect_str_character (s_buf *buf, const character *c);
 sw buf_inspect_str_character_size (const character *c);
+sw buf_inspect_str_reserved (s_buf *buf, const s_str *str);
+sw buf_inspect_str_reserved_size (const s_str *str);
+sw buf_inspect_str_size (const s_str *str);
 sw buf_inspect_sym (s_buf *buf, const s_sym *sym);
+sw buf_inspect_sym_reserved (s_buf *buf, const s_sym *sym);
+sw buf_inspect_sym_reserved_size (const s_sym *sym);
 sw buf_inspect_sym_size (const s_sym *sym);
 sw buf_inspect_tag (s_buf *buf, const s_tag *tag);
 sw buf_inspect_tag_size (const s_tag *tag);
diff --git a/libc3/configure b/libc3/configure
index e6d6f51..98947a1 100755
--- a/libc3/configure
+++ b/libc3/configure
@@ -51,6 +51,10 @@ config_include sha1_h sys/types.h sha1.h HAVE_SHA1_H
 config_define PREFIX "\"${PREFIX}\""
 update_config_h
 
+if ! [ -f ../ucd2c/ucd.c ]; then
+    touch ../ucd2c/ucd.c
+fi
+
 # Address Sanitizer config
 CFLAGS_ASAN="$CFLAGS -fsanitize=address -O1 -fno-omit-frame-pointer -g"
 LDFLAGS_ASAN="$LDFLAGS"
diff --git a/test/Makefile b/test/Makefile
index cc2529d..e942181 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -10,9 +10,29 @@
 ## AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
 ## THIS SOFTWARE.
 
-CLEANFILES = *.a *.css *.gcno *.html ic3/*.diff ic3/*.err ic3/*.out ic3/*.ret *.o libc3_test libc3_test_asan libc3_test_cov libc3_test_debug .libs *.lo
+CLEANFILES = \
+	*.a \
+	*.css \
+	*.gcno \
+	*.html \
+	*.lo \
+	*.o \
+	.libs \
+	ic3/*.diff \
+	ic3/*.err \
+	ic3/*.out \
+	ic3/*.ret \
+	test_libc3 \
+	test_libc3_asan \
+	test_libc3_cov \
+	test_libc3_debug
+
+CLEANFILES_COV = \
+	*.css \
+	*.gcda \
+	*.html \
+	.libs/*.gcda
 
-CLEANFILES_COV = *.css *.gcda *.html .libs/*.gcda
 CLEANFILES += ${CLEANFILES_COV}
 
 DISTCLEANFILES = ${CLEANFILES} config.mk
diff --git a/test/buf_inspect_test.c b/test/buf_inspect_test.c
index 44f32e9..73d07a7 100644
--- a/test/buf_inspect_test.c
+++ b/test/buf_inspect_test.c
@@ -122,9 +122,9 @@
     test_context("buf_inspect_str(" # test ") -> " # expected);        \
     str_init_1(&str, NULL, (test));                                    \
     buf_init(&buf, false, sizeof(b), b);                               \
-    TEST_EQ(buf_inspect_str_size(&str), strlen(expected));             \
-    TEST_EQ(buf_inspect_str(&buf, &str), strlen(expected));            \
     TEST_STRNCMP(buf.ptr.p, (expected), buf.wpos);                     \
+    TEST_EQ(buf_inspect_str(&buf, &str), strlen(expected));            \
+    TEST_EQ(buf_inspect_str_size(&str), strlen(expected));             \
     test_context(NULL);                                                \
   } while (0)