chiark / gitweb /
Typo fix.
[disorder] / libtests / t-split.c
CommitLineData
b90f122b
RK
1/*
2 * This file is part of DisOrder.
3 * Copyright (C) 2005, 2007, 2008 Richard Kettlewell
4 *
e7eb3a27 5 * This program is free software: you can redistribute it and/or modify
b90f122b 6 * it under the terms of the GNU General Public License as published by
e7eb3a27 7 * the Free Software Foundation, either version 3 of the License, or
b90f122b 8 * (at your option) any later version.
e7eb3a27
RK
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 *
b90f122b 15 * You should have received a copy of the GNU General Public License
e7eb3a27 16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
b90f122b
RK
17 */
18#include "test.h"
19
c68d8eba 20static void test_split(void) {
b90f122b
RK
21 char **v;
22 int nv;
23
b90f122b
RK
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
c68d8eba
RK
88TEST(split);
89
b90f122b
RK
90/*
91Local Variables:
92c-basic-offset:2
93comment-column:40
94fill-column:79
95indent-tabs-mode:nil
96End:
97*/