Commit eacb0f1d17cd428449ab549b0752f9bc90704011

Thomas de Grivel 2024-10-26T12:52:01

test Str.random_base64

diff --git a/.ikc3_history b/.ikc3_history
index a1725c1..ea2c169 100644
--- a/.ikc3_history
+++ b/.ikc3_history
@@ -1,7 +1,3 @@
-a = Facts.env_db()
-(Facts) a
-db = ^ a
-(Facts) db
 Facts.with(db, [[KC3, :operator, op = ?], [op, :sym, sym = ?]], fn (fact) { puts("#{op} #{sym}") })
 op
 sym
@@ -97,3 +93,7 @@ hash = Crypt.sha512("Plop", "$6$rounds=1234$abc0123456789$")
 h2 = Crypt.sha512("Plop", hash)
 h2 = Crypt.sha512("Plop2", hash)
 Crypt.sha512_hash_password("Plop")
+Str.random_base64(1)
+Str.random_base64(2)
+Str.size(Str.random_base64(2))
+Str.size(Str.random_base64(1))
diff --git a/libkc3/str.c b/libkc3/str.c
index e75c21e..8c4002e 100644
--- a/libkc3/str.c
+++ b/libkc3/str.c
@@ -587,7 +587,7 @@ DEF_STR_INIT_STRUCT(map)
 DEF_STR_INIT_PTR(ptr, const u_ptr_w *)
 DEF_STR_INIT_PTR(ptr_free, const u_ptr_w *)
 
-s_str * str_init_random_base64 (const s_tag *len, s_str *dest)
+s_str * str_init_random_base64 (s_str *str, const s_tag *len)
 {
   const s_sym *type;
   char *random_bytes;
@@ -651,7 +651,7 @@ s_str * str_init_random_base64 (const s_tag *len, s_str *dest)
     }
   }
   free(random_bytes);
-  return str_init(dest, result, result_len, result);
+  return str_init(str, result, result_len, result);
 }
 
 DEF_STR_INIT_INT(s8)
diff --git a/libkc3/str.h b/libkc3/str.h
index f96d5e6..d87e350 100644
--- a/libkc3/str.h
+++ b/libkc3/str.h
@@ -62,7 +62,7 @@ PROTOTYPE_STR_INIT(list, const s_list * const *);
 PROTOTYPE_STR_INIT_STRUCT(map);
 PROTOTYPE_STR_INIT(ptr, const u_ptr_w *);
 PROTOTYPE_STR_INIT(ptr_free, const u_ptr_w *);
-s_str * str_init_random_base64 (const s_tag *len, s_str *dest);
+s_str * str_init_random_base64 (s_str *str, const s_tag *len);
 PROTOTYPE_STR_INIT_INT(s8);
 PROTOTYPE_STR_INIT_INT(s16);
 PROTOTYPE_STR_INIT_INT(s32);
diff --git a/test/ikc3/str.kc3 b/test/ikc3/str.kc3
index fd08880..ac916bb 100644
--- a/test/ikc3/str.kc3
+++ b/test/ikc3/str.kc3
@@ -78,3 +78,9 @@ quote "#{(U8[]) {{0, 0}, {0, 0}, {0, 0}}}"
 "#{(U8[]) {{0, 0}, {0, 0}, {0, 0}}}"
 quote "#{%Socket.Buf{}}"
 "#{%Socket.Buf{}}"
+quote Str.size(Str.random_base64(1))
+Str.size(Str.random_base64(1))
+quote Str.size(Str.random_base64(2))
+Str.size(Str.random_base64(2))
+quote Str.size(Str.random_base64(64))
+Str.size(Str.random_base64(64))
diff --git a/test/ikc3/str.out.expected b/test/ikc3/str.out.expected
index 66509b8..d55a9a9 100644
--- a/test/ikc3/str.out.expected
+++ b/test/ikc3/str.out.expected
@@ -66,3 +66,9 @@
 "(U8[]) {{0, 0},\n        {0, 0},\n        {0, 0}}"
 "#{%Socket.Buf{}}"
 "%Socket.Buf{addr: (Ptr) 0x0,\n            addr_len: (U32) 0,\n            addr_str: \"\",\n            sockfd: (S32) -1,\n            buf_rw: %BufRW{r: (Ptr) 0x0,\n                           w: (Ptr) 0x0}}"
+Str.size(Str.random_base64(1))
+1
+Str.size(Str.random_base64(2))
+2
+Str.size(Str.random_base64(64))
+64