chiark / gitweb /
Partial untested FreeBSD and Linux support for scripts/setup.
[disorder] / lib / 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 2 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, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * 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, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18  * USA
19  */
20 #include "test.h"
21
22 void test_split(void) {
23   char **v;
24   int nv;
25
26   fprintf(stderr, "test_split\n");
27   insist(split("\"misquoted", &nv, SPLIT_COMMENTS|SPLIT_QUOTES, 0, 0) == 0);
28   insist(split("\'misquoted", &nv, SPLIT_COMMENTS|SPLIT_QUOTES, 0, 0) == 0);
29   insist(split("\'misquoted\\", &nv, SPLIT_COMMENTS|SPLIT_QUOTES, 0, 0) == 0);
30   insist(split("\'misquoted\\\"", &nv, SPLIT_COMMENTS|SPLIT_QUOTES, 0, 0) == 0);
31   insist(split("\'mis\\escaped\'", &nv, SPLIT_COMMENTS|SPLIT_QUOTES, 0, 0) == 0);
32
33   insist((v = split("", &nv, SPLIT_COMMENTS|SPLIT_QUOTES, 0, 0)));
34   check_integer(nv, 0);
35   insist(*v == 0);
36
37   insist((v = split("wibble", &nv, SPLIT_COMMENTS|SPLIT_QUOTES, 0, 0)));
38   check_integer(nv, 1);
39   check_string(v[0], "wibble");
40   insist(v[1] == 0);
41
42   insist((v = split("   wibble \t\r\n wobble   ", &nv,
43                     SPLIT_COMMENTS|SPLIT_QUOTES, 0, 0)));
44   check_integer(nv, 2);
45   check_string(v[0], "wibble");
46   check_string(v[1], "wobble");
47   insist(v[2] == 0);
48
49   insist((v = split("wibble wobble #splat", &nv,
50                     SPLIT_COMMENTS|SPLIT_QUOTES, 0, 0)));
51   check_integer(nv, 2);
52   check_string(v[0], "wibble");
53   check_string(v[1], "wobble");
54   insist(v[2] == 0);
55
56   insist((v = split("\"wibble wobble\" #splat", &nv,
57                     SPLIT_COMMENTS|SPLIT_QUOTES, 0, 0)));
58   check_integer(nv, 1);
59   check_string(v[0], "wibble wobble");
60   insist(v[1] == 0);
61
62   insist((v = split("\"wibble \\\"\\nwobble\"", &nv,
63                     SPLIT_COMMENTS|SPLIT_QUOTES, 0, 0)));
64   check_integer(nv, 1);
65   check_string(v[0], "wibble \"\nwobble");
66   insist(v[1] == 0);
67
68   insist((v = split("\"wibble wobble\" #splat", &nv,
69                     SPLIT_QUOTES, 0, 0)));
70   check_integer(nv, 2);
71   check_string(v[0], "wibble wobble");
72   check_string(v[1], "#splat");
73   insist(v[2] == 0);
74
75   insist((v = split("\"wibble wobble\" #splat", &nv,
76                     SPLIT_COMMENTS, 0, 0)));
77   check_integer(nv, 2);
78   check_string(v[0], "\"wibble");
79   check_string(v[1], "wobble\"");
80   insist(v[2] == 0);
81
82   check_string(quoteutf8("wibble"), "wibble");
83   check_string(quoteutf8("  wibble  "), "\"  wibble  \"");
84   check_string(quoteutf8("wibble wobble"), "\"wibble wobble\"");
85   check_string(quoteutf8("wibble\"wobble"), "\"wibble\\\"wobble\"");
86   check_string(quoteutf8("wibble\nwobble"), "\"wibble\\nwobble\"");
87   check_string(quoteutf8("wibble\\wobble"), "\"wibble\\\\wobble\"");
88   check_string(quoteutf8("wibble'wobble"), "\"wibble'wobble\"");
89 }
90
91 /*
92 Local Variables:
93 c-basic-offset:2
94 comment-column:40
95 fill-column:79
96 indent-tabs-mode:nil
97 End:
98 */