Commit 8cb54ad2e0dc6d8b218bcb23d0a140a630ee7c8f

Thomas de Grivel 2024-11-20T20:45:56

fix tests for floats, and fix floats

diff --git a/libkc3/buf_inspect.c b/libkc3/buf_inspect.c
index bd72eaf..a72179c 100644
--- a/libkc3/buf_inspect.c
+++ b/libkc3/buf_inspect.c
@@ -1575,9 +1575,13 @@ sw buf_inspect_f32 (s_buf *buf, const f32 *f)
       return r;
     result += r;
   }
-  if ((r = buf_write_1(buf, "f")) <= 0)
-    return r;
+  /*
+  if (false) {
+    if ((r = buf_write_1(buf, "f")) <= 0)
+      return r;
+  }
   result += r;
+  */
   return result;
 }
 
@@ -1647,9 +1651,13 @@ sw buf_inspect_f32_size (s_pretty *pretty, const f32 *f)
       return r;
     result += r;
   }
-  if ((r = buf_write_1_size(pretty, "f")) <= 0)
-    return r;
+  /*
+  if (false) {
+    if ((r = buf_write_1_size(pretty, "f")) <= 0)
+      return r;
+  }
   result += r;
+  */
   return result;
 }
 
@@ -1880,8 +1888,15 @@ sw buf_inspect_f128_size (s_pretty *pretty, const f128 *x)
   assert(x);
   exp = 0.0;
   y = *x;
-  if (y == 0.0)
-    return buf_write_1_size(pretty, "0.0");
+  if ((r = buf_write_1_size(pretty, "(F128) ")) < 0)
+    return r;
+  result += r;
+  if (y == 0.0) {
+    if ((r = buf_write_1_size(pretty, "0.0")) < 0)
+      return r;
+    result += r;
+    return result;
+  }
   if (y < 0) {
     if ((r = buf_write_1_size(pretty, "-")) <= 0)
       return r;
diff --git a/test/buf_inspect_test.c b/test/buf_inspect_test.c
index 0270ce1..299ab93 100644
--- a/test/buf_inspect_test.c
+++ b/test/buf_inspect_test.c
@@ -101,6 +101,25 @@
     test_context(NULL);                                                \
   } while (0)
 
