Commit cdc4416f454bee0280bc4c7b9352b9cf848f4237

Thomas de Grivel 2024-07-27T20:40:49

buf_inspect_s, buf_inspect_u: print cast when necessary

diff --git a/.ikc3_history b/.ikc3_history
index 83f57e0..7fcccce 100644
--- a/.ikc3_history
+++ b/.ikc3_history
@@ -1,4 +1,3 @@
-a
 module()
 defmodule Plop do
   def m = fn () { module() }
@@ -97,3 +96,4 @@ defmodule Socket do
 dlopen("lib/kc3/0.1/http.so")
 def connect = cfn Socket.Buf "socket_buf_init_connect" (Result, Str, Str)
 end
+22
diff --git a/test/buf_inspect_test.c b/test/buf_inspect_test.c
index 010f777..dad0066 100644
--- a/test/buf_inspect_test.c
+++ b/test/buf_inspect_test.c
@@ -205,7 +205,7 @@ TEST_CASE(buf_inspect_array)
                          "(U8[]) {0}");
   BUF_INSPECT_TEST_ARRAY("(U8[]){{0, 1}, {2, 3}}",
                          "(U8[]) {{0, 1}, {2, 3}}");
-  BUF_INSPECT_TEST_ARRAY("(U8[]) { { { 0 , 1 } , {2 , 3 } } , { { 4 , 5 } , { 6 , 7 } } }",
+  BUF_INSPECT_TEST_ARRAY("(U8[]){ { { 0 , 1 } , {2 , 3 } } , { { 4 , 5 } , { 6 , 7 } } }",
                          "(U8[]) {{{0, 1}, {2, 3}}, {{4, 5}, {6, 7}}}");
 }
 TEST_CASE_END(buf_inspect_array)
@@ -390,21 +390,21 @@ TEST_CASE(buf_inspect_tag)
   BUF_INSPECT_TEST_TAG(tag_list(&tag, NULL), "[]");
   BUF_INSPECT_TEST_TAG(tag_list_1(&tag, "[[] | []]"), "[[]]");
   BUF_INSPECT_TEST_TAG(tag_list_1(&tag, "[]"), "[]");
-  BUF_INSPECT_TEST_TAG(tag_s16(&tag, -0x100), "-256");
-  BUF_INSPECT_TEST_TAG(tag_s32(&tag, -0x10000), "-65536");
-  BUF_INSPECT_TEST_TAG(tag_s64(&tag, -0x100000000), "-4294967296");
-  BUF_INSPECT_TEST_TAG(tag_s8(&tag, -1), "-1");
-  BUF_INSPECT_TEST_TAG(tag_s8(&tag, -10), "-10");
+  BUF_INSPECT_TEST_TAG(tag_s16(&tag, -0x100), "(S16) -256");
+  BUF_INSPECT_TEST_TAG(tag_s32(&tag, -0x10000), "(S32) -65536");
+  BUF_INSPECT_TEST_TAG(tag_s64(&tag, -0x100000000), "(S64) -4294967296");
+  BUF_INSPECT_TEST_TAG(tag_s8(&tag, -1), "(S8) -1");
+  BUF_INSPECT_TEST_TAG(tag_s8(&tag, -10), "(S8) -10");
   BUF_INSPECT_TEST_TAG(tag_str(&tag, NULL, 0, ""), "\"\"");
   BUF_INSPECT_TEST_TAG(tag_str_1(&tag, NULL, ""), "\"\"");
   BUF_INSPECT_TEST_TAG(tag_str_1(&tag, NULL, "09AZaz"), "\"09AZaz\"");
   BUF_INSPECT_TEST_TAG(tag_sym(&tag, sym_1("Module")), "Module");
