diff --git a/test/ref/strtok.c b/test/ref/strtok.c new file mode 100644 index 000000000..15c3a289d --- /dev/null +++ b/test/ref/strtok.c @@ -0,0 +1,43 @@ +// 2024-02-14 Sven Michael Klose + +#include +#include +#include + +void +error (void) +{ + printf ("strtok() test failed!\n"); + exit (-1); +} + +void +test (char * s) +{ + if (strcmp ("test", strtok (s, "/"))) + error (); + if (strcmp ("foo", strtok (NULL, "/"))) + error (); + if (strcmp ("bar", strtok (NULL, "/"))) + error (); + if (strtok (NULL, "/")) + error (); + if (strtok (NULL, "/")) + error (); +} + +int +main (void) +{ + char s1[] = "test/foo/bar"; + char s2[] = "/test/foo/bar"; + char s3[] = "//test/foo/bar"; + char s4[] = "//test/foo/bar//"; + + test (s1); + test (s2); + test (s3); + test (s4); + + return 0; +}