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