t_strip_lastelem.c (1175B)
- // utils-std: Collection of commonly available Unix tools
- // SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
- // SPDX-License-Identifier: MPL-2.0
- #define _POSIX_C_SOURCE 200809L
- #include "../libutils/strip_lastelem.h"
- #include <assert.h>
- #include <stdio.h> // printf
- #include <string.h> // strcmp
- int counter = 0;
- int err = 0;
- static void
- t_strip_lastelem(const char *in, const char *exp)
- {
- int id = ++counter;
- static char buf[512];
- strcpy(buf, in);
- strip_lastelem(buf);
- if(strcmp(buf, exp) == 0)
- {
- printf("ok %d - \"%s\" -> \"%s\"\n", id, in, exp);
- return;
- }
- err = 1;
- printf("not ok %d - \"%s\" -> \"%s\"\n", id, in, exp);
- printf("# Got: \"%s\"\n", buf);
- }
- int
- main(void)
- {
- int plan = 11;
- printf("1..%d\n", plan);
- t_strip_lastelem("", "");
- t_strip_lastelem("/", "");
- t_strip_lastelem("//", "");
- t_strip_lastelem("/foo", "");
- t_strip_lastelem("/foo/", "");
- t_strip_lastelem("/foo/bar", "/foo/");
- t_strip_lastelem("/foo/bar/", "/foo/");
- t_strip_lastelem("a", "");
- t_strip_lastelem("a/", "");
- t_strip_lastelem("a/b", "a/");
- t_strip_lastelem("a/b/", "a/");
- assert(counter == plan);
- return err;
- }