chiark / gitweb /
Obsolete 'TODO'. Use the bug tracker instead.
[disorder] / libtests / t-split.c
1 /*
2  * This file is part of DisOrder.
3  * Copyright (C) 2005, 2007, 2008 Richard Kettlewell
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  * 
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  * 
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 #include "test.h"
19
20 static void test_split(void) {
21   char **v;
22   int nv;
23
24   insist(split("\"misquoted", &nv, SPLIT_COMMENTS|SPLIT_QUOTES, 0, 0) == 0);
25   insist(split("\'misquoted", &nv, SPLIT_COMMENTS|SPLIT_QUOTES, 0, 0) == 0);
26   insist(split("\'misquoted\\", &nv, SPLIT_COMMENTS|SPLIT_QUOTES, 0, 0) == 0);
27   insist(split("\'misquoted\\\"", &nv, SPLIT_COMMENTS|SPLIT_QUOTES, 0, 0) == 0);
28   insist(split("\'mis\\escaped\'", &nv, SPLIT_COMMENTS|SPLIT_QUOTES, 0, 0) == 0);
29
30   insist((v = split("", &nv, SPLIT_COMMENTS|SPLIT_QUOTES, 0, 0)));
31   check_integer(nv, 0);
32   insist(*v == 0);
33
34   insist((v = split("wibble", &nv, SPLIT_COMMENTS|SPLIT_QUOTES, 0, 0)));
35   check_integer(nv, 1);
36   check_string(v[0], "wibble");
37   insist(v[1] == 0);
38
39   insist((v = split("   wibble \t\r\n wobble   ", &nv,
40                     SPLIT_COMMENTS|SPLIT_QUOTES, 0, 0)));
41   check_integer(nv, 2);
42   check_string(v[0], "wibble");
43   check_string(v[1], "wobble");
44   insist(v[2] == 0);
45
46   insist((v = split("wibble wobble #splat", &nv,
47                     SPLIT_COMMENTS|SPLIT_QUOTES, 0, 0)));
48   check_integer(nv, 2);
49   check_string(v[0], "wibble");
50   check_string(v[1], "wobble");
51   insist(v[2] == 0);
52
53   insist((v = split("\"wibble wobble\" #splat", &nv,
54                     SPLIT_COMMENTS|SPLIT_QUOTES, 0, 0)));
55   check_integer(nv, 1);
56   check_string(v[0], "wibble wobble");
57   insist(v[1] == 0);
58
59   insist((v = split("\"wibble \\\"\\nwobble\"", &nv,
60                     SPLIT_COMMENTS|SPLIT_QUOTES, 0, 0)));
61   check_integer(nv, 1);
62   check_string(v[0], "wibble \"\nwobble");
63   insist(v[1] == 0);
64
65   insist((v = split("\"wibble wobble\" #splat", &nv,
66                     SPLIT_QUOTES, 0, 0)));
67   check_integer(nv, 2);
68   check_string(v[0], "wibble wobble");
69   check_string(v[1], "#splat");
70   insist(v[2] == 0);
71
72   insist((v = split("\"wibble wobble\" #splat", &nv,
73                     SPLIT_COMMENTS, 0, 0)));
74   check_integer(nv, 2);
75   check_string(v[0], "\"wibble");
76   check_string(v[1], "wobble\"");
77   insist(v[2] == 0);
78
79   check_string(quoteutf8("wibble"), "wibble");
80   check_string(quoteutf8("  wibble  "), "\"  wibble  \"");
81   check_string(quoteutf8("wibble wobble"), "\"wibble wobble\"");
82   check_string(quoteutf8("wibble\"wobble"), "\"wibble\\\"wobble\"");
83   check_string(quoteutf8("wibble\nwobble"), "\"wibble\\nwobble\"");
84   check_string(quoteutf8("wibble\\wobble"), "\"wibble\\\\wobble\"");
85   check_string(quoteutf8("wibble'wobble"), "\"wibble'wobble\"");
86 }
87
88 TEST(split);
89
90 /*
91 Local Variables:
92 c-basic-offset:2
93 comment-column:40
94 fill-column:79
95 indent-tabs-mode:nil
96 End:
97 */