-  BUF_INSPECT_TEST_TAG(tag_u16(&tag, 0x100), "256");
-  BUF_INSPECT_TEST_TAG(tag_u32(&tag, 0x10000), "65536");
-  BUF_INSPECT_TEST_TAG(tag_u64(&tag, 0x100000000), "4294967296");
-  BUF_INSPECT_TEST_TAG(tag_u8(&tag, 0), "0");
-  BUF_INSPECT_TEST_TAG(tag_u8(&tag, 1), "1");
-  BUF_INSPECT_TEST_TAG(tag_u8(&tag, 10), "10");
+  BUF_INSPECT_TEST_TAG(tag_u16(&tag, 0x100), "(U16) 256");
+  BUF_INSPECT_TEST_TAG(tag_u32(&tag, 0x10000), "(U32) 65536");
+  BUF_INSPECT_TEST_TAG(tag_u64(&tag, 0x100000000), "(U64) 4294967296");
+  BUF_INSPECT_TEST_TAG(tag_u8(&tag, 0), "(U8) 0");
+  BUF_INSPECT_TEST_TAG(tag_u8(&tag, 1), "(U8) 1");
+  BUF_INSPECT_TEST_TAG(tag_u8(&tag, 10), "(U8) 10");
   BUF_INSPECT_TEST_TAG(tag_void(&tag), "void");
   tag_clean(&tag);
 }
diff --git a/test/facts_test.c b/test/facts_test.c
index 9663d71..acfb04a 100644
--- a/test/facts_test.c
+++ b/test/facts_test.c
@@ -467,7 +467,7 @@ TEST_CASE(facts_open_file)
   }
   facts_init(&facts);
   str_init_1(&path, NULL, "facts_test_open_file.1.facts");
