chiark / gitweb /
Mini-mode now hides/shows tab group widget and has a separate label
[disorder] / libtests / t-filepart.c
1
2 /*
3  * This file is part of DisOrder.
4  * Copyright (C) 2005, 2007, 2008 Richard Kettlewell
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  * 
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 #include "test.h"
20
21 #define check_filepart(PATH, DIR, BASE) do {            \
22   char *d = d_dirname(PATH), *b = d_basename(PATH);     \
23                                                         \
24   if(strcmp(d, DIR)) {                                  \
25     fprintf(stderr, "%s:%d: d_dirname failed:\n"        \
26             "    path: %s\n"                            \
27             "     got: %s\n"                            \
28             "expected: %s\n",                           \
29             __FILE__, __LINE__,                         \
30             PATH, d, DIR);                              \
31     count_error();                                      \
32   }                                                     \
33   if(strcmp(b, BASE)) {                                 \
34     fprintf(stderr, "%s:%d: d_basename failed:\n"       \
35             "    path: %s\n"                            \
36             "     got: %s\n"                            \
37             "expected: %s\n",                           \
38             __FILE__, __LINE__,                         \
39             PATH, d, DIR);                              \
40     count_error();                                      \
41   }                                                     \
42 } while(0)
43
44 static void test_filepart(void) {
45   check_filepart("", "", "");
46   check_filepart("/", "/", "/");
47   check_filepart("////", "/", "/");
48   check_filepart("/spong", "/", "spong");
49   check_filepart("/spong/", "/", "spong");
50   check_filepart("/spong//", "/", "spong");
51   check_filepart("////spong", "/", "spong");
52   check_filepart("/foo/bar", "/foo", "bar");
53   check_filepart("/foo/bar/", "/foo", "bar");
54   check_filepart("////foo/////bar", "////foo", "bar");
55   check_filepart("./bar", ".", "bar");
56   check_filepart(".//bar", ".", "bar");
57   check_filepart(".", ".", ".");
58   check_filepart("..", ".", "..");
59   check_filepart("../blat", "..", "blat");
60   check_filepart("..//blat", "..", "blat");
61   check_filepart("wibble", ".", "wibble");
62   check_string(extension("foo.c"), ".c");
63   check_string(extension(".c"), ".c");
64   check_string(extension("."), ".");
65   check_string(extension("foo"), "");
66   check_string(extension("./foo"), "");
67   check_string(extension("./foo.c"), ".c");
68   check_string(strip_extension("foo.c"), "foo");
69   check_string(strip_extension("foo.mp3"), "foo");
70   check_string(strip_extension("foo.---"), "foo.---");
71   check_string(strip_extension("foo.---xyz"), "foo.---xyz");
72   check_string(strip_extension("foo.bar/wibble.spong"), "foo.bar/wibble");
73 }
74
75 TEST(filepart);
76
77 /*
78 Local Variables:
79 c-basic-offset:2
80 comment-column:40
81 fill-column:79
82 indent-tabs-mode:nil
83 End:
84 */