aboutsummaryrefslogtreecommitdiff
path: root/lib/test/string.c
diff options
context:
space:
mode:
authoraqua <aqua@iserlohn-fortress.net>2022-07-28 11:13:12 +0300
committeraqua <aqua@iserlohn-fortress.net>2022-08-12 10:14:00 +0300
commitc362ff8e900d5ef97eb417d951a0dd71941386d2 (patch)
tree44dd6a2ac7bd4cfcf7fb589c116c744b539fa6f5 /lib/test/string.c
parentEnable coverage report (diff)
downloadkernel-c362ff8e900d5ef97eb417d951a0dd71941386d2.tar.xz
Add libk tests
Diffstat (limited to 'lib/test/string.c')
-rw-r--r--lib/test/string.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/test/string.c b/lib/test/string.c
new file mode 100644
index 0000000..725d547
--- /dev/null
+++ b/lib/test/string.c
@@ -0,0 +1,34 @@
+#include "../string.h"
+#include <assert.h>
+
+static const char *dec = "12341234";
+static const char *neg_dec = "-12341234";
+static const char *u32_hex = "decafade";
+static const char *i32_hex = "7fffffff";
+static char buffer[64];
+
+int
+main()
+{
+ { // utoa
+ char *r;
+
+ r = utoa(buffer, 12341234u, 10);
+ for (unsigned i = 0; dec[i] != '\0'; ++i) assert(r[i] == dec[i]);
+
+ r = utoa(buffer, 0xdecafade, 16);
+ for (unsigned i = 0; u32_hex[i] != '\0'; ++i) assert(r[i] == u32_hex[i]);
+ }
+ { // itoa
+ char *r;
+
+ r = itoa(buffer, 12341234, 10);
+ for (unsigned i = 0; dec[i] != '\0'; ++i) assert(r[i] == dec[i]);
+
+ r = itoa(buffer, -12341234, 10);
+ for (unsigned i = 0; neg_dec[i] != '\0'; ++i) assert(r[i] == neg_dec[i]);
+
+ r = itoa(buffer, 0x7fffffff, 16);
+ for (unsigned i = 0; i32_hex[i] != '\0'; ++i) assert(r[i] == i32_hex[i]);
+ }
+}