-  TEST_EQ(facts_open_file(&facts, &path), 761);
+  TEST_EQ(facts_open_file(&facts, &path), 944);
   TEST_EQ(facts_count(&facts), 23);
   i = 0;
   while (p[i]) {
diff --git a/test/facts_test_dump_file.expected.facts b/test/facts_test_dump_file.expected.facts
index 19ea675..23008e1 100644
--- a/test/facts_test_dump_file.expected.facts
+++ b/test/facts_test_dump_file.expected.facts
@@ -1,17 +1,17 @@
 %{module: KC3.Facts.Dump,
   version: 1}
 add {-18446744073709551616, -18446744073709551616, -18446744073709551616}
-add {-4294967296, -4294967296, -4294967296}
-add {-65536, -65536, -65536}
-add {-256, -256, -256}
-add {-10, -10, -10}
-add {-1, -1, -1}
-add {0, 0, 0}
-add {1, 1, 1}
-add {10, 10, 10}
-add {256, 256, 256}
-add {65536, 65536, 65536}
-add {4294967296, 4294967296, 4294967296}
+add {(S64) -4294967296, (S64) -4294967296, (S64) -4294967296}
+add {(S32) -65536, (S32) -65536, (S32) -65536}
+add {(S16) -256, (S16) -256, (S16) -256}
+add {(S8) -10, (S8) -10, (S8) -10}
+add {(S8) -1, (S8) -1, (S8) -1}
+add {(U8) 0, (U8) 0, (U8) 0}
+add {(U8) 1, (U8) 1, (U8) 1}
+add {(U8) 10, (U8) 10, (U8) 10}
+add {(U16) 256, (U16) 256, (U16) 256}
+add {(U32) 65536, (U32) 65536, (U32) 65536}
+add {(U64) 4294967296, (U64) 4294967296, (U64) 4294967296}
 add {18446744073709551616, 18446744073709551616, 18446744073709551616}
 add {[], [], []}
 add {[[], []], [[], []], [[], []]}
diff --git a/test/facts_test_log_add.expected.facts b/test/facts_test_log_add.expected.facts
index 5286f7a..6930e1d 100644
--- a/test/facts_test_log_add.expected.facts
+++ b/test/facts_test_log_add.expected.facts
@@ -8,16 +8,16 @@ add {{:a, :b}, {:a, :b}, {:a, :b}}
 add {{{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}}
 add {{a, b}, {a, b}, {a, b}}
 add {{{a, b}, {c, d}}, {{a, b}, {c, d}}, {{a, b}, {c, d}}}
-add {0, 0, 0}
-add {1, 1, 1}
-add {10, 10, 10}
-add {256, 256, 256}
-add {65536, 65536, 65536}
-add {4294967296, 4294967296, 4294967296}
+add {(U8) 0, (U8) 0, (U8) 0}
+add {(U8) 1, (U8) 1, (U8) 1}
+add {(U8) 10, (U8) 10, (U8) 10}
+add {(U16) 256, (U16) 256, (U16) 256}
+add {(U32) 65536, (U32) 65536, (U32) 65536}
+add {(U64) 4294967296, (U64) 4294967296, (U64) 4294967296}
 add {18446744073709551616, 18446744073709551616, 18446744073709551616}
-add {-1, -1, -1}
-add {-10, -10, -10}
-add {-256, -256, -256}
-add {-65536, -65536, -65536}
-add {-4294967296, -4294967296, -4294967296}
+add {(S8) -1, (S8) -1, (S8) -1}
+add {(S8) -10, (S8) -10, (S8) -10}
+add {(S16) -256, (S16) -256, (S16) -256}
+add {(S32) -65536, (S32) -65536, (S32) -65536}
+add {(S64) -4294967296, (S64) -4294967296, (S64) -4294967296}
 add {-18446744073709551616, -18446744073709551616, -18446744073709551616}
diff --git a/test/facts_test_log_remove.expected.facts b/test/facts_test_log_remove.expected.facts
index f96c838..068f723 100644
--- a/test/facts_test_log_remove.expected.facts
+++ b/test/facts_test_log_remove.expected.facts
@@ -8,32 +8,32 @@ add {{:a, :b}, {:a, :b}, {:a, :b}}
 add {{{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}}
 add {{a, b}, {a, b}, {a, b}}
 add {{{a, b}, {c, d}}, {{a, b}, {c, d}}, {{a, b}, {c, d}}}
-add {0, 0, 0}
-add {1, 1, 1}
-add {10, 10, 10}
-add {256, 256, 256}
-add {65536, 65536, 65536}
-add {4294967296, 4294967296, 4294967296}
+add {(U8) 0, (U8) 0, (U8) 0}
+add {(U8) 1, (U8) 1, (U8) 1}
+add {(U8) 10, (U8) 10, (U8) 10}
+add {(U16) 256, (U16) 256, (U16) 256}
+add {(U32) 65536, (U32) 65536, (U32) 65536}
+add {(U64) 4294967296, (U64) 4294967296, (U64) 4294967296}
 add {18446744073709551616, 18446744073709551616, 18446744073709551616}
-add {-1, -1, -1}
-add {-10, -10, -10}
-add {-256, -256, -256}
-add {-65536, -65536, -65536}
-add {-4294967296, -4294967296, -4294967296}
+add {(S8) -1, (S8) -1, (S8) -1}
+add {(S8) -10, (S8) -10, (S8) -10}
+add {(S16) -256, (S16) -256, (S16) -256}
+add {(S32) -65536, (S32) -65536, (S32) -65536}
+add {(S64) -4294967296, (S64) -4294967296, (S64) -4294967296}
 add {-18446744073709551616, -18446744073709551616, -18446744073709551616}
 remove {-18446744073709551616, -18446744073709551616, -18446744073709551616}
-remove {-4294967296, -4294967296, -4294967296}
-remove {-65536, -65536, -65536}
-remove {-256, -256, -256}
-remove {-10, -10, -10}
-remove {-1, -1, -1}
+remove {(S64) -4294967296, (S64) -4294967296, (S64) -4294967296}
+remove {(S32) -65536, (S32) -65536, (S32) -65536}
+remove {(S16) -256, (S16) -256, (S16) -256}
+remove {(S8) -10, (S8) -10, (S8) -10}
+remove {(S8) -1, (S8) -1, (S8) -1}
 remove {18446744073709551616, 18446744073709551616, 18446744073709551616}
-remove {4294967296, 4294967296, 4294967296}
-remove {65536, 65536, 65536}
-remove {256, 256, 256}
-remove {10, 10, 10}
-remove {1, 1, 1}
-remove {0, 0, 0}
+remove {(U64) 4294967296, (U64) 4294967296, (U64) 4294967296}
+remove {(U32) 65536, (U32) 65536, (U32) 65536}
+remove {(U16) 256, (U16) 256, (U16) 256}
+remove {(U8) 10, (U8) 10, (U8) 10}
+remove {(U8) 1, (U8) 1, (U8) 1}
+remove {(U8) 0, (U8) 0, (U8) 0}
 remove {{{a, b}, {c, d}}, {{a, b}, {c, d}}, {{a, b}, {c, d}}}
 remove {{a, b}, {a, b}, {a, b}}
 remove {{{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}}
diff --git a/test/facts_test_open_file.1.expected.facts b/test/facts_test_open_file.1.expected.facts
index 3b9a294..86d47e7 100644
--- a/test/facts_test_open_file.1.expected.facts
+++ b/test/facts_test_open_file.1.expected.facts
@@ -3,17 +3,17 @@
 add {a, a, a}
 add {-18446744073709551616, -18446744073709551616, -18446744073709551616}
 add {18446744073709551616, 18446744073709551616, 18446744073709551616}
-add {-4294967296, -4294967296, -4294967296}
-add {-65536, -65536, -65536}
-add {-256, -256, -256}
-add {-10, -10, -10}
-add {-1, -1, -1}
-add {0, 0, 0}
-add {1, 1, 1}
-add {10, 10, 10}
-add {256, 256, 256}
-add {65536, 65536, 65536}
-add {4294967296, 4294967296, 4294967296}
+add {(S64) -4294967296, (S64) -4294967296, (S64) -4294967296}
+add {(S32) -65536, (S32) -65536, (S32) -65536}
+add {(S16) -256, (S16) -256, (S16) -256}
+add {(S8) -10, (S8) -10, (S8) -10}
+add {(S8) -1, (S8) -1, (S8) -1}
+add {(U8) 0, (U8) 0, (U8) 0}
+add {(U8) 1, (U8) 1, (U8) 1}
+add {(U8) 10, (U8) 10, (U8) 10}
+add {(U16) 256, (U16) 256, (U16) 256}
+add {(U32) 65536, (U32) 65536, (U32) 65536}
+add {(U64) 4294967296, (U64) 4294967296, (U64) 4294967296}
 add {[], [], []}
 add {[[], []], [[], []], [[], []]}
 add {"a", "a", "a"}
@@ -33,18 +33,18 @@ remove {{:a, :b}, {:a, :b}, {:a, :b}}
 remove {{{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}}
 remove {{a, b}, {a, b}, {a, b}}
 remove {{{a, b}, {c, d}}, {{a, b}, {c, d}}, {{a, b}, {c, d}}}
-remove {0, 0, 0}
-remove {1, 1, 1}
-remove {10, 10, 10}
-remove {256, 256, 256}
-remove {65536, 65536, 65536}
-remove {4294967296, 4294967296, 4294967296}
+remove {(U8) 0, (U8) 0, (U8) 0}
+remove {(U8) 1, (U8) 1, (U8) 1}
+remove {(U8) 10, (U8) 10, (U8) 10}
+remove {(U16) 256, (U16) 256, (U16) 256}
+remove {(U32) 65536, (U32) 65536, (U32) 65536}
+remove {(U64) 4294967296, (U64) 4294967296, (U64) 4294967296}
 remove {18446744073709551616, 18446744073709551616, 18446744073709551616}
-remove {-1, -1, -1}
-remove {-10, -10, -10}
-remove {-256, -256, -256}
-remove {-65536, -65536, -65536}
-remove {-4294967296, -4294967296, -4294967296}
+remove {(S8) -1, (S8) -1, (S8) -1}
+remove {(S8) -10, (S8) -10, (S8) -10}
+remove {(S16) -256, (S16) -256, (S16) -256}
+remove {(S32) -65536, (S32) -65536, (S32) -65536}
+remove {(S64) -4294967296, (S64) -4294967296, (S64) -4294967296}
 remove {-18446744073709551616, -18446744073709551616, -18446744073709551616}
 add {"b", "b", "b"}
 add {:b, :b, :b}
@@ -56,16 +56,16 @@ add {{:b, :b}, {:b, :b}, {:b, :b}}
 add {{{:b, :b}, {:c, :d}}, {{:b, :b}, {:c, :d}}, {{:b, :b}, {:c, :d}}}
 add {{b, b}, {b, b}, {b, b}}
 add {{{b, b}, {c, d}}, {{b, b}, {c, d}}, {{b, b}, {c, d}}}
-add {2, 2, 2}
-add {3, 3, 3}
-add {11, 11, 11}
-add {257, 257, 257}
-add {65537, 65537, 65537}
-add {4294967297, 4294967297, 4294967297}
+add {(U8) 2, (U8) 2, (U8) 2}
+add {(U8) 3, (U8) 3, (U8) 3}
+add {(U8) 11, (U8) 11, (U8) 11}
+add {(U16) 257, (U16) 257, (U16) 257}
+add {(U32) 65537, (U32) 65537, (U32) 65537}
+add {(U64) 4294967297, (U64) 4294967297, (U64) 4294967297}
 add {18446744073709551617, 18446744073709551617, 18446744073709551617}
-add {-2, -2, -2}
-add {-11, -11, -11}
-add {-257, -257, -257}
-add {-65537, -65537, -65537}
-add {-4294967297, -4294967297, -4294967297}
+add {(S8) -2, (S8) -2, (S8) -2}
+add {(S8) -11, (S8) -11, (S8) -11}
+add {(S16) -257, (S16) -257, (S16) -257}
+add {(S32) -65537, (S32) -65537, (S32) -65537}
+add {(S64) -4294967297, (S64) -4294967297, (S64) -4294967297}
 add {-18446744073709551617, -18446744073709551617, -18446744073709551617}
diff --git a/test/facts_test_open_file.1.in.facts b/test/facts_test_open_file.1.in.facts
index d86dd0a..de9b7b6 100644
--- a/test/facts_test_open_file.1.in.facts
+++ b/test/facts_test_open_file.1.in.facts
@@ -3,17 +3,17 @@
 add {a, a, a}
 add {-18446744073709551616, -18446744073709551616, -18446744073709551616}
 add {18446744073709551616, 18446744073709551616, 18446744073709551616}
-add {-4294967296, -4294967296, -4294967296}
-add {-65536, -65536, -65536}
-add {-256, -256, -256}
-add {-10, -10, -10}
-add {-1, -1, -1}
-add {0, 0, 0}
-add {1, 1, 1}
-add {10, 10, 10}
-add {256, 256, 256}
-add {65536, 65536, 65536}
-add {4294967296, 4294967296, 4294967296}
+add {(S64) -4294967296, (S64) -4294967296, (S64) -4294967296}
+add {(S32) -65536, (S32) -65536, (S32) -65536}
+add {(S16) -256, (S16) -256, (S16) -256}
+add {(S8) -10, (S8) -10, (S8) -10}
+add {(S8) -1, (S8) -1, (S8) -1}
+add {(U8) 0, (U8) 0, (U8) 0}
+add {(U8) 1, (U8) 1, (U8) 1}
+add {(U8) 10, (U8) 10, (U8) 10}
+add {(U16) 256, (U16) 256, (U16) 256}
+add {(U32) 65536, (U32) 65536, (U32) 65536}
+add {(U64) 4294967296, (U64) 4294967296, (U64) 4294967296}
 add {[], [], []}
 add {[[], []], [[], []], [[], []]}
 add {"a", "a", "a"}
diff --git a/test/facts_test_save.expected.facts b/test/facts_test_save.expected.facts
index 19ea675..23008e1 100644
--- a/test/facts_test_save.expected.facts
+++ b/test/facts_test_save.expected.facts
@@ -1,17 +1,17 @@
 %{module: KC3.Facts.Dump,
   version: 1}
 add {-18446744073709551616, -18446744073709551616, -18446744073709551616}
-add {-4294967296, -4294967296, -4294967296}
-add {-65536, -65536, -65536}
-add {-256, -256, -256}
-add {-10, -10, -10}
-add {-1, -1, -1}
-add {0, 0, 0}
-add {1, 1, 1}
-add {10, 10, 10}
-add {256, 256, 256}
-add {65536, 65536, 65536}
-add {4294967296, 4294967296, 4294967296}
+add {(S64) -4294967296, (S64) -4294967296, (S64) -4294967296}
+add {(S32) -65536, (S32) -65536, (S32) -65536}
+add {(S16) -256, (S16) -256, (S16) -256}
+add {(S8) -10, (S8) -10, (S8) -10}
+add {(S8) -1, (S8) -1, (S8) -1}
+add {(U8) 0, (U8) 0, (U8) 0}
+add {(U8) 1, (U8) 1, (U8) 1}
+add {(U8) 10, (U8) 10, (U8) 10}
+add {(U16) 256, (U16) 256, (U16) 256}
+add {(U32) 65536, (U32) 65536, (U32) 65536}
+add {(U64) 4294967296, (U64) 4294967296, (U64) 4294967296}
 add {18446744073709551616, 18446744073709551616, 18446744073709551616}
 add {[], [], []}
 add {[[], []], [[], []], [[], []]}