Commit | Line | Data |
---|---|---|
b90f122b RK |
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 | ||
c68d8eba | 22 | static void test_split(void) { |
b90f122b RK |
23 | char **v; |
24 | int nv; | |
25 | ||
b90f122b RK |
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("\'misquoted\\", &nv, SPLIT_COMMENTS|SPLIT_QUOTES, 0, 0) == 0); | |
29 | insist(split("\'misquoted\\\"", &nv, SPLIT_COMMENTS|SPLIT_QUOTES, 0, 0) == 0); | |
30 | insist(split("\'mis\\escaped\'", &nv, SPLIT_COMMENTS|SPLIT_QUOTES, 0, 0) == 0); | |
31 | ||
32 | insist((v = split("", &nv, SPLIT_COMMENTS|SPLIT_QUOTES, 0, 0))); | |
33 | check_integer(nv, 0); | |
34 | insist(*v == 0); | |
35 | ||
36 | insist((v = split("wibble", &nv, SPLIT_COMMENTS|SPLIT_QUOTES, 0, 0))); | |
37 | check_integer(nv, 1); | |
38 | check_string(v[0], "wibble"); | |
39 | insist(v[1] == 0); | |
40 | ||
41 | insist((v = split(" wibble \t\r\n wobble ", &nv, | |
42 | SPLIT_COMMENTS|SPLIT_QUOTES, 0, 0))); | |
43 | check_integer(nv, 2); | |
44 | check_string(v[0], "wibble"); | |
45 | check_string(v[1], "wobble"); | |
46 | insist(v[2] == 0); | |
47 | ||
48 | insist((v = split("wibble wobble #splat", &nv, | |
49 | SPLIT_COMMENTS|SPLIT_QUOTES, 0, 0))); | |
50 | check_integer(nv, 2); | |
51 | check_string(v[0], "wibble"); | |
52 | check_string(v[1], "wobble"); | |
53 | insist(v[2] == 0); | |
54 | ||
55 | insist((v = split("\"wibble wobble\" #splat", &nv, | |
56 | SPLIT_COMMENTS|SPLIT_QUOTES, 0, 0))); | |
57 | check_integer(nv, 1); | |
58 | check_string(v[0], "wibble wobble"); | |
59 | insist(v[1] == 0); | |
60 | ||
61 | insist((v = split("\"wibble \\\"\\nwobble\"", &nv, | |
62 | SPLIT_COMMENTS|SPLIT_QUOTES, 0, 0))); | |
63 | check_integer(nv, 1); | |
64 | check_string(v[0], "wibble \"\nwobble"); | |
65 | insist(v[1] == 0); | |
66 | ||
67 | insist((v = split("\"wibble wobble\" #splat", &nv, | |
68 | SPLIT_QUOTES, 0, 0))); | |
69 | check_integer(nv, 2); | |
70 | check_string(v[0], "wibble wobble"); | |
71 | check_string(v[1], "#splat"); | |
72 | insist(v[2] == 0); | |
73 | ||
74 | insist((v = split("\"wibble wobble\" #splat", &nv, | |
75 | SPLIT_COMMENTS, 0, 0))); | |
76 | check_integer(nv, 2); | |
77 | check_string(v[0], "\"wibble"); | |
78 | check_string(v[1], "wobble\""); | |
79 | insist(v[2] == 0); | |
80 | ||
81 | check_string(quoteutf8("wibble"), "wibble"); | |
82 | check_string(quoteutf8(" wibble "), "\" wibble \""); | |
83 | check_string(quoteutf8("wibble wobble"), "\"wibble wobble\""); | |
84 | check_string(quoteutf8("wibble\"wobble"), "\"wibble\\\"wobble\""); | |
85 | check_string(quoteutf8("wibble\nwobble"), "\"wibble\\nwobble\""); | |
86 | check_string(quoteutf8("wibble\\wobble"), "\"wibble\\\\wobble\""); | |
87 | check_string(quoteutf8("wibble'wobble"), "\"wibble'wobble\""); | |
88 | } | |
89 | ||
c68d8eba RK |
90 | TEST(split); |
91 | ||
b90f122b RK |
92 | /* |
93 | Local Variables: | |
94 | c-basic-offset:2 | |
95 | comment-column:40 | |
96 | fill-column:79 | |
97 | indent-tabs-mode:nil | |
98 | End: | |
99 | */ |