+#define BUF_INSPECT_TEST_F128(test, expected)                          \
+  do {                                                                 \
+    char b[128];                                                       \
+    s_buf buf;                                                         \
+    s_pretty pretty = {0};                                             \
+    f128 tmp;                                                          \
+    test_context("buf_inspect_f128(" # test ") -> " # expected);       \
+    tmp = (test);                                                      \
+    buf_init(&buf, false, sizeof(b), b);                               \
+    buf_inspect_f128(&buf, &tmp);                                      \
+    TEST_STRNCMP(buf.ptr.pchar, (expected), buf.wpos);                 \
+    TEST_EQ(buf.wpos, strlen(expected));                               \
+    TEST_EQ(buf_inspect_f128_size(&pretty, &tmp), strlen(expected));   \
+    buf_init(&buf, false, sizeof(b), b);                               \
+    TEST_EQ(buf_inspect_f128(&buf, &tmp), strlen(expected));           \
+    TEST_STRNCMP(buf.ptr.pchar, (expected), buf.wpos);                 \
+    test_context(NULL);                                                \
+  } while (0)
+
 #define BUF_INSPECT_TEST_INTEGER(test, expected)                       \
   do {                                                                 \
     char b[1024];                                                      \
@@ -259,32 +278,46 @@ TEST_CASE_END(buf_inspect_character)
 
 TEST_CASE(buf_inspect_f32)
 {
-  BUF_INSPECT_TEST_F32(0.0f, "0.0f");
-  BUF_INSPECT_TEST_F32(0.1f, "1.0e-1f");
-  BUF_INSPECT_TEST_F32(0.1234567f, "1.234567e-1f");
-  BUF_INSPECT_TEST_F32(1.234567f, "1.234567f");
-  BUF_INSPECT_TEST_F32(1234567.0f, "1.234567e+6f");
-  BUF_INSPECT_TEST_F32(-0.1f, "-1.0e-1f");
-  BUF_INSPECT_TEST_F32(-0.1234567f, "-1.234567e-1f");
-  BUF_INSPECT_TEST_F32(-1.234567f, "-1.234567f");
-  BUF_INSPECT_TEST_F32(-1234567.0f, "-1.234567e+6f");
+  BUF_INSPECT_TEST_F32(0.0f, "(F32) 0.0");
+  BUF_INSPECT_TEST_F32(0.1f, "(F32) 1.0e-1");
+  BUF_INSPECT_TEST_F32(0.1234567f, "(F32) 1.234567e-1");
+  BUF_INSPECT_TEST_F32(1.234567f, "(F32) 1.234567");
+  BUF_INSPECT_TEST_F32(1234567.0f, "(F32) 1.234567e+6");
+  BUF_INSPECT_TEST_F32(-0.1f, "(F32) -1.0e-1");
+  BUF_INSPECT_TEST_F32(-0.1234567f, "(F32) -1.234567e-1");
+  BUF_INSPECT_TEST_F32(-1.234567f, "(F32) -1.234567");
+  BUF_INSPECT_TEST_F32(-1234567.0f, "(F32) -1.234567e+6");
 }
 TEST_CASE_END(buf_inspect_f32)
 
 TEST_CASE(buf_inspect_f64)
 {
-  BUF_INSPECT_TEST_F64(0.0, "0.0");
-  BUF_INSPECT_TEST_F64(0.1, "1.0e-1");
-  BUF_INSPECT_TEST_F64(0.123456789, "1.23456788999999e-1");
-  BUF_INSPECT_TEST_F64(1.23456789, "1.23456788999999");
-  BUF_INSPECT_TEST_F64(123456789.0, "1.23456789e+8");
-  BUF_INSPECT_TEST_F64(-0.1, "-1.0e-1");
-  BUF_INSPECT_TEST_F64(-0.123456789, "-1.23456788999999e-1");
-  BUF_INSPECT_TEST_F64(-1.23456789, "-1.23456788999999");
-  BUF_INSPECT_TEST_F64(-123456789.0, "-1.23456789e+8");
+  BUF_INSPECT_TEST_F64(0.0, "(F64) 0.0");
+  BUF_INSPECT_TEST_F64(0.1, "(F64) 1.0e-1");
+  BUF_INSPECT_TEST_F64(0.123456789, "(F64) 1.23456788999999e-1");
+  BUF_INSPECT_TEST_F64(1.23456789, "(F64) 1.23456788999999");
+  BUF_INSPECT_TEST_F64(123456789.0, "(F64) 1.23456789e+8");
+  BUF_INSPECT_TEST_F64(-0.1, "(F64) -1.0e-1");
+  BUF_INSPECT_TEST_F64(-0.123456789, "(F64) -1.23456788999999e-1");
+  BUF_INSPECT_TEST_F64(-1.23456789, "(F64) -1.23456788999999");
+  BUF_INSPECT_TEST_F64(-123456789.0, "(F64) -1.23456789e+8");
 }
 TEST_CASE_END(buf_inspect_f64)
 
+TEST_CASE(buf_inspect_f128)
+{
+  BUF_INSPECT_TEST_F128(0.0, "(F128) 0.0");
+  BUF_INSPECT_TEST_F128(0.1, "(F128) 1.0e-1");
+  BUF_INSPECT_TEST_F128(0.123456789, "(F128) 1.23456788999999e-1");
+  BUF_INSPECT_TEST_F128(1.23456789, "(F128) 1.23456788999999");
+  BUF_INSPECT_TEST_F128(123456789.0, "(F128) 1.23456789e+8");
+  BUF_INSPECT_TEST_F128(-0.1, "(F128) -1.0e-1");
+  BUF_INSPECT_TEST_F128(-0.123456789, "(F128) -1.23456788999999e-1");
+  BUF_INSPECT_TEST_F128(-1.23456789, "(F128) -1.23456788999999");
+  BUF_INSPECT_TEST_F128(-123456789.0, "(F128) -1.23456789e+8");
+}
+TEST_CASE_END(buf_inspect_f128)
+
 TEST_CASE(buf_inspect_integer)
 {
   BUF_INSPECT_TEST_INTEGER("0", "0");
@@ -401,8 +434,9 @@ TEST_CASE(buf_inspect_tag)
   BUF_INSPECT_TEST_TAG(tag_bool(&tag, false), "false");
   BUF_INSPECT_TEST_TAG(tag_bool(&tag, true), "true");
   BUF_INSPECT_TEST_TAG(tag_character(&tag, '\n'), "'\\n'");
-  BUF_INSPECT_TEST_TAG(tag_f32(&tag, 1.0f), "1.0f");
-  BUF_INSPECT_TEST_TAG(tag_f64(&tag, 1.0), "1.0");
+  BUF_INSPECT_TEST_TAG(tag_f32(&tag, 1.0f), "(F32) 1.0");
+  BUF_INSPECT_TEST_TAG(tag_f64(&tag, 1.0), "(F64) 1.0");
+  BUF_INSPECT_TEST_TAG(tag_f128(&tag, 1.0), "(F128) 1.0");
   BUF_INSPECT_TEST_TAG(tag_ident_1(&tag, "ident"), "ident");
   BUF_INSPECT_TEST_TAG(tag_integer_1(&tag, "-0x10000000000000000"), "-18446744073709551616");
   BUF_INSPECT_TEST_TAG(tag_integer_1(&tag, "0x10000000000000000"), "18446744073709551616");
diff --git a/test/ikc3/equal.kc3 b/test/ikc3/equal.kc3
index ef41d93..1e3b58e 100644
--- a/test/ikc3/equal.kc3
+++ b/test/ikc3/equal.kc3
@@ -10,7 +10,7 @@ quote {1, 2} = {f, g}
 {1, 2} = {f, g}
 quote ? = 1
 ? = 1
-quote to_lisp(quote a = 1 && b = 2)
-to_lisp(quote a = 1 && b = 2)
-quote if (a = 1 && b = 2) do {a, b} end
-if (a = 1 && b = 2) do {a, b} end
+quote to_lisp(quote (a = 1) && (b = 2))
+to_lisp(quote (a = 1) && (b = 2))
+quote if (a = 1) && (b = 2) do {a, b} end
+if (a = 1) && (b = 2) do {a, b} end
diff --git a/test/ikc3/gl.out.expected b/test/ikc3/gl.out.expected
index 2f9884b..d87627a 100644
--- a/test/ikc3/gl.out.expected
+++ b/test/ikc3/gl.out.expected
@@ -1,19 +1,19 @@
 %GL.Vec2{}
-%GL.Vec2{x: 0.0f,
-         y: 0.0f}
+%GL.Vec2{x: (F32) 0.0,
+         y: (F32) 0.0}
 %GL.Vec3{}
-%GL.Vec3{x: 0.0f,
-         y: 0.0f,
-         z: 0.0f}
+%GL.Vec3{x: (F32) 0.0,
+         y: (F32) 0.0,
+         z: (F32) 0.0}
 %GL.Vertex{}
-%GL.Vertex{position: %GL.Vec3{x: 0.0f,
-                              y: 0.0f,
-                              z: 0.0f},
-           normal: %GL.Vec3{x: 0.0f,
-                            y: 0.0f,
-                            z: 0.0f},
-           tex_coord: %GL.Vec2{x: 0.0f,
-                               y: 0.0f}}
+%GL.Vertex{position: %GL.Vec3{x: (F32) 0.0,
+                              y: (F32) 0.0,
+                              z: (F32) 0.0},
+           normal: %GL.Vec3{x: (F32) 0.0,
+                            y: (F32) 0.0,
+                            z: (F32) 0.0},
+           tex_coord: %GL.Vec2{x: (F32) 0.0,
+                               y: (F32) 0.0}}
 %GL.Triangle{}
 %GL.Triangle{a: (U32) 0,
              b: (U32) 1,
diff --git a/test/ikc3/struct.out.expected b/test/ikc3/struct.out.expected
index 2cbc357..beb508b 100644
--- a/test/ikc3/struct.out.expected
+++ b/test/ikc3/struct.out.expected
@@ -1,17 +1,17 @@
-0.0
-0.0
+(F128) 0.0
+(F128) 0.0
 %GL.Vec3{}
-%GL.Vec3{x: 0.0f,
-         y: 0.0f,
-         z: 0.0f}
+%GL.Vec3{x: (F32) 0.0,
+         y: (F32) 0.0,
+         z: (F32) 0.0}
 [position: %GL.Vec3{},
  normal: %GL.Vec3{},
  tex_coord: %GL.Vec2{}]
-[position: %GL.Vec3{x: 0.0f,
-                    y: 0.0f,
-                    z: 0.0f},
- normal: %GL.Vec3{x: 0.0f,
-                  y: 0.0f,
-                  z: 0.0f},
- tex_coord: %GL.Vec2{x: 0.0f,
-                     y: 0.0f}]
+[position: %GL.Vec3{x: (F32) 0.0,
+                    y: (F32) 0.0,
+                    z: (F32) 0.0},
+ normal: %GL.Vec3{x: (F32) 0.0,
+                  y: (F32) 0.0,
+                  z: (F32) 0.0},
+ tex_coord: %GL.Vec2{x: (F32) 0.0,
+                     y: (F32) 0.0}]