aboutsummaryrefslogtreecommitdiffstats
path: root/strstarts.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2018-08-12 21:35:12 +0200
committerMattias Andrée <maandree@kth.se>2018-08-12 21:35:12 +0200
commit93b8428b5812191177c790ea9ffb9158d5a296b4 (patch)
tree8e43220208a7e3b4780a49b8278e731f3b5fcbbf /strstarts.c
parentAdd DONT_DEFINE_CLOCK_MONOTONIC_RAW (diff)
downloadlibsimple-93b8428b5812191177c790ea9ffb9158d5a296b4.tar.gz
libsimple-93b8428b5812191177c790ea9ffb9158d5a296b4.tar.bz2
libsimple-93b8428b5812191177c790ea9ffb9158d5a296b4.tar.xz
Add tests
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'strstarts.c')
-rw-r--r--strstarts.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/strstarts.c b/strstarts.c
index ca44e52..f2db947 100644
--- a/strstarts.c
+++ b/strstarts.c
@@ -8,3 +8,43 @@ libsimple_strstarts(const char *s, const char *t)
for (; *t && *s == *t; s++, t++);
return !*t;
}
+
+
+#ifdef TEST
+#include <assert.h>
+
+int
+main(void)
+{
+ assert(libsimple_strstarts("", "") == 1);
+ assert(libsimple_strstarts("test", "") == 1);
+ assert(libsimple_strstarts("", "test") == 0);
+ assert(libsimple_strstarts("test", "test") == 1);
+ assert(libsimple_strstarts("test", "testx") == 0);
+ assert(libsimple_strstarts("test", "tes") == 1);
+ assert(libsimple_strstarts("test", "te") == 1);
+ assert(libsimple_strstarts("test", "t") == 1);
+ assert(libsimple_strstarts("test", "x") == 0);
+ assert(libsimple_strstarts("test", "xx") == 0);
+
+ assert(libsimple_strstarts("TEST", "") == 1);
+ assert(libsimple_strstarts("TEST", "test") == 0);
+ assert(libsimple_strstarts("TEST", "testx") == 0);
+ assert(libsimple_strstarts("TEST", "tes") == 0);
+ assert(libsimple_strstarts("TEST", "te") == 0);
+ assert(libsimple_strstarts("TEST", "t") == 0);
+ assert(libsimple_strstarts("TEST", "x") == 0);
+ assert(libsimple_strstarts("TEST", "xx") == 0);
+
+ assert(libsimple_strstarts("", "TEST") == 0);
+ assert(libsimple_strstarts("test", "TEST") == 0);
+ assert(libsimple_strstarts("test", "TESTX") == 0);
+ assert(libsimple_strstarts("test", "TES") == 0);
+ assert(libsimple_strstarts("test", "TE") == 0);
+ assert(libsimple_strstarts("test", "T") == 0);
+ assert(libsimple_strstarts("test", "X") == 0);
+ assert(libsimple_strstarts("test", "XX") == 0);
+ return 0;
+}
+
+#endif