aboutsummaryrefslogtreecommitdiffstats
path: root/strrncasestr.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--strrncasestr.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/strrncasestr.c b/strrncasestr.c
index 8fb0778..f1874c7 100644
--- a/strrncasestr.c
+++ b/strrncasestr.c
@@ -1,5 +1,6 @@
/* See LICENSE file for copyright and license details. */
#include "libsimple.h"
+#ifndef TEST
char *
@@ -21,3 +22,66 @@ libsimple_strrncasestr(const char *h_, const char *n, size_t len)
return h;
return NULL;
}
+
+
+#else
+#include "test.h"
+
+int
+main(void)
+{
+ assert(!strcmpnul(libsimple_strrncasestr("", "", 10), ""));
+ assert(!strcmpnul(libsimple_strrncasestr("test", "", 10), ""));
+ assert(!libsimple_strrncasestr("", "test", 10));
+ assert(!libsimple_strrncasestr("t", "test", 10));
+ assert(!strcmpnul(libsimple_strrncasestr("test", "t", 10), "t"));
+ assert(!strcmpnul(libsimple_strrncasestr("test", "e", 10), "est"));
+ assert(!strcmpnul(libsimple_strrncasestr("test", "s", 10), "st"));
+ assert(!libsimple_strrncasestr("test", "x", 10));
+ assert(!strcmpnul(libsimple_strrncasestr("test", "te", 10), "test"));
+ assert(!strcmpnul(libsimple_strrncasestr("test", "es", 10), "est"));
+ assert(!strcmpnul(libsimple_strrncasestr("test", "st", 10), "st"));
+ assert(!libsimple_strrncasestr("test", "xx", 10));
+ assert(!strcmpnul(libsimple_strrncasestr("abc", "c", 10), "c"));
+ assert(!strcmpnul(libsimple_strrncasestr("abc", "bc", 10), "bc"));
+ assert(!strcmpnul(libsimple_strrncasestr("abc", "abc", 10), "abc"));
+ assert(!strcmpnul(libsimple_strrncasestr("abcabc", "bc", 10), "bc"));
+
+ assert(!strcmpnul(libsimple_strrncasestr("TEST", "", 10), ""));
+ assert(!libsimple_strrncasestr("T", "test", 10));
+ assert(!strcmpnul(libsimple_strrncasestr("TEST", "t", 10), "T"));
+ assert(!strcmpnul(libsimple_strrncasestr("TEST", "e", 10), "EST"));
+ assert(!strcmpnul(libsimple_strrncasestr("TEST", "s", 10), "ST"));
+ assert(!libsimple_strrncasestr("TEST", "x", 10));
+ assert(!strcmpnul(libsimple_strrncasestr("TEST", "te", 10), "TEST"));
+ assert(!strcmpnul(libsimple_strrncasestr("TEST", "es", 10), "EST"));
+ assert(!strcmpnul(libsimple_strrncasestr("TEST", "st", 10), "ST"));
+ assert(!libsimple_strrncasestr("TEST", "xx", 10));
+ assert(!strcmpnul(libsimple_strrncasestr("ABC", "c", 10), "C"));
+ assert(!strcmpnul(libsimple_strrncasestr("ABC", "bc", 10), "BC"));
+ assert(!strcmpnul(libsimple_strrncasestr("ABC", "abc", 10), "ABC"));
+ assert(!strcmpnul(libsimple_strrncasestr("ABCABC", "bc", 10), "BC"));
+
+ assert(!libsimple_strrncasestr("", "TEST", 10));
+ assert(!libsimple_strrncasestr("t", "TEST", 10));
+ assert(!strcmpnul(libsimple_strrncasestr("test", "T", 10), "t"));
+ assert(!strcmpnul(libsimple_strrncasestr("test", "E", 10), "est"));
+ assert(!strcmpnul(libsimple_strrncasestr("test", "S", 10), "st"));
+ assert(!libsimple_strrncasestr("test", "X", 10));
+ assert(!strcmpnul(libsimple_strrncasestr("test", "TE", 10), "test"));
+ assert(!strcmpnul(libsimple_strrncasestr("test", "ES", 10), "est"));
+ assert(!strcmpnul(libsimple_strrncasestr("test", "ST", 10), "st"));
+ assert(!libsimple_strrncasestr("test", "XX", 10));
+ assert(!strcmpnul(libsimple_strrncasestr("abc", "C", 10), "c"));
+ assert(!strcmpnul(libsimple_strrncasestr("abc", "BC", 10), "bc"));
+ assert(!strcmpnul(libsimple_strrncasestr("abc", "ABC", 10), "abc"));
+ assert(!strcmpnul(libsimple_strrncasestr("abcabc", "BC", 10), "bc"));
+
+ assert(!libsimple_strrncasestr("abcdefgh", "def", 2));
+ assert(!libsimple_strrncasestr("abcdefgh", "DEF", 2));
+ assert(!libsimple_strrncasestr("ABCDEFGH", "def", 2));
+
+ return 0;
+}
+
+#endif