ref: 75f5c7d3948bc647b21272c2e0bcbf841fb4d9f7
parent: f9f95b10dfcda3981a820a24e7929af6afbebad0
author: Ori Bernstein <[email protected]>
date: Mon May 30 11:05:19 EDT 2022
strchr: add tests (thanks amavect)
--- a/libc/mkfile
+++ b/libc/mkfile
@@ -3,6 +3,7 @@
TEST=\
date\
pow\
+ strchr\
zones\
<../regress
--- /dev/null
+++ b/libc/strchr.c
@@ -1,0 +1,47 @@
+#include <u.h>
+#include <libc.h>
+void
+chars(void)
+{
+ char *z = "";
+ char *v = "foo bar ss";
+ char *e;
+
+ e = strchr(z, 0);
+ assert(e == z);
+ e = strchr(z, 'z');
+ assert(e == nil);
+ e = strchr(v, L'z');
+ assert(e == nil);
+ e = strchr(v, L'a');
+ assert(e == v+5);
+ e = strchr(v, 0);
+ assert(e == v+10);
+}
+
+void
+runes(void)
+{
+ Rune *z = L"";
+ Rune *c = L"foo βαρ ß";
+ Rune *e;
+
+ e = runestrchr(z, 0);
+ assert(e == z);
+ e = runestrchr(z, L'z');
+ assert(e == nil);
+ e = runestrchr(c, L'z');
+ assert(e == nil);
+ e = runestrchr(c, L'α');
+ assert(e == c+5);
+ e = runestrchr(c, 0);
+ assert(e == c+9);
+}
+
+void
+main(void)
+{
+ chars();
+ runes();
+ exits(nil);
+}