sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (C) 2005 - 2006, Marco Barisione <marco@barisione.org>
|
sl@0
|
3 |
* Portions copyright (c) 2009 Nokia Corporation. All rights reserved.
|
sl@0
|
4 |
* This library is free software; you can redistribute it and/or
|
sl@0
|
5 |
* modify it under the terms of the GNU Lesser General Public
|
sl@0
|
6 |
* License as published by the Free Software Foundation; either
|
sl@0
|
7 |
* version 2 of the License, or (at your option) any later version.
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* This library is distributed in the hope that it will be useful,
|
sl@0
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
sl@0
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
sl@0
|
12 |
* Lesser General Public License for more details.
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* You should have received a copy of the GNU Lesser General Public
|
sl@0
|
15 |
* License along with this library; if not, write to the
|
sl@0
|
16 |
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
sl@0
|
17 |
* Boston, MA 02111-1307, USA.
|
sl@0
|
18 |
*/
|
sl@0
|
19 |
|
sl@0
|
20 |
#undef G_DISABLE_ASSERT
|
sl@0
|
21 |
#undef G_LOG_DOMAIN
|
sl@0
|
22 |
#define ENABLE_REGEX
|
sl@0
|
23 |
#include <string.h>
|
sl@0
|
24 |
#include <locale.h>
|
sl@0
|
25 |
#include "glib.h"
|
sl@0
|
26 |
#ifdef __SYMBIAN32__
|
sl@0
|
27 |
#include "mrt2_glib2_test.h"
|
sl@0
|
28 |
#endif /*__SYMBIAN32__*/
|
sl@0
|
29 |
#ifdef ENABLE_REGEX
|
sl@0
|
30 |
|
sl@0
|
31 |
/* U+20AC EURO SIGN (symbol, currency) */
|
sl@0
|
32 |
#define EURO "\xe2\x82\xac"
|
sl@0
|
33 |
/* U+00E0 LATIN SMALL LETTER A WITH GRAVE (letter, lowercase) */
|
sl@0
|
34 |
#define AGRAVE "\xc3\xa0"
|
sl@0
|
35 |
/* U+00C0 LATIN CAPITAL LETTER A WITH GRAVE (letter, uppercase) */
|
sl@0
|
36 |
#define AGRAVE_UPPER "\xc3\x80"
|
sl@0
|
37 |
/* U+00E8 LATIN SMALL LETTER E WITH GRAVE (letter, lowercase) */
|
sl@0
|
38 |
#define EGRAVE "\xc3\xa8"
|
sl@0
|
39 |
/* U+00F2 LATIN SMALL LETTER O WITH GRAVE (letter, lowercase) */
|
sl@0
|
40 |
#define OGRAVE "\xc3\xb2"
|
sl@0
|
41 |
/* U+014B LATIN SMALL LETTER ENG (letter, lowercase) */
|
sl@0
|
42 |
#define ENG "\xc5\x8b"
|
sl@0
|
43 |
/* U+0127 LATIN SMALL LETTER H WITH STROKE (letter, lowercase) */
|
sl@0
|
44 |
#define HSTROKE "\xc4\xa7"
|
sl@0
|
45 |
/* U+0634 ARABIC LETTER SHEEN (letter, other) */
|
sl@0
|
46 |
#define SHEEN "\xd8\xb4"
|
sl@0
|
47 |
/* U+1374 ETHIOPIC NUMBER THIRTY (number, other) */
|
sl@0
|
48 |
#define ETH30 "\xe1\x8d\xb4"
|
sl@0
|
49 |
|
sl@0
|
50 |
/* A random value use to mark untouched integer variables. */
|
sl@0
|
51 |
#define UNTOUCHED -559038737
|
sl@0
|
52 |
|
sl@0
|
53 |
static gboolean noisy = FALSE;
|
sl@0
|
54 |
static gboolean abort_on_fail = FALSE;
|
sl@0
|
55 |
|
sl@0
|
56 |
#define PASS passed++
|
sl@0
|
57 |
#define FAIL \
|
sl@0
|
58 |
G_STMT_START \
|
sl@0
|
59 |
{ \
|
sl@0
|
60 |
failed++; \
|
sl@0
|
61 |
if (abort_on_fail) \
|
sl@0
|
62 |
goto end; \
|
sl@0
|
63 |
} \
|
sl@0
|
64 |
G_STMT_END
|
sl@0
|
65 |
|
sl@0
|
66 |
/* A replacement for strcmp that doesn't crash with null pointers. */
|
sl@0
|
67 |
static gboolean
|
sl@0
|
68 |
streq (const gchar *s1, const gchar *s2)
|
sl@0
|
69 |
{
|
sl@0
|
70 |
if (s1 == NULL && s2 == NULL)
|
sl@0
|
71 |
return TRUE;
|
sl@0
|
72 |
else if (s1 == NULL)
|
sl@0
|
73 |
return FALSE;
|
sl@0
|
74 |
else if (s2 == NULL)
|
sl@0
|
75 |
return FALSE;
|
sl@0
|
76 |
else
|
sl@0
|
77 |
return strcmp (s1, s2) == 0;
|
sl@0
|
78 |
}
|
sl@0
|
79 |
|
sl@0
|
80 |
static void
|
sl@0
|
81 |
verbose (const gchar *format, ...)
|
sl@0
|
82 |
{
|
sl@0
|
83 |
/* Function copied from glib/tests/patterntest.c by Matthias Clasen. */
|
sl@0
|
84 |
gchar *msg;
|
sl@0
|
85 |
va_list args;
|
sl@0
|
86 |
|
sl@0
|
87 |
va_start (args, format);
|
sl@0
|
88 |
msg = g_strdup_vprintf (format, args);
|
sl@0
|
89 |
va_end (args);
|
sl@0
|
90 |
|
sl@0
|
91 |
if (noisy)
|
sl@0
|
92 |
g_print ("%s", msg);
|
sl@0
|
93 |
g_free (msg);
|
sl@0
|
94 |
}
|
sl@0
|
95 |
|
sl@0
|
96 |
static gboolean
|
sl@0
|
97 |
test_new (const gchar *pattern,
|
sl@0
|
98 |
GRegexCompileFlags compile_opts,
|
sl@0
|
99 |
GRegexMatchFlags match_opts)
|
sl@0
|
100 |
{
|
sl@0
|
101 |
GRegex *regex;
|
sl@0
|
102 |
|
sl@0
|
103 |
verbose ("compiling \"%s\" \t", pattern);
|
sl@0
|
104 |
|
sl@0
|
105 |
regex = g_regex_new (pattern, compile_opts, match_opts, NULL);
|
sl@0
|
106 |
if (regex == NULL)
|
sl@0
|
107 |
{
|
sl@0
|
108 |
g_print ("failed \t(pattern: \"%s\", compile: %d, match %d)\n",
|
sl@0
|
109 |
pattern, compile_opts, match_opts);
|
sl@0
|
110 |
return FALSE;
|
sl@0
|
111 |
}
|
sl@0
|
112 |
|
sl@0
|
113 |
if (!streq (g_regex_get_pattern (regex), pattern))
|
sl@0
|
114 |
{
|
sl@0
|
115 |
g_print ("failed \t(pattern: \"%s\")\n",
|
sl@0
|
116 |
pattern);
|
sl@0
|
117 |
g_regex_unref (regex);
|
sl@0
|
118 |
return FALSE;
|
sl@0
|
119 |
}
|
sl@0
|
120 |
|
sl@0
|
121 |
g_regex_unref (regex);
|
sl@0
|
122 |
|
sl@0
|
123 |
verbose ("passed\n");
|
sl@0
|
124 |
return TRUE;
|
sl@0
|
125 |
}
|
sl@0
|
126 |
|
sl@0
|
127 |
#define TEST_NEW(pattern, compile_opts, match_opts) { \
|
sl@0
|
128 |
total++; \
|
sl@0
|
129 |
if (test_new (pattern, compile_opts, match_opts)) \
|
sl@0
|
130 |
PASS; \
|
sl@0
|
131 |
else \
|
sl@0
|
132 |
FAIL; \
|
sl@0
|
133 |
}
|
sl@0
|
134 |
|
sl@0
|
135 |
static gboolean
|
sl@0
|
136 |
test_new_fail (const gchar *pattern,
|
sl@0
|
137 |
GRegexCompileFlags compile_opts,
|
sl@0
|
138 |
GRegexError expected_error)
|
sl@0
|
139 |
{
|
sl@0
|
140 |
GRegex *regex;
|
sl@0
|
141 |
GError *error = NULL;
|
sl@0
|
142 |
|
sl@0
|
143 |
verbose ("compiling \"%s\" (expected a failure) \t", pattern);
|
sl@0
|
144 |
|
sl@0
|
145 |
regex = g_regex_new (pattern, compile_opts, 0, &error);
|
sl@0
|
146 |
|
sl@0
|
147 |
if (regex != NULL)
|
sl@0
|
148 |
{
|
sl@0
|
149 |
g_print ("failed \t(pattern: \"%s\", compile: %d)\n",
|
sl@0
|
150 |
pattern, compile_opts);
|
sl@0
|
151 |
g_regex_unref (regex);
|
sl@0
|
152 |
return FALSE;
|
sl@0
|
153 |
}
|
sl@0
|
154 |
|
sl@0
|
155 |
if (error->code != expected_error)
|
sl@0
|
156 |
{
|
sl@0
|
157 |
g_print ("failed \t(pattern: \"%s\", compile: %d, got error: %d, "
|
sl@0
|
158 |
"expected error: %d)\n",
|
sl@0
|
159 |
pattern, compile_opts, error->code, expected_error);
|
sl@0
|
160 |
g_error_free (error);
|
sl@0
|
161 |
return FALSE;
|
sl@0
|
162 |
}
|
sl@0
|
163 |
|
sl@0
|
164 |
verbose ("passed\n");
|
sl@0
|
165 |
return TRUE;
|
sl@0
|
166 |
}
|
sl@0
|
167 |
|
sl@0
|
168 |
#define TEST_NEW_FAIL(pattern, compile_opts, expected_error) { \
|
sl@0
|
169 |
total++; \
|
sl@0
|
170 |
if (test_new_fail (pattern, compile_opts, expected_error)) \
|
sl@0
|
171 |
PASS; \
|
sl@0
|
172 |
else \
|
sl@0
|
173 |
FAIL; \
|
sl@0
|
174 |
}
|
sl@0
|
175 |
|
sl@0
|
176 |
static gboolean
|
sl@0
|
177 |
test_match_simple (const gchar *pattern,
|
sl@0
|
178 |
const gchar *string,
|
sl@0
|
179 |
GRegexCompileFlags compile_opts,
|
sl@0
|
180 |
GRegexMatchFlags match_opts,
|
sl@0
|
181 |
gboolean expected)
|
sl@0
|
182 |
{
|
sl@0
|
183 |
gboolean match;
|
sl@0
|
184 |
|
sl@0
|
185 |
verbose ("matching \"%s\" against \"%s\" \t", string, pattern);
|
sl@0
|
186 |
|
sl@0
|
187 |
match = g_regex_match_simple (pattern, string, compile_opts, match_opts);
|
sl@0
|
188 |
if (match != expected)
|
sl@0
|
189 |
{
|
sl@0
|
190 |
g_print ("failed \t(unexpected %s)\n", match ? "match" : "mismatch");
|
sl@0
|
191 |
return FALSE;
|
sl@0
|
192 |
}
|
sl@0
|
193 |
else
|
sl@0
|
194 |
{
|
sl@0
|
195 |
verbose ("passed (%s)\n", match ? "match" : "nomatch");
|
sl@0
|
196 |
return TRUE;
|
sl@0
|
197 |
}
|
sl@0
|
198 |
}
|
sl@0
|
199 |
|
sl@0
|
200 |
#define TEST_MATCH_SIMPLE(pattern, string, compile_opts, match_opts, expected) { \
|
sl@0
|
201 |
total++; \
|
sl@0
|
202 |
if (test_match_simple (pattern, string, compile_opts, match_opts, expected)) \
|
sl@0
|
203 |
PASS; \
|
sl@0
|
204 |
else \
|
sl@0
|
205 |
FAIL; \
|
sl@0
|
206 |
}
|
sl@0
|
207 |
|
sl@0
|
208 |
static gboolean
|
sl@0
|
209 |
test_match (const gchar *pattern,
|
sl@0
|
210 |
GRegexCompileFlags compile_opts,
|
sl@0
|
211 |
GRegexMatchFlags match_opts,
|
sl@0
|
212 |
const gchar *string,
|
sl@0
|
213 |
gssize string_len,
|
sl@0
|
214 |
gint start_position,
|
sl@0
|
215 |
GRegexMatchFlags match_opts2,
|
sl@0
|
216 |
gboolean expected)
|
sl@0
|
217 |
{
|
sl@0
|
218 |
GRegex *regex;
|
sl@0
|
219 |
gboolean match;
|
sl@0
|
220 |
|
sl@0
|
221 |
verbose ("matching \"%s\" against \"%s\" (start: %d, len: %d) \t",
|
sl@0
|
222 |
string, pattern, start_position, string_len);
|
sl@0
|
223 |
|
sl@0
|
224 |
regex = g_regex_new (pattern, compile_opts, match_opts, NULL);
|
sl@0
|
225 |
match = g_regex_match_full (regex, string, string_len,
|
sl@0
|
226 |
start_position, match_opts2, NULL, NULL);
|
sl@0
|
227 |
if (match != expected)
|
sl@0
|
228 |
{
|
sl@0
|
229 |
gchar *e1 = g_strescape (pattern, NULL);
|
sl@0
|
230 |
gchar *e2 = g_strescape (string, NULL);
|
sl@0
|
231 |
g_print ("failed \t(unexpected %s) '%s' against '%s'\n", match ? "match" : "mismatch", e1, e2);
|
sl@0
|
232 |
g_free (e1);
|
sl@0
|
233 |
g_free (e2);
|
sl@0
|
234 |
g_regex_unref (regex);
|
sl@0
|
235 |
return FALSE;
|
sl@0
|
236 |
}
|
sl@0
|
237 |
|
sl@0
|
238 |
if (string_len == -1 && start_position == 0)
|
sl@0
|
239 |
{
|
sl@0
|
240 |
match = g_regex_match (regex, string, match_opts2, NULL);
|
sl@0
|
241 |
if (match != expected)
|
sl@0
|
242 |
{
|
sl@0
|
243 |
g_print ("failed \t(pattern: \"%s\", string: \"%s\")\n",
|
sl@0
|
244 |
pattern, string);
|
sl@0
|
245 |
g_regex_unref (regex);
|
sl@0
|
246 |
return FALSE;
|
sl@0
|
247 |
}
|
sl@0
|
248 |
}
|
sl@0
|
249 |
|
sl@0
|
250 |
g_regex_unref (regex);
|
sl@0
|
251 |
|
sl@0
|
252 |
verbose ("passed (%s)\n", match ? "match" : "nomatch");
|
sl@0
|
253 |
return TRUE;
|
sl@0
|
254 |
}
|
sl@0
|
255 |
|
sl@0
|
256 |
#define TEST_MATCH(pattern, compile_opts, match_opts, string, \
|
sl@0
|
257 |
string_len, start_position, match_opts2, expected) { \
|
sl@0
|
258 |
total++; \
|
sl@0
|
259 |
if (test_match (pattern, compile_opts, match_opts, string, \
|
sl@0
|
260 |
string_len, start_position, match_opts2, expected)) \
|
sl@0
|
261 |
PASS; \
|
sl@0
|
262 |
else \
|
sl@0
|
263 |
FAIL; \
|
sl@0
|
264 |
}
|
sl@0
|
265 |
|
sl@0
|
266 |
struct _Match
|
sl@0
|
267 |
{
|
sl@0
|
268 |
gchar *string;
|
sl@0
|
269 |
gint start, end;
|
sl@0
|
270 |
};
|
sl@0
|
271 |
typedef struct _Match Match;
|
sl@0
|
272 |
|
sl@0
|
273 |
static void
|
sl@0
|
274 |
free_match (gpointer data, gpointer user_data)
|
sl@0
|
275 |
{
|
sl@0
|
276 |
Match *match = data;
|
sl@0
|
277 |
if (match == NULL)
|
sl@0
|
278 |
return;
|
sl@0
|
279 |
g_free (match->string);
|
sl@0
|
280 |
g_free (match);
|
sl@0
|
281 |
}
|
sl@0
|
282 |
|
sl@0
|
283 |
static gboolean
|
sl@0
|
284 |
test_match_next (const gchar *pattern,
|
sl@0
|
285 |
const gchar *string,
|
sl@0
|
286 |
gssize string_len,
|
sl@0
|
287 |
gint start_position,
|
sl@0
|
288 |
...)
|
sl@0
|
289 |
{
|
sl@0
|
290 |
GRegex *regex;
|
sl@0
|
291 |
GMatchInfo *match_info;
|
sl@0
|
292 |
va_list args;
|
sl@0
|
293 |
GSList *matches = NULL;
|
sl@0
|
294 |
GSList *expected = NULL;
|
sl@0
|
295 |
GSList *l_exp, *l_match;
|
sl@0
|
296 |
gboolean ret = TRUE;
|
sl@0
|
297 |
|
sl@0
|
298 |
verbose ("matching \"%s\" against \"%s\" (start: %d, len: %d) \t",
|
sl@0
|
299 |
string, pattern, start_position, string_len);
|
sl@0
|
300 |
|
sl@0
|
301 |
/* The va_list is a NULL-terminated sequence of: extected matched string,
|
sl@0
|
302 |
* expected start and expected end. */
|
sl@0
|
303 |
va_start (args, start_position);
|
sl@0
|
304 |
while (TRUE)
|
sl@0
|
305 |
{
|
sl@0
|
306 |
Match *match;
|
sl@0
|
307 |
const gchar *expected_string = va_arg (args, const gchar *);
|
sl@0
|
308 |
if (expected_string == NULL)
|
sl@0
|
309 |
break;
|
sl@0
|
310 |
match = g_new0 (Match, 1);
|
sl@0
|
311 |
match->string = g_strdup (expected_string);
|
sl@0
|
312 |
match->start = va_arg (args, gint);
|
sl@0
|
313 |
match->end = va_arg (args, gint);
|
sl@0
|
314 |
expected = g_slist_prepend (expected, match);
|
sl@0
|
315 |
}
|
sl@0
|
316 |
expected = g_slist_reverse (expected);
|
sl@0
|
317 |
va_end (args);
|
sl@0
|
318 |
|
sl@0
|
319 |
regex = g_regex_new (pattern, 0, 0, NULL);
|
sl@0
|
320 |
|
sl@0
|
321 |
g_regex_match_full (regex, string, string_len,
|
sl@0
|
322 |
start_position, 0, &match_info, NULL);
|
sl@0
|
323 |
while (g_match_info_matches (match_info))
|
sl@0
|
324 |
{
|
sl@0
|
325 |
Match *match = g_new0 (Match, 1);
|
sl@0
|
326 |
match->string = g_match_info_fetch (match_info, 0);
|
sl@0
|
327 |
match->start = UNTOUCHED;
|
sl@0
|
328 |
match->end = UNTOUCHED;
|
sl@0
|
329 |
g_match_info_fetch_pos (match_info, 0, &match->start, &match->end);
|
sl@0
|
330 |
matches = g_slist_prepend (matches, match);
|
sl@0
|
331 |
g_match_info_next (match_info, NULL);
|
sl@0
|
332 |
}
|
sl@0
|
333 |
g_assert (regex == g_match_info_get_regex (match_info));
|
sl@0
|
334 |
g_assert (string == g_match_info_get_string (match_info));
|
sl@0
|
335 |
g_match_info_free (match_info);
|
sl@0
|
336 |
matches = g_slist_reverse (matches);
|
sl@0
|
337 |
|
sl@0
|
338 |
if (g_slist_length (matches) != g_slist_length (expected))
|
sl@0
|
339 |
{
|
sl@0
|
340 |
gint match_count = g_slist_length (matches);
|
sl@0
|
341 |
g_print ("failed \t(got %d %s, expected %d)\n", match_count,
|
sl@0
|
342 |
match_count == 1 ? "match" : "matches",
|
sl@0
|
343 |
g_slist_length (expected));
|
sl@0
|
344 |
ret = FALSE;
|
sl@0
|
345 |
goto exit;
|
sl@0
|
346 |
}
|
sl@0
|
347 |
|
sl@0
|
348 |
l_exp = expected;
|
sl@0
|
349 |
l_match = matches;
|
sl@0
|
350 |
while (l_exp != NULL)
|
sl@0
|
351 |
{
|
sl@0
|
352 |
Match *exp = l_exp->data;
|
sl@0
|
353 |
Match *match = l_match->data;
|
sl@0
|
354 |
|
sl@0
|
355 |
if (!streq(exp->string, match->string))
|
sl@0
|
356 |
{
|
sl@0
|
357 |
g_print ("failed \t(got \"%s\", expected \"%s\")\n",
|
sl@0
|
358 |
match->string, exp->string);
|
sl@0
|
359 |
ret = FALSE;
|
sl@0
|
360 |
goto exit;
|
sl@0
|
361 |
}
|
sl@0
|
362 |
|
sl@0
|
363 |
if (exp->start != match->start || exp->end != match->end)
|
sl@0
|
364 |
{
|
sl@0
|
365 |
g_print ("failed \t(got [%d, %d], expected [%d, %d])\n",
|
sl@0
|
366 |
match->start, match->end, exp->start, exp->end);
|
sl@0
|
367 |
ret = FALSE;
|
sl@0
|
368 |
goto exit;
|
sl@0
|
369 |
}
|
sl@0
|
370 |
|
sl@0
|
371 |
l_exp = g_slist_next (l_exp);
|
sl@0
|
372 |
l_match = g_slist_next (l_match);
|
sl@0
|
373 |
}
|
sl@0
|
374 |
|
sl@0
|
375 |
exit:
|
sl@0
|
376 |
if (ret)
|
sl@0
|
377 |
{
|
sl@0
|
378 |
gint count = g_slist_length (matches);
|
sl@0
|
379 |
verbose ("passed (%d %s)\n", count, count == 1 ? "match" : "matches");
|
sl@0
|
380 |
}
|
sl@0
|
381 |
|
sl@0
|
382 |
g_regex_unref (regex);
|
sl@0
|
383 |
g_slist_foreach (expected, free_match, NULL);
|
sl@0
|
384 |
g_slist_free (expected);
|
sl@0
|
385 |
g_slist_foreach (matches, free_match, NULL);
|
sl@0
|
386 |
g_slist_free (matches);
|
sl@0
|
387 |
|
sl@0
|
388 |
return ret;
|
sl@0
|
389 |
}
|
sl@0
|
390 |
|
sl@0
|
391 |
#define TEST_MATCH_NEXT0(pattern, string, string_len, start_position) { \
|
sl@0
|
392 |
total++; \
|
sl@0
|
393 |
if (test_match_next (pattern, string, string_len, start_position, NULL)) \
|
sl@0
|
394 |
PASS; \
|
sl@0
|
395 |
else \
|
sl@0
|
396 |
FAIL; \
|
sl@0
|
397 |
}
|
sl@0
|
398 |
|
sl@0
|
399 |
#define TEST_MATCH_NEXT1(pattern, string, string_len, start_position, \
|
sl@0
|
400 |
t1, s1, e1) { \
|
sl@0
|
401 |
total++; \
|
sl@0
|
402 |
if (test_match_next (pattern, string, string_len, start_position, \
|
sl@0
|
403 |
t1, s1, e1, NULL)) \
|
sl@0
|
404 |
PASS; \
|
sl@0
|
405 |
else \
|
sl@0
|
406 |
FAIL; \
|
sl@0
|
407 |
}
|
sl@0
|
408 |
|
sl@0
|
409 |
#define TEST_MATCH_NEXT2(pattern, string, string_len, start_position, \
|
sl@0
|
410 |
t1, s1, e1, t2, s2, e2) { \
|
sl@0
|
411 |
total++; \
|
sl@0
|
412 |
if (test_match_next (pattern, string, string_len, start_position, \
|
sl@0
|
413 |
t1, s1, e1, t2, s2, e2, NULL)) \
|
sl@0
|
414 |
PASS; \
|
sl@0
|
415 |
else \
|
sl@0
|
416 |
FAIL; \
|
sl@0
|
417 |
}
|
sl@0
|
418 |
|
sl@0
|
419 |
#define TEST_MATCH_NEXT3(pattern, string, string_len, start_position, \
|
sl@0
|
420 |
t1, s1, e1, t2, s2, e2, t3, s3, e3) { \
|
sl@0
|
421 |
total++; \
|
sl@0
|
422 |
if (test_match_next (pattern, string, string_len, start_position, \
|
sl@0
|
423 |
t1, s1, e1, t2, s2, e2, t3, s3, e3, NULL)) \
|
sl@0
|
424 |
PASS; \
|
sl@0
|
425 |
else \
|
sl@0
|
426 |
FAIL; \
|
sl@0
|
427 |
}
|
sl@0
|
428 |
|
sl@0
|
429 |
#define TEST_MATCH_NEXT4(pattern, string, string_len, start_position, \
|
sl@0
|
430 |
t1, s1, e1, t2, s2, e2, t3, s3, e3, t4, s4, e4) { \
|
sl@0
|
431 |
total++; \
|
sl@0
|
432 |
if (test_match_next (pattern, string, string_len, start_position, \
|
sl@0
|
433 |
t1, s1, e1, t2, s2, e2, t3, s3, e3, t4, s4, e4, NULL)) \
|
sl@0
|
434 |
PASS; \
|
sl@0
|
435 |
else \
|
sl@0
|
436 |
FAIL; \
|
sl@0
|
437 |
}
|
sl@0
|
438 |
|
sl@0
|
439 |
static gboolean
|
sl@0
|
440 |
test_match_count (const gchar *pattern,
|
sl@0
|
441 |
const gchar *string,
|
sl@0
|
442 |
gint start_position,
|
sl@0
|
443 |
GRegexMatchFlags match_opts,
|
sl@0
|
444 |
gint expected_count)
|
sl@0
|
445 |
{
|
sl@0
|
446 |
GRegex *regex;
|
sl@0
|
447 |
GMatchInfo *match_info;
|
sl@0
|
448 |
gint count;
|
sl@0
|
449 |
|
sl@0
|
450 |
verbose ("fetching match count (string: \"%s\", pattern: \"%s\", start: %d) \t",
|
sl@0
|
451 |
string, pattern, start_position);
|
sl@0
|
452 |
|
sl@0
|
453 |
regex = g_regex_new (pattern, 0, 0, NULL);
|
sl@0
|
454 |
|
sl@0
|
455 |
g_regex_match_full (regex, string, -1, start_position,
|
sl@0
|
456 |
match_opts, &match_info, NULL);
|
sl@0
|
457 |
count = g_match_info_get_match_count (match_info);
|
sl@0
|
458 |
|
sl@0
|
459 |
if (count != expected_count)
|
sl@0
|
460 |
{
|
sl@0
|
461 |
g_print ("failed \t(got %d, expected: %d)\n", count, expected_count);
|
sl@0
|
462 |
return FALSE;
|
sl@0
|
463 |
}
|
sl@0
|
464 |
|
sl@0
|
465 |
g_match_info_free (match_info);
|
sl@0
|
466 |
g_regex_unref (regex);
|
sl@0
|
467 |
|
sl@0
|
468 |
verbose ("passed\n");
|
sl@0
|
469 |
return TRUE;
|
sl@0
|
470 |
}
|
sl@0
|
471 |
|
sl@0
|
472 |
#define TEST_MATCH_COUNT(pattern, string, start_position, match_opts, expected_count) { \
|
sl@0
|
473 |
total++; \
|
sl@0
|
474 |
if (test_match_count (pattern, string, start_position, match_opts, expected_count)) \
|
sl@0
|
475 |
PASS; \
|
sl@0
|
476 |
else \
|
sl@0
|
477 |
FAIL; \
|
sl@0
|
478 |
}
|
sl@0
|
479 |
|
sl@0
|
480 |
static gboolean
|
sl@0
|
481 |
test_partial (const gchar *pattern,
|
sl@0
|
482 |
const gchar *string,
|
sl@0
|
483 |
gboolean expected)
|
sl@0
|
484 |
{
|
sl@0
|
485 |
GRegex *regex;
|
sl@0
|
486 |
GMatchInfo *match_info;
|
sl@0
|
487 |
|
sl@0
|
488 |
verbose ("partial matching (string: \"%s\", pattern: \"%s\") \t",
|
sl@0
|
489 |
string, pattern);
|
sl@0
|
490 |
|
sl@0
|
491 |
regex = g_regex_new (pattern, 0, 0, NULL);
|
sl@0
|
492 |
|
sl@0
|
493 |
g_regex_match (regex, string, G_REGEX_MATCH_PARTIAL, &match_info);
|
sl@0
|
494 |
if (expected != g_match_info_is_partial_match (match_info))
|
sl@0
|
495 |
{
|
sl@0
|
496 |
g_print ("failed \t(got %d, expected: %d)\n", !expected, expected);
|
sl@0
|
497 |
g_regex_unref (regex);
|
sl@0
|
498 |
return FALSE;
|
sl@0
|
499 |
}
|
sl@0
|
500 |
|
sl@0
|
501 |
if (expected && g_match_info_fetch_pos (match_info, 0, NULL, NULL))
|
sl@0
|
502 |
{
|
sl@0
|
503 |
g_print ("failed \t(got sub-pattern 0)\n");
|
sl@0
|
504 |
g_regex_unref (regex);
|
sl@0
|
505 |
return FALSE;
|
sl@0
|
506 |
}
|
sl@0
|
507 |
|
sl@0
|
508 |
if (expected && g_match_info_fetch_pos (match_info, 1, NULL, NULL))
|
sl@0
|
509 |
{
|
sl@0
|
510 |
g_print ("failed \t(got sub-pattern 1)\n");
|
sl@0
|
511 |
g_regex_unref (regex);
|
sl@0
|
512 |
return FALSE;
|
sl@0
|
513 |
}
|
sl@0
|
514 |
|
sl@0
|
515 |
g_match_info_free (match_info);
|
sl@0
|
516 |
g_regex_unref (regex);
|
sl@0
|
517 |
|
sl@0
|
518 |
verbose ("passed\n");
|
sl@0
|
519 |
return TRUE;
|
sl@0
|
520 |
}
|
sl@0
|
521 |
|
sl@0
|
522 |
#define TEST_PARTIAL(pattern, string, expected) { \
|
sl@0
|
523 |
total++; \
|
sl@0
|
524 |
if (test_partial (pattern, string, expected)) \
|
sl@0
|
525 |
PASS; \
|
sl@0
|
526 |
else \
|
sl@0
|
527 |
FAIL; \
|
sl@0
|
528 |
}
|
sl@0
|
529 |
|
sl@0
|
530 |
static gboolean
|
sl@0
|
531 |
test_sub_pattern (const gchar *pattern,
|
sl@0
|
532 |
const gchar *string,
|
sl@0
|
533 |
gint start_position,
|
sl@0
|
534 |
gint sub_n,
|
sl@0
|
535 |
const gchar *expected_sub,
|
sl@0
|
536 |
gint expected_start,
|
sl@0
|
537 |
gint expected_end)
|
sl@0
|
538 |
{
|
sl@0
|
539 |
GRegex *regex;
|
sl@0
|
540 |
GMatchInfo *match_info;
|
sl@0
|
541 |
gchar *sub_expr;
|
sl@0
|
542 |
gint start = UNTOUCHED, end = UNTOUCHED;
|
sl@0
|
543 |
|
sl@0
|
544 |
verbose ("fetching sub-pattern %d from \"%s\" (pattern: \"%s\") \t",
|
sl@0
|
545 |
sub_n, string, pattern);
|
sl@0
|
546 |
|
sl@0
|
547 |
regex = g_regex_new (pattern, 0, 0, NULL);
|
sl@0
|
548 |
g_regex_match_full (regex, string, -1, start_position, 0, &match_info, NULL);
|
sl@0
|
549 |
|
sl@0
|
550 |
sub_expr = g_match_info_fetch (match_info, sub_n);
|
sl@0
|
551 |
if (!streq(sub_expr, expected_sub))
|
sl@0
|
552 |
{
|
sl@0
|
553 |
g_print ("failed \t(got \"%s\", expected \"%s\")\n",
|
sl@0
|
554 |
sub_expr, expected_sub);
|
sl@0
|
555 |
g_free (sub_expr);
|
sl@0
|
556 |
g_regex_unref (regex);
|
sl@0
|
557 |
return FALSE;
|
sl@0
|
558 |
}
|
sl@0
|
559 |
g_free (sub_expr);
|
sl@0
|
560 |
|
sl@0
|
561 |
g_match_info_fetch_pos (match_info, sub_n, &start, &end);
|
sl@0
|
562 |
if (start != expected_start || end != expected_end)
|
sl@0
|
563 |
{
|
sl@0
|
564 |
g_print ("failed \t(got [%d, %d], expected [%d, %d])\n",
|
sl@0
|
565 |
start, end, expected_start, expected_end);
|
sl@0
|
566 |
g_regex_unref (regex);
|
sl@0
|
567 |
return FALSE;
|
sl@0
|
568 |
}
|
sl@0
|
569 |
|
sl@0
|
570 |
g_match_info_free (match_info);
|
sl@0
|
571 |
g_regex_unref (regex);
|
sl@0
|
572 |
|
sl@0
|
573 |
verbose ("passed\n");
|
sl@0
|
574 |
return TRUE;
|
sl@0
|
575 |
}
|
sl@0
|
576 |
|
sl@0
|
577 |
#define TEST_SUB_PATTERN(pattern, string, start_position, sub_n, expected_sub, \
|
sl@0
|
578 |
expected_start, expected_end) { \
|
sl@0
|
579 |
total++; \
|
sl@0
|
580 |
if (test_sub_pattern (pattern, string, start_position, sub_n, expected_sub, \
|
sl@0
|
581 |
expected_start, expected_end)) \
|
sl@0
|
582 |
PASS; \
|
sl@0
|
583 |
else \
|
sl@0
|
584 |
FAIL; \
|
sl@0
|
585 |
}
|
sl@0
|
586 |
|
sl@0
|
587 |
static gboolean
|
sl@0
|
588 |
test_named_sub_pattern (const gchar *pattern,
|
sl@0
|
589 |
GRegexCompileFlags flags,
|
sl@0
|
590 |
const gchar *string,
|
sl@0
|
591 |
gint start_position,
|
sl@0
|
592 |
const gchar *sub_name,
|
sl@0
|
593 |
const gchar *expected_sub,
|
sl@0
|
594 |
gint expected_start,
|
sl@0
|
595 |
gint expected_end)
|
sl@0
|
596 |
{
|
sl@0
|
597 |
GRegex *regex;
|
sl@0
|
598 |
GMatchInfo *match_info;
|
sl@0
|
599 |
gint start = UNTOUCHED, end = UNTOUCHED;
|
sl@0
|
600 |
gchar *sub_expr;
|
sl@0
|
601 |
|
sl@0
|
602 |
verbose ("fetching sub-pattern \"%s\" from \"%s\" (pattern: \"%s\") \t",
|
sl@0
|
603 |
sub_name, string, pattern);
|
sl@0
|
604 |
|
sl@0
|
605 |
regex = g_regex_new (pattern, flags, 0, NULL);
|
sl@0
|
606 |
|
sl@0
|
607 |
g_regex_match_full (regex, string, -1, start_position, 0, &match_info, NULL);
|
sl@0
|
608 |
sub_expr = g_match_info_fetch_named (match_info, sub_name);
|
sl@0
|
609 |
if (!streq (sub_expr, expected_sub))
|
sl@0
|
610 |
{
|
sl@0
|
611 |
g_print ("failed \t(got \"%s\", expected \"%s\")\n",
|
sl@0
|
612 |
sub_expr, expected_sub);
|
sl@0
|
613 |
g_free (sub_expr);
|
sl@0
|
614 |
g_regex_unref (regex);
|
sl@0
|
615 |
return FALSE;
|
sl@0
|
616 |
}
|
sl@0
|
617 |
g_free (sub_expr);
|
sl@0
|
618 |
|
sl@0
|
619 |
g_match_info_fetch_named_pos (match_info, sub_name, &start, &end);
|
sl@0
|
620 |
if (start != expected_start || end != expected_end)
|
sl@0
|
621 |
{
|
sl@0
|
622 |
g_print ("failed \t(got [%d, %d], expected [%d, %d])\n",
|
sl@0
|
623 |
start, end, expected_start, expected_end);
|
sl@0
|
624 |
g_regex_unref (regex);
|
sl@0
|
625 |
return FALSE;
|
sl@0
|
626 |
}
|
sl@0
|
627 |
|
sl@0
|
628 |
g_match_info_free (match_info);
|
sl@0
|
629 |
g_regex_unref (regex);
|
sl@0
|
630 |
|
sl@0
|
631 |
verbose ("passed\n");
|
sl@0
|
632 |
return TRUE;
|
sl@0
|
633 |
}
|
sl@0
|
634 |
|
sl@0
|
635 |
#define TEST_NAMED_SUB_PATTERN(pattern, string, start_position, sub_name, \
|
sl@0
|
636 |
expected_sub, expected_start, expected_end) { \
|
sl@0
|
637 |
total++; \
|
sl@0
|
638 |
if (test_named_sub_pattern (pattern, 0, string, start_position, sub_name, \
|
sl@0
|
639 |
expected_sub, expected_start, expected_end)) \
|
sl@0
|
640 |
PASS; \
|
sl@0
|
641 |
else \
|
sl@0
|
642 |
FAIL; \
|
sl@0
|
643 |
}
|
sl@0
|
644 |
|
sl@0
|
645 |
#define TEST_NAMED_SUB_PATTERN_DUPNAMES(pattern, string, start_position, sub_name, \
|
sl@0
|
646 |
expected_sub, expected_start, expected_end) { \
|
sl@0
|
647 |
total++; \
|
sl@0
|
648 |
if (test_named_sub_pattern (pattern, G_REGEX_DUPNAMES, string, start_position, \
|
sl@0
|
649 |
sub_name, expected_sub, expected_start, expected_end)) \
|
sl@0
|
650 |
PASS; \
|
sl@0
|
651 |
else \
|
sl@0
|
652 |
FAIL; \
|
sl@0
|
653 |
}
|
sl@0
|
654 |
|
sl@0
|
655 |
static gboolean
|
sl@0
|
656 |
test_fetch_all (const gchar *pattern,
|
sl@0
|
657 |
const gchar *string,
|
sl@0
|
658 |
...)
|
sl@0
|
659 |
{
|
sl@0
|
660 |
GRegex *regex;
|
sl@0
|
661 |
GMatchInfo *match_info;
|
sl@0
|
662 |
va_list args;
|
sl@0
|
663 |
GSList *expected = NULL;
|
sl@0
|
664 |
GSList *l_exp;
|
sl@0
|
665 |
gchar **matches;
|
sl@0
|
666 |
gint match_count;
|
sl@0
|
667 |
gboolean ret = TRUE;
|
sl@0
|
668 |
gint i;
|
sl@0
|
669 |
|
sl@0
|
670 |
verbose ("fetching all sub-patterns from \"%s\" (pattern: \"%s\") \t",
|
sl@0
|
671 |
string, pattern);
|
sl@0
|
672 |
|
sl@0
|
673 |
/* The va_list is a NULL-terminated sequence of extected strings. */
|
sl@0
|
674 |
va_start (args, string);
|
sl@0
|
675 |
while (TRUE)
|
sl@0
|
676 |
{
|
sl@0
|
677 |
gchar *expected_string = va_arg (args, gchar *);
|
sl@0
|
678 |
if (expected_string == NULL)
|
sl@0
|
679 |
break;
|
sl@0
|
680 |
else
|
sl@0
|
681 |
expected = g_slist_prepend (expected, g_strdup (expected_string));
|
sl@0
|
682 |
}
|
sl@0
|
683 |
expected = g_slist_reverse (expected);
|
sl@0
|
684 |
va_end (args);
|
sl@0
|
685 |
|
sl@0
|
686 |
regex = g_regex_new (pattern, 0, 0, NULL);
|
sl@0
|
687 |
g_regex_match (regex, string, 0, &match_info);
|
sl@0
|
688 |
matches = g_match_info_fetch_all (match_info);
|
sl@0
|
689 |
if (matches)
|
sl@0
|
690 |
match_count = g_strv_length (matches);
|
sl@0
|
691 |
else
|
sl@0
|
692 |
match_count = 0;
|
sl@0
|
693 |
|
sl@0
|
694 |
if (match_count != g_slist_length (expected))
|
sl@0
|
695 |
{
|
sl@0
|
696 |
g_print ("failed \t(got %d %s, expected %d)\n", match_count,
|
sl@0
|
697 |
match_count == 1 ? "match" : "matches",
|
sl@0
|
698 |
g_slist_length (expected));
|
sl@0
|
699 |
ret = FALSE;
|
sl@0
|
700 |
goto exit;
|
sl@0
|
701 |
}
|
sl@0
|
702 |
|
sl@0
|
703 |
l_exp = expected;
|
sl@0
|
704 |
for (i = 0; l_exp != NULL; i++, l_exp = g_slist_next (l_exp))
|
sl@0
|
705 |
{
|
sl@0
|
706 |
if (!streq(l_exp->data, matches [i]))
|
sl@0
|
707 |
{
|
sl@0
|
708 |
g_print ("failed \t(got \"%s\", expected \"%s\")\n",
|
sl@0
|
709 |
matches [i], (gchar *)l_exp->data);
|
sl@0
|
710 |
ret = FALSE;
|
sl@0
|
711 |
goto exit;
|
sl@0
|
712 |
}
|
sl@0
|
713 |
}
|
sl@0
|
714 |
|
sl@0
|
715 |
verbose ("passed (%d %s)\n", match_count,
|
sl@0
|
716 |
match_count == 1 ? "match" : "matches");
|
sl@0
|
717 |
|
sl@0
|
718 |
exit:
|
sl@0
|
719 |
g_match_info_free (match_info);
|
sl@0
|
720 |
g_regex_unref (regex);
|
sl@0
|
721 |
g_slist_foreach (expected, (GFunc)g_free, NULL);
|
sl@0
|
722 |
g_slist_free (expected);
|
sl@0
|
723 |
g_strfreev (matches);
|
sl@0
|
724 |
|
sl@0
|
725 |
return ret;
|
sl@0
|
726 |
}
|
sl@0
|
727 |
|
sl@0
|
728 |
#define TEST_FETCH_ALL0(pattern, string) { \
|
sl@0
|
729 |
total++; \
|
sl@0
|
730 |
if (test_fetch_all (pattern, string, NULL)) \
|
sl@0
|
731 |
PASS; \
|
sl@0
|
732 |
else \
|
sl@0
|
733 |
FAIL; \
|
sl@0
|
734 |
}
|
sl@0
|
735 |
|
sl@0
|
736 |
#define TEST_FETCH_ALL1(pattern, string, e1) { \
|
sl@0
|
737 |
total++; \
|
sl@0
|
738 |
if (test_fetch_all (pattern, string, e1, NULL)) \
|
sl@0
|
739 |
PASS; \
|
sl@0
|
740 |
else \
|
sl@0
|
741 |
FAIL; \
|
sl@0
|
742 |
}
|
sl@0
|
743 |
|
sl@0
|
744 |
#define TEST_FETCH_ALL2(pattern, string, e1, e2) { \
|
sl@0
|
745 |
total++; \
|
sl@0
|
746 |
if (test_fetch_all (pattern, string, e1, e2, NULL)) \
|
sl@0
|
747 |
PASS; \
|
sl@0
|
748 |
else \
|
sl@0
|
749 |
FAIL; \
|
sl@0
|
750 |
}
|
sl@0
|
751 |
|
sl@0
|
752 |
#define TEST_FETCH_ALL3(pattern, string, e1, e2, e3) { \
|
sl@0
|
753 |
total++; \
|
sl@0
|
754 |
if (test_fetch_all (pattern, string, e1, e2, e3, NULL)) \
|
sl@0
|
755 |
PASS; \
|
sl@0
|
756 |
else \
|
sl@0
|
757 |
FAIL; \
|
sl@0
|
758 |
}
|
sl@0
|
759 |
|
sl@0
|
760 |
static gboolean
|
sl@0
|
761 |
test_split_simple (const gchar *pattern,
|
sl@0
|
762 |
const gchar *string,
|
sl@0
|
763 |
...)
|
sl@0
|
764 |
{
|
sl@0
|
765 |
va_list args;
|
sl@0
|
766 |
GSList *expected = NULL;
|
sl@0
|
767 |
GSList *l_exp;
|
sl@0
|
768 |
gchar **tokens;
|
sl@0
|
769 |
gint token_count;
|
sl@0
|
770 |
gboolean ret = TRUE;
|
sl@0
|
771 |
gint i;
|
sl@0
|
772 |
|
sl@0
|
773 |
verbose ("splitting \"%s\" against \"%s\" \t", string, pattern);
|
sl@0
|
774 |
|
sl@0
|
775 |
/* The va_list is a NULL-terminated sequence of extected strings. */
|
sl@0
|
776 |
va_start (args, string);
|
sl@0
|
777 |
while (TRUE)
|
sl@0
|
778 |
{
|
sl@0
|
779 |
gchar *expected_string = va_arg (args, gchar *);
|
sl@0
|
780 |
if (expected_string == NULL)
|
sl@0
|
781 |
break;
|
sl@0
|
782 |
else
|
sl@0
|
783 |
expected = g_slist_prepend (expected, g_strdup (expected_string));
|
sl@0
|
784 |
}
|
sl@0
|
785 |
expected = g_slist_reverse (expected);
|
sl@0
|
786 |
va_end (args);
|
sl@0
|
787 |
|
sl@0
|
788 |
tokens = g_regex_split_simple (pattern, string, 0, 0);
|
sl@0
|
789 |
if (tokens)
|
sl@0
|
790 |
token_count = g_strv_length (tokens);
|
sl@0
|
791 |
else
|
sl@0
|
792 |
token_count = 0;
|
sl@0
|
793 |
|
sl@0
|
794 |
if (token_count != g_slist_length (expected))
|
sl@0
|
795 |
{
|
sl@0
|
796 |
g_print ("failed \t(got %d %s, expected %d)\n", token_count,
|
sl@0
|
797 |
token_count == 1 ? "match" : "matches",
|
sl@0
|
798 |
g_slist_length (expected));
|
sl@0
|
799 |
ret = FALSE;
|
sl@0
|
800 |
goto exit;
|
sl@0
|
801 |
}
|
sl@0
|
802 |
|
sl@0
|
803 |
l_exp = expected;
|
sl@0
|
804 |
for (i = 0; l_exp != NULL; i++, l_exp = g_slist_next (l_exp))
|
sl@0
|
805 |
{
|
sl@0
|
806 |
if (!streq(l_exp->data, tokens [i]))
|
sl@0
|
807 |
{
|
sl@0
|
808 |
g_print ("failed \t(got \"%s\", expected \"%s\")\n",
|
sl@0
|
809 |
tokens[i], (gchar *)l_exp->data);
|
sl@0
|
810 |
ret = FALSE;
|
sl@0
|
811 |
goto exit;
|
sl@0
|
812 |
}
|
sl@0
|
813 |
}
|
sl@0
|
814 |
|
sl@0
|
815 |
verbose ("passed (%d %s)\n", token_count,
|
sl@0
|
816 |
token_count == 1 ? "token" : "tokens");
|
sl@0
|
817 |
|
sl@0
|
818 |
exit:
|
sl@0
|
819 |
g_slist_foreach (expected, (GFunc)g_free, NULL);
|
sl@0
|
820 |
g_slist_free (expected);
|
sl@0
|
821 |
g_strfreev (tokens);
|
sl@0
|
822 |
|
sl@0
|
823 |
return ret;
|
sl@0
|
824 |
}
|
sl@0
|
825 |
|
sl@0
|
826 |
#define TEST_SPLIT_SIMPLE0(pattern, string) { \
|
sl@0
|
827 |
total++; \
|
sl@0
|
828 |
if (test_split_simple (pattern, string, NULL)) \
|
sl@0
|
829 |
PASS; \
|
sl@0
|
830 |
else \
|
sl@0
|
831 |
FAIL; \
|
sl@0
|
832 |
}
|
sl@0
|
833 |
|
sl@0
|
834 |
#define TEST_SPLIT_SIMPLE1(pattern, string, e1) { \
|
sl@0
|
835 |
total++; \
|
sl@0
|
836 |
if (test_split_simple (pattern, string, e1, NULL)) \
|
sl@0
|
837 |
PASS; \
|
sl@0
|
838 |
else \
|
sl@0
|
839 |
FAIL; \
|
sl@0
|
840 |
}
|
sl@0
|
841 |
|
sl@0
|
842 |
#define TEST_SPLIT_SIMPLE2(pattern, string, e1, e2) { \
|
sl@0
|
843 |
total++; \
|
sl@0
|
844 |
if (test_split_simple (pattern, string, e1, e2, NULL)) \
|
sl@0
|
845 |
PASS; \
|
sl@0
|
846 |
else \
|
sl@0
|
847 |
FAIL; \
|
sl@0
|
848 |
}
|
sl@0
|
849 |
|
sl@0
|
850 |
#define TEST_SPLIT_SIMPLE3(pattern, string, e1, e2, e3) { \
|
sl@0
|
851 |
total++; \
|
sl@0
|
852 |
if (test_split_simple (pattern, string, e1, e2, e3, NULL)) \
|
sl@0
|
853 |
PASS; \
|
sl@0
|
854 |
else \
|
sl@0
|
855 |
FAIL; \
|
sl@0
|
856 |
}
|
sl@0
|
857 |
|
sl@0
|
858 |
static gboolean
|
sl@0
|
859 |
test_split_full (const gchar *pattern,
|
sl@0
|
860 |
const gchar *string,
|
sl@0
|
861 |
gint start_position,
|
sl@0
|
862 |
gint max_tokens,
|
sl@0
|
863 |
...)
|
sl@0
|
864 |
{
|
sl@0
|
865 |
GRegex *regex;
|
sl@0
|
866 |
va_list args;
|
sl@0
|
867 |
GSList *expected = NULL;
|
sl@0
|
868 |
GSList *l_exp;
|
sl@0
|
869 |
gchar **tokens;
|
sl@0
|
870 |
gint token_count;
|
sl@0
|
871 |
gboolean ret = TRUE;
|
sl@0
|
872 |
gint i;
|
sl@0
|
873 |
|
sl@0
|
874 |
verbose ("splitting \"%s\" against \"%s\" (start: %d, max: %d) \t",
|
sl@0
|
875 |
string, pattern, start_position, max_tokens);
|
sl@0
|
876 |
|
sl@0
|
877 |
/* The va_list is a NULL-terminated sequence of extected strings. */
|
sl@0
|
878 |
va_start (args, max_tokens);
|
sl@0
|
879 |
while (TRUE)
|
sl@0
|
880 |
{
|
sl@0
|
881 |
gchar *expected_string = va_arg (args, gchar *);
|
sl@0
|
882 |
if (expected_string == NULL)
|
sl@0
|
883 |
break;
|
sl@0
|
884 |
else
|
sl@0
|
885 |
expected = g_slist_prepend (expected, g_strdup (expected_string));
|
sl@0
|
886 |
}
|
sl@0
|
887 |
expected = g_slist_reverse (expected);
|
sl@0
|
888 |
va_end (args);
|
sl@0
|
889 |
|
sl@0
|
890 |
regex = g_regex_new (pattern, 0, 0, NULL);
|
sl@0
|
891 |
tokens = g_regex_split_full (regex, string, -1, start_position,
|
sl@0
|
892 |
0, max_tokens, NULL);
|
sl@0
|
893 |
if (tokens)
|
sl@0
|
894 |
token_count = g_strv_length (tokens);
|
sl@0
|
895 |
else
|
sl@0
|
896 |
token_count = 0;
|
sl@0
|
897 |
|
sl@0
|
898 |
if (token_count != g_slist_length (expected))
|
sl@0
|
899 |
{
|
sl@0
|
900 |
g_print ("failed \t(got %d %s, expected %d)\n", token_count,
|
sl@0
|
901 |
token_count == 1 ? "match" : "matches",
|
sl@0
|
902 |
g_slist_length (expected));
|
sl@0
|
903 |
ret = FALSE;
|
sl@0
|
904 |
goto exit;
|
sl@0
|
905 |
}
|
sl@0
|
906 |
|
sl@0
|
907 |
l_exp = expected;
|
sl@0
|
908 |
for (i = 0; l_exp != NULL; i++, l_exp = g_slist_next (l_exp))
|
sl@0
|
909 |
{
|
sl@0
|
910 |
if (!streq(l_exp->data, tokens [i]))
|
sl@0
|
911 |
{
|
sl@0
|
912 |
g_print ("failed \t(got \"%s\", expected \"%s\")\n",
|
sl@0
|
913 |
tokens[i], (gchar *)l_exp->data);
|
sl@0
|
914 |
ret = FALSE;
|
sl@0
|
915 |
goto exit;
|
sl@0
|
916 |
}
|
sl@0
|
917 |
}
|
sl@0
|
918 |
|
sl@0
|
919 |
verbose ("passed (%d %s)\n", token_count,
|
sl@0
|
920 |
token_count == 1 ? "token" : "tokens");
|
sl@0
|
921 |
|
sl@0
|
922 |
exit:
|
sl@0
|
923 |
g_regex_unref (regex);
|
sl@0
|
924 |
g_slist_foreach (expected, (GFunc)g_free, NULL);
|
sl@0
|
925 |
g_slist_free (expected);
|
sl@0
|
926 |
g_strfreev (tokens);
|
sl@0
|
927 |
|
sl@0
|
928 |
return ret;
|
sl@0
|
929 |
}
|
sl@0
|
930 |
|
sl@0
|
931 |
static gboolean
|
sl@0
|
932 |
test_split (const gchar *pattern,
|
sl@0
|
933 |
const gchar *string,
|
sl@0
|
934 |
...)
|
sl@0
|
935 |
{
|
sl@0
|
936 |
GRegex *regex;
|
sl@0
|
937 |
va_list args;
|
sl@0
|
938 |
GSList *expected = NULL;
|
sl@0
|
939 |
GSList *l_exp;
|
sl@0
|
940 |
gchar **tokens;
|
sl@0
|
941 |
gint token_count;
|
sl@0
|
942 |
gboolean ret = TRUE;
|
sl@0
|
943 |
gint i;
|
sl@0
|
944 |
|
sl@0
|
945 |
verbose ("splitting \"%s\" against \"%s\" \t", string, pattern);
|
sl@0
|
946 |
|
sl@0
|
947 |
/* The va_list is a NULL-terminated sequence of extected strings. */
|
sl@0
|
948 |
va_start (args, string);
|
sl@0
|
949 |
while (TRUE)
|
sl@0
|
950 |
{
|
sl@0
|
951 |
gchar *expected_string = va_arg (args, gchar *);
|
sl@0
|
952 |
if (expected_string == NULL)
|
sl@0
|
953 |
break;
|
sl@0
|
954 |
else
|
sl@0
|
955 |
expected = g_slist_prepend (expected, g_strdup (expected_string));
|
sl@0
|
956 |
}
|
sl@0
|
957 |
expected = g_slist_reverse (expected);
|
sl@0
|
958 |
va_end (args);
|
sl@0
|
959 |
|
sl@0
|
960 |
regex = g_regex_new (pattern, 0, 0, NULL);
|
sl@0
|
961 |
tokens = g_regex_split (regex, string, 0);
|
sl@0
|
962 |
if (tokens)
|
sl@0
|
963 |
token_count = g_strv_length (tokens);
|
sl@0
|
964 |
else
|
sl@0
|
965 |
token_count = 0;
|
sl@0
|
966 |
|
sl@0
|
967 |
if (token_count != g_slist_length (expected))
|
sl@0
|
968 |
{
|
sl@0
|
969 |
g_print ("failed \t(got %d %s, expected %d)\n", token_count,
|
sl@0
|
970 |
token_count == 1 ? "match" : "matches",
|
sl@0
|
971 |
g_slist_length (expected));
|
sl@0
|
972 |
ret = FALSE;
|
sl@0
|
973 |
goto exit;
|
sl@0
|
974 |
}
|
sl@0
|
975 |
|
sl@0
|
976 |
l_exp = expected;
|
sl@0
|
977 |
for (i = 0; l_exp != NULL; i++, l_exp = g_slist_next (l_exp))
|
sl@0
|
978 |
{
|
sl@0
|
979 |
if (!streq(l_exp->data, tokens [i]))
|
sl@0
|
980 |
{
|
sl@0
|
981 |
g_print ("failed \t(got \"%s\", expected \"%s\")\n",
|
sl@0
|
982 |
tokens[i], (gchar *)l_exp->data);
|
sl@0
|
983 |
ret = FALSE;
|
sl@0
|
984 |
goto exit;
|
sl@0
|
985 |
}
|
sl@0
|
986 |
}
|
sl@0
|
987 |
|
sl@0
|
988 |
verbose ("passed (%d %s)\n", token_count,
|
sl@0
|
989 |
token_count == 1 ? "token" : "tokens");
|
sl@0
|
990 |
|
sl@0
|
991 |
exit:
|
sl@0
|
992 |
g_regex_unref (regex);
|
sl@0
|
993 |
g_slist_foreach (expected, (GFunc)g_free, NULL);
|
sl@0
|
994 |
g_slist_free (expected);
|
sl@0
|
995 |
g_strfreev (tokens);
|
sl@0
|
996 |
|
sl@0
|
997 |
return ret;
|
sl@0
|
998 |
}
|
sl@0
|
999 |
|
sl@0
|
1000 |
#define TEST_SPLIT0(pattern, string, start_position, max_tokens) { \
|
sl@0
|
1001 |
total++; \
|
sl@0
|
1002 |
if (test_split_full (pattern, string, start_position, max_tokens, NULL)) \
|
sl@0
|
1003 |
PASS; \
|
sl@0
|
1004 |
else \
|
sl@0
|
1005 |
FAIL; \
|
sl@0
|
1006 |
if (start_position == 0 && max_tokens <= 0) \
|
sl@0
|
1007 |
{ \
|
sl@0
|
1008 |
total++; \
|
sl@0
|
1009 |
if (test_split (pattern, string, NULL)) \
|
sl@0
|
1010 |
PASS; \
|
sl@0
|
1011 |
else \
|
sl@0
|
1012 |
FAIL; \
|
sl@0
|
1013 |
} \
|
sl@0
|
1014 |
}
|
sl@0
|
1015 |
|
sl@0
|
1016 |
#define TEST_SPLIT1(pattern, string, start_position, max_tokens, e1) { \
|
sl@0
|
1017 |
total++; \
|
sl@0
|
1018 |
if (test_split_full (pattern, string, start_position, max_tokens, e1, NULL)) \
|
sl@0
|
1019 |
PASS; \
|
sl@0
|
1020 |
else \
|
sl@0
|
1021 |
FAIL; \
|
sl@0
|
1022 |
if (start_position == 0 && max_tokens <= 0) \
|
sl@0
|
1023 |
{ \
|
sl@0
|
1024 |
total++; \
|
sl@0
|
1025 |
if (test_split (pattern, string, e1, NULL)) \
|
sl@0
|
1026 |
PASS; \
|
sl@0
|
1027 |
else \
|
sl@0
|
1028 |
FAIL; \
|
sl@0
|
1029 |
} \
|
sl@0
|
1030 |
}
|
sl@0
|
1031 |
|
sl@0
|
1032 |
#define TEST_SPLIT2(pattern, string, start_position, max_tokens, e1, e2) { \
|
sl@0
|
1033 |
total++; \
|
sl@0
|
1034 |
if (test_split_full (pattern, string, start_position, max_tokens, e1, e2, NULL)) \
|
sl@0
|
1035 |
PASS; \
|
sl@0
|
1036 |
else \
|
sl@0
|
1037 |
FAIL; \
|
sl@0
|
1038 |
if (start_position == 0 && max_tokens <= 0) \
|
sl@0
|
1039 |
{ \
|
sl@0
|
1040 |
total++; \
|
sl@0
|
1041 |
if (test_split (pattern, string, e1, e2, NULL)) \
|
sl@0
|
1042 |
PASS; \
|
sl@0
|
1043 |
else \
|
sl@0
|
1044 |
FAIL; \
|
sl@0
|
1045 |
} \
|
sl@0
|
1046 |
}
|
sl@0
|
1047 |
|
sl@0
|
1048 |
#define TEST_SPLIT3(pattern, string, start_position, max_tokens, e1, e2, e3) { \
|
sl@0
|
1049 |
total++; \
|
sl@0
|
1050 |
if (test_split_full (pattern, string, start_position, max_tokens, e1, e2, e3, NULL)) \
|
sl@0
|
1051 |
PASS; \
|
sl@0
|
1052 |
else \
|
sl@0
|
1053 |
FAIL; \
|
sl@0
|
1054 |
if (start_position == 0 && max_tokens <= 0) \
|
sl@0
|
1055 |
{ \
|
sl@0
|
1056 |
total++; \
|
sl@0
|
1057 |
if (test_split (pattern, string, e1, e2, e3, NULL)) \
|
sl@0
|
1058 |
PASS; \
|
sl@0
|
1059 |
else \
|
sl@0
|
1060 |
FAIL; \
|
sl@0
|
1061 |
} \
|
sl@0
|
1062 |
}
|
sl@0
|
1063 |
|
sl@0
|
1064 |
static gboolean
|
sl@0
|
1065 |
test_check_replacement (const gchar *string_to_expand,
|
sl@0
|
1066 |
gboolean expected,
|
sl@0
|
1067 |
gboolean expected_refs)
|
sl@0
|
1068 |
{
|
sl@0
|
1069 |
gboolean result;
|
sl@0
|
1070 |
gboolean has_refs;
|
sl@0
|
1071 |
|
sl@0
|
1072 |
verbose ("checking replacement string \"%s\" \t", string_to_expand);
|
sl@0
|
1073 |
|
sl@0
|
1074 |
result = g_regex_check_replacement (string_to_expand, &has_refs, NULL);
|
sl@0
|
1075 |
if (expected != result)
|
sl@0
|
1076 |
{
|
sl@0
|
1077 |
g_print ("failed \t(got \"%s\", expected \"%s\")\n",
|
sl@0
|
1078 |
result ? "TRUE" : "FALSE",
|
sl@0
|
1079 |
expected ? "TRUE" : "FALSE");
|
sl@0
|
1080 |
return FALSE;
|
sl@0
|
1081 |
}
|
sl@0
|
1082 |
|
sl@0
|
1083 |
if (expected && expected_refs != has_refs)
|
sl@0
|
1084 |
{
|
sl@0
|
1085 |
g_print ("failed \t(got has_references \"%s\", expected \"%s\")\n",
|
sl@0
|
1086 |
has_refs ? "TRUE" : "FALSE",
|
sl@0
|
1087 |
expected_refs ? "TRUE" : "FALSE");
|
sl@0
|
1088 |
return FALSE;
|
sl@0
|
1089 |
}
|
sl@0
|
1090 |
|
sl@0
|
1091 |
verbose ("passed\n");
|
sl@0
|
1092 |
return TRUE;
|
sl@0
|
1093 |
}
|
sl@0
|
1094 |
|
sl@0
|
1095 |
#define TEST_CHECK_REPLACEMENT(string_to_expand, expected, expected_refs) { \
|
sl@0
|
1096 |
total++; \
|
sl@0
|
1097 |
if (test_check_replacement (string_to_expand, expected, expected_refs)) \
|
sl@0
|
1098 |
PASS; \
|
sl@0
|
1099 |
else \
|
sl@0
|
1100 |
FAIL; \
|
sl@0
|
1101 |
}
|
sl@0
|
1102 |
static gboolean
|
sl@0
|
1103 |
test_expand (const gchar *pattern,
|
sl@0
|
1104 |
const gchar *string,
|
sl@0
|
1105 |
const gchar *string_to_expand,
|
sl@0
|
1106 |
gboolean raw,
|
sl@0
|
1107 |
const gchar *expected)
|
sl@0
|
1108 |
{
|
sl@0
|
1109 |
GRegex *regex = NULL;
|
sl@0
|
1110 |
GMatchInfo *match_info = NULL;
|
sl@0
|
1111 |
gchar *res;
|
sl@0
|
1112 |
|
sl@0
|
1113 |
verbose ("expanding the references in \"%s\" (pattern: \"%s\", string: \"%s\") \t",
|
sl@0
|
1114 |
string_to_expand,
|
sl@0
|
1115 |
pattern ? pattern : "(null)",
|
sl@0
|
1116 |
string ? string : "(null)");
|
sl@0
|
1117 |
|
sl@0
|
1118 |
if (pattern)
|
sl@0
|
1119 |
{
|
sl@0
|
1120 |
regex = g_regex_new (pattern, raw ? G_REGEX_RAW : 0, 0, NULL);
|
sl@0
|
1121 |
g_regex_match (regex, string, 0, &match_info);
|
sl@0
|
1122 |
}
|
sl@0
|
1123 |
|
sl@0
|
1124 |
res = g_match_info_expand_references (match_info, string_to_expand, NULL);
|
sl@0
|
1125 |
if (!streq (res, expected))
|
sl@0
|
1126 |
{
|
sl@0
|
1127 |
g_print ("failed \t(got \"%s\", expected \"%s\")\n", res, expected);
|
sl@0
|
1128 |
g_free (res);
|
sl@0
|
1129 |
g_match_info_free (match_info);
|
sl@0
|
1130 |
g_regex_unref (regex);
|
sl@0
|
1131 |
return FALSE;
|
sl@0
|
1132 |
}
|
sl@0
|
1133 |
|
sl@0
|
1134 |
g_free (res);
|
sl@0
|
1135 |
g_match_info_free (match_info);
|
sl@0
|
1136 |
if (regex)
|
sl@0
|
1137 |
g_regex_unref (regex);
|
sl@0
|
1138 |
|
sl@0
|
1139 |
verbose ("passed\n");
|
sl@0
|
1140 |
return TRUE;
|
sl@0
|
1141 |
}
|
sl@0
|
1142 |
|
sl@0
|
1143 |
#define TEST_EXPAND(pattern, string, string_to_expand, raw, expected) { \
|
sl@0
|
1144 |
total++; \
|
sl@0
|
1145 |
if (test_expand (pattern, string, string_to_expand, raw, expected)) \
|
sl@0
|
1146 |
PASS; \
|
sl@0
|
1147 |
else \
|
sl@0
|
1148 |
FAIL; \
|
sl@0
|
1149 |
}
|
sl@0
|
1150 |
|
sl@0
|
1151 |
static gboolean
|
sl@0
|
1152 |
test_replace (const gchar *pattern,
|
sl@0
|
1153 |
const gchar *string,
|
sl@0
|
1154 |
gint start_position,
|
sl@0
|
1155 |
const gchar *replacement,
|
sl@0
|
1156 |
const gchar *expected)
|
sl@0
|
1157 |
{
|
sl@0
|
1158 |
GRegex *regex;
|
sl@0
|
1159 |
gchar *res;
|
sl@0
|
1160 |
|
sl@0
|
1161 |
verbose ("replacing \"%s\" in \"%s\" (pattern: \"%s\", start: %d) \t",
|
sl@0
|
1162 |
replacement, string, pattern, start_position);
|
sl@0
|
1163 |
|
sl@0
|
1164 |
regex = g_regex_new (pattern, 0, 0, NULL);
|
sl@0
|
1165 |
res = g_regex_replace (regex, string, -1, start_position, replacement, 0, NULL);
|
sl@0
|
1166 |
if (!streq (res, expected))
|
sl@0
|
1167 |
{
|
sl@0
|
1168 |
g_print ("failed \t(got \"%s\", expected \"%s\")\n", res, expected);
|
sl@0
|
1169 |
g_free (res);
|
sl@0
|
1170 |
g_regex_unref (regex);
|
sl@0
|
1171 |
return FALSE;
|
sl@0
|
1172 |
}
|
sl@0
|
1173 |
|
sl@0
|
1174 |
g_free (res);
|
sl@0
|
1175 |
g_regex_unref (regex);
|
sl@0
|
1176 |
|
sl@0
|
1177 |
verbose ("passed\n");
|
sl@0
|
1178 |
return TRUE;
|
sl@0
|
1179 |
}
|
sl@0
|
1180 |
|
sl@0
|
1181 |
#define TEST_REPLACE(pattern, string, start_position, replacement, expected) { \
|
sl@0
|
1182 |
total++; \
|
sl@0
|
1183 |
if (test_replace (pattern, string, start_position, replacement, expected)) \
|
sl@0
|
1184 |
PASS; \
|
sl@0
|
1185 |
else \
|
sl@0
|
1186 |
FAIL; \
|
sl@0
|
1187 |
}
|
sl@0
|
1188 |
|
sl@0
|
1189 |
static gboolean
|
sl@0
|
1190 |
test_replace_lit (const gchar *pattern,
|
sl@0
|
1191 |
const gchar *string,
|
sl@0
|
1192 |
gint start_position,
|
sl@0
|
1193 |
const gchar *replacement,
|
sl@0
|
1194 |
const gchar *expected)
|
sl@0
|
1195 |
{
|
sl@0
|
1196 |
GRegex *regex;
|
sl@0
|
1197 |
gchar *res;
|
sl@0
|
1198 |
|
sl@0
|
1199 |
verbose ("replacing literally \"%s\" in \"%s\" (pattern: \"%s\", start: %d) \t",
|
sl@0
|
1200 |
replacement, string, pattern, start_position);
|
sl@0
|
1201 |
|
sl@0
|
1202 |
regex = g_regex_new (pattern, 0, 0, NULL);
|
sl@0
|
1203 |
res = g_regex_replace_literal (regex, string, -1, start_position,
|
sl@0
|
1204 |
replacement, 0, NULL);
|
sl@0
|
1205 |
if (!streq (res, expected))
|
sl@0
|
1206 |
{
|
sl@0
|
1207 |
g_print ("failed \t(got \"%s\", expected \"%s\")\n", res, expected);
|
sl@0
|
1208 |
g_free (res);
|
sl@0
|
1209 |
g_regex_unref (regex);
|
sl@0
|
1210 |
return FALSE;
|
sl@0
|
1211 |
}
|
sl@0
|
1212 |
|
sl@0
|
1213 |
g_free (res);
|
sl@0
|
1214 |
g_regex_unref (regex);
|
sl@0
|
1215 |
|
sl@0
|
1216 |
verbose ("passed\n");
|
sl@0
|
1217 |
return TRUE;
|
sl@0
|
1218 |
}
|
sl@0
|
1219 |
|
sl@0
|
1220 |
#define TEST_REPLACE_LIT(pattern, string, start_position, replacement, expected) { \
|
sl@0
|
1221 |
total++; \
|
sl@0
|
1222 |
if (test_replace_lit (pattern, string, start_position, replacement, expected)) \
|
sl@0
|
1223 |
PASS; \
|
sl@0
|
1224 |
else \
|
sl@0
|
1225 |
FAIL; \
|
sl@0
|
1226 |
}
|
sl@0
|
1227 |
|
sl@0
|
1228 |
static gboolean
|
sl@0
|
1229 |
test_get_string_number (const gchar *pattern,
|
sl@0
|
1230 |
const gchar *name,
|
sl@0
|
1231 |
gint expected_num)
|
sl@0
|
1232 |
{
|
sl@0
|
1233 |
GRegex *regex;
|
sl@0
|
1234 |
gint num;
|
sl@0
|
1235 |
|
sl@0
|
1236 |
verbose ("getting the number of \"%s\" (pattern: \"%s\") \t",
|
sl@0
|
1237 |
name, pattern);
|
sl@0
|
1238 |
|
sl@0
|
1239 |
regex = g_regex_new (pattern, 0, 0, NULL);
|
sl@0
|
1240 |
num = g_regex_get_string_number (regex, name);
|
sl@0
|
1241 |
g_regex_unref (regex);
|
sl@0
|
1242 |
|
sl@0
|
1243 |
if (num != expected_num)
|
sl@0
|
1244 |
{
|
sl@0
|
1245 |
g_print ("failed \t(got %d, expected %d)\n", num, expected_num);
|
sl@0
|
1246 |
return FALSE;
|
sl@0
|
1247 |
}
|
sl@0
|
1248 |
else
|
sl@0
|
1249 |
{
|
sl@0
|
1250 |
verbose ("passed\n");
|
sl@0
|
1251 |
return TRUE;
|
sl@0
|
1252 |
}
|
sl@0
|
1253 |
}
|
sl@0
|
1254 |
|
sl@0
|
1255 |
#define TEST_GET_STRING_NUMBER(pattern, name, expected_num) { \
|
sl@0
|
1256 |
total++; \
|
sl@0
|
1257 |
if (test_get_string_number (pattern, name, expected_num)) \
|
sl@0
|
1258 |
PASS; \
|
sl@0
|
1259 |
else \
|
sl@0
|
1260 |
FAIL; \
|
sl@0
|
1261 |
}
|
sl@0
|
1262 |
|
sl@0
|
1263 |
static gboolean
|
sl@0
|
1264 |
test_escape (const gchar *string,
|
sl@0
|
1265 |
gint length,
|
sl@0
|
1266 |
const gchar *expected)
|
sl@0
|
1267 |
{
|
sl@0
|
1268 |
gchar *escaped;
|
sl@0
|
1269 |
|
sl@0
|
1270 |
verbose ("escaping \"%s\" (len: %d) \t", string, length);
|
sl@0
|
1271 |
|
sl@0
|
1272 |
escaped = g_regex_escape_string (string, length);
|
sl@0
|
1273 |
|
sl@0
|
1274 |
if (!streq (escaped, expected))
|
sl@0
|
1275 |
{
|
sl@0
|
1276 |
g_print ("failed \t(got \"%s\", expected \"%s\")\n", escaped, expected);
|
sl@0
|
1277 |
g_free (escaped);
|
sl@0
|
1278 |
return FALSE;
|
sl@0
|
1279 |
}
|
sl@0
|
1280 |
|
sl@0
|
1281 |
g_free (escaped);
|
sl@0
|
1282 |
|
sl@0
|
1283 |
verbose ("passed\n");
|
sl@0
|
1284 |
return TRUE;
|
sl@0
|
1285 |
}
|
sl@0
|
1286 |
|
sl@0
|
1287 |
#define TEST_ESCAPE(string, length, expected) { \
|
sl@0
|
1288 |
total++; \
|
sl@0
|
1289 |
if (test_escape (string, length, expected)) \
|
sl@0
|
1290 |
PASS; \
|
sl@0
|
1291 |
else \
|
sl@0
|
1292 |
FAIL; \
|
sl@0
|
1293 |
}
|
sl@0
|
1294 |
|
sl@0
|
1295 |
static gboolean
|
sl@0
|
1296 |
test_match_all_full (const gchar *pattern,
|
sl@0
|
1297 |
const gchar *string,
|
sl@0
|
1298 |
gssize string_len,
|
sl@0
|
1299 |
gint start_position,
|
sl@0
|
1300 |
...)
|
sl@0
|
1301 |
{
|
sl@0
|
1302 |
GRegex *regex;
|
sl@0
|
1303 |
GMatchInfo *match_info;
|
sl@0
|
1304 |
va_list args;
|
sl@0
|
1305 |
GSList *expected = NULL;
|
sl@0
|
1306 |
GSList *l_exp;
|
sl@0
|
1307 |
gboolean match_ok;
|
sl@0
|
1308 |
gboolean ret = TRUE;
|
sl@0
|
1309 |
gint match_count;
|
sl@0
|
1310 |
gint i;
|
sl@0
|
1311 |
|
sl@0
|
1312 |
verbose ("matching all in \"%s\" against \"%s\" (start: %d, len: %d) \t",
|
sl@0
|
1313 |
string, pattern, start_position, string_len);
|
sl@0
|
1314 |
|
sl@0
|
1315 |
/* The va_list is a NULL-terminated sequence of: extected matched string,
|
sl@0
|
1316 |
* expected start and expected end. */
|
sl@0
|
1317 |
va_start (args, start_position);
|
sl@0
|
1318 |
while (TRUE)
|
sl@0
|
1319 |
{
|
sl@0
|
1320 |
Match *match;
|
sl@0
|
1321 |
const gchar *expected_string = va_arg (args, const gchar *);
|
sl@0
|
1322 |
if (expected_string == NULL)
|
sl@0
|
1323 |
break;
|
sl@0
|
1324 |
match = g_new0 (Match, 1);
|
sl@0
|
1325 |
match->string = g_strdup (expected_string);
|
sl@0
|
1326 |
match->start = va_arg (args, gint);
|
sl@0
|
1327 |
match->end = va_arg (args, gint);
|
sl@0
|
1328 |
expected = g_slist_prepend (expected, match);
|
sl@0
|
1329 |
}
|
sl@0
|
1330 |
expected = g_slist_reverse (expected);
|
sl@0
|
1331 |
va_end (args);
|
sl@0
|
1332 |
|
sl@0
|
1333 |
regex = g_regex_new (pattern, 0, 0, NULL);
|
sl@0
|
1334 |
match_ok = g_regex_match_all_full (regex, string, string_len, start_position,
|
sl@0
|
1335 |
0, &match_info, NULL);
|
sl@0
|
1336 |
|
sl@0
|
1337 |
if (match_ok && g_slist_length (expected) == 0)
|
sl@0
|
1338 |
{
|
sl@0
|
1339 |
g_print ("failed\n");
|
sl@0
|
1340 |
ret = FALSE;
|
sl@0
|
1341 |
goto exit;
|
sl@0
|
1342 |
}
|
sl@0
|
1343 |
if (!match_ok && g_slist_length (expected) != 0)
|
sl@0
|
1344 |
{
|
sl@0
|
1345 |
g_print ("failed\n");
|
sl@0
|
1346 |
ret = FALSE;
|
sl@0
|
1347 |
goto exit;
|
sl@0
|
1348 |
}
|
sl@0
|
1349 |
|
sl@0
|
1350 |
match_count = g_match_info_get_match_count (match_info);
|
sl@0
|
1351 |
if (match_count != g_slist_length (expected))
|
sl@0
|
1352 |
{
|
sl@0
|
1353 |
g_print ("failed \t(got %d %s, expected %d)\n", match_count,
|
sl@0
|
1354 |
match_count == 1 ? "match" : "matches",
|
sl@0
|
1355 |
g_slist_length (expected));
|
sl@0
|
1356 |
ret = FALSE;
|
sl@0
|
1357 |
goto exit;
|
sl@0
|
1358 |
}
|
sl@0
|
1359 |
|
sl@0
|
1360 |
l_exp = expected;
|
sl@0
|
1361 |
for (i = 0; i < match_count; i++)
|
sl@0
|
1362 |
{
|
sl@0
|
1363 |
gint start, end;
|
sl@0
|
1364 |
gchar *matched_string;
|
sl@0
|
1365 |
Match *exp = l_exp->data;
|
sl@0
|
1366 |
|
sl@0
|
1367 |
matched_string = g_match_info_fetch (match_info, i);
|
sl@0
|
1368 |
g_match_info_fetch_pos (match_info, i, &start, &end);
|
sl@0
|
1369 |
|
sl@0
|
1370 |
if (!streq(exp->string, matched_string))
|
sl@0
|
1371 |
{
|
sl@0
|
1372 |
g_print ("failed \t(got \"%s\", expected \"%s\")\n",
|
sl@0
|
1373 |
matched_string, exp->string);
|
sl@0
|
1374 |
g_free (matched_string);
|
sl@0
|
1375 |
ret = FALSE;
|
sl@0
|
1376 |
goto exit;
|
sl@0
|
1377 |
}
|
sl@0
|
1378 |
g_free (matched_string);
|
sl@0
|
1379 |
|
sl@0
|
1380 |
if (exp->start != start || exp->end != end)
|
sl@0
|
1381 |
{
|
sl@0
|
1382 |
g_print ("failed \t(got [%d, %d], expected [%d, %d])\n",
|
sl@0
|
1383 |
start, end, exp->start, exp->end);
|
sl@0
|
1384 |
ret = FALSE;
|
sl@0
|
1385 |
goto exit;
|
sl@0
|
1386 |
}
|
sl@0
|
1387 |
|
sl@0
|
1388 |
l_exp = g_slist_next (l_exp);
|
sl@0
|
1389 |
}
|
sl@0
|
1390 |
|
sl@0
|
1391 |
exit:
|
sl@0
|
1392 |
if (ret)
|
sl@0
|
1393 |
{
|
sl@0
|
1394 |
verbose ("passed (%d %s)\n", match_count, match_count == 1 ? "match" : "matches");
|
sl@0
|
1395 |
}
|
sl@0
|
1396 |
|
sl@0
|
1397 |
g_match_info_free (match_info);
|
sl@0
|
1398 |
g_regex_unref (regex);
|
sl@0
|
1399 |
g_slist_foreach (expected, free_match, NULL);
|
sl@0
|
1400 |
g_slist_free (expected);
|
sl@0
|
1401 |
|
sl@0
|
1402 |
return ret;
|
sl@0
|
1403 |
}
|
sl@0
|
1404 |
|
sl@0
|
1405 |
static gboolean
|
sl@0
|
1406 |
test_match_all (const gchar *pattern,
|
sl@0
|
1407 |
const gchar *string,
|
sl@0
|
1408 |
...)
|
sl@0
|
1409 |
{
|
sl@0
|
1410 |
GRegex *regex;
|
sl@0
|
1411 |
GMatchInfo *match_info;
|
sl@0
|
1412 |
va_list args;
|
sl@0
|
1413 |
GSList *expected = NULL;
|
sl@0
|
1414 |
GSList *l_exp;
|
sl@0
|
1415 |
gboolean match_ok;
|
sl@0
|
1416 |
gboolean ret = TRUE;
|
sl@0
|
1417 |
gint match_count;
|
sl@0
|
1418 |
gint i;
|
sl@0
|
1419 |
|
sl@0
|
1420 |
verbose ("matching all in \"%s\" against \"%s\" \t", string, pattern);
|
sl@0
|
1421 |
|
sl@0
|
1422 |
/* The va_list is a NULL-terminated sequence of: extected matched string,
|
sl@0
|
1423 |
* expected start and expected end. */
|
sl@0
|
1424 |
va_start (args, string);
|
sl@0
|
1425 |
while (TRUE)
|
sl@0
|
1426 |
{
|
sl@0
|
1427 |
Match *match;
|
sl@0
|
1428 |
const gchar *expected_string = va_arg (args, const gchar *);
|
sl@0
|
1429 |
if (expected_string == NULL)
|
sl@0
|
1430 |
break;
|
sl@0
|
1431 |
match = g_new0 (Match, 1);
|
sl@0
|
1432 |
match->string = g_strdup (expected_string);
|
sl@0
|
1433 |
match->start = va_arg (args, gint);
|
sl@0
|
1434 |
match->end = va_arg (args, gint);
|
sl@0
|
1435 |
expected = g_slist_prepend (expected, match);
|
sl@0
|
1436 |
}
|
sl@0
|
1437 |
expected = g_slist_reverse (expected);
|
sl@0
|
1438 |
va_end (args);
|
sl@0
|
1439 |
|
sl@0
|
1440 |
regex = g_regex_new (pattern, 0, 0, NULL);
|
sl@0
|
1441 |
match_ok = g_regex_match_all (regex, string, 0, &match_info);
|
sl@0
|
1442 |
|
sl@0
|
1443 |
if (match_ok && g_slist_length (expected) == 0)
|
sl@0
|
1444 |
{
|
sl@0
|
1445 |
g_print ("failed\n");
|
sl@0
|
1446 |
ret = FALSE;
|
sl@0
|
1447 |
goto exit;
|
sl@0
|
1448 |
}
|
sl@0
|
1449 |
if (!match_ok && g_slist_length (expected) != 0)
|
sl@0
|
1450 |
{
|
sl@0
|
1451 |
g_print ("failed\n");
|
sl@0
|
1452 |
ret = FALSE;
|
sl@0
|
1453 |
goto exit;
|
sl@0
|
1454 |
}
|
sl@0
|
1455 |
|
sl@0
|
1456 |
match_count = g_match_info_get_match_count (match_info);
|
sl@0
|
1457 |
if (match_count != g_slist_length (expected))
|
sl@0
|
1458 |
{
|
sl@0
|
1459 |
g_print ("failed \t(got %d %s, expected %d)\n", match_count,
|
sl@0
|
1460 |
match_count == 1 ? "match" : "matches",
|
sl@0
|
1461 |
g_slist_length (expected));
|
sl@0
|
1462 |
ret = FALSE;
|
sl@0
|
1463 |
goto exit;
|
sl@0
|
1464 |
}
|
sl@0
|
1465 |
|
sl@0
|
1466 |
l_exp = expected;
|
sl@0
|
1467 |
for (i = 0; i < match_count; i++)
|
sl@0
|
1468 |
{
|
sl@0
|
1469 |
gint start, end;
|
sl@0
|
1470 |
gchar *matched_string;
|
sl@0
|
1471 |
Match *exp = l_exp->data;
|
sl@0
|
1472 |
|
sl@0
|
1473 |
matched_string = g_match_info_fetch (match_info, i);
|
sl@0
|
1474 |
g_match_info_fetch_pos (match_info, i, &start, &end);
|
sl@0
|
1475 |
|
sl@0
|
1476 |
if (!streq(exp->string, matched_string))
|
sl@0
|
1477 |
{
|
sl@0
|
1478 |
g_print ("failed \t(got \"%s\", expected \"%s\")\n",
|
sl@0
|
1479 |
matched_string, exp->string);
|
sl@0
|
1480 |
g_free (matched_string);
|
sl@0
|
1481 |
ret = FALSE;
|
sl@0
|
1482 |
goto exit;
|
sl@0
|
1483 |
}
|
sl@0
|
1484 |
g_free (matched_string);
|
sl@0
|
1485 |
|
sl@0
|
1486 |
if (exp->start != start || exp->end != end)
|
sl@0
|
1487 |
{
|
sl@0
|
1488 |
g_print ("failed \t(got [%d, %d], expected [%d, %d])\n",
|
sl@0
|
1489 |
start, end, exp->start, exp->end);
|
sl@0
|
1490 |
ret = FALSE;
|
sl@0
|
1491 |
goto exit;
|
sl@0
|
1492 |
}
|
sl@0
|
1493 |
|
sl@0
|
1494 |
l_exp = g_slist_next (l_exp);
|
sl@0
|
1495 |
}
|
sl@0
|
1496 |
|
sl@0
|
1497 |
exit:
|
sl@0
|
1498 |
if (ret)
|
sl@0
|
1499 |
{
|
sl@0
|
1500 |
verbose ("passed (%d %s)\n", match_count, match_count == 1 ? "match" : "matches");
|
sl@0
|
1501 |
}
|
sl@0
|
1502 |
|
sl@0
|
1503 |
g_match_info_free (match_info);
|
sl@0
|
1504 |
g_regex_unref (regex);
|
sl@0
|
1505 |
g_slist_foreach (expected, free_match, NULL);
|
sl@0
|
1506 |
g_slist_free (expected);
|
sl@0
|
1507 |
|
sl@0
|
1508 |
return ret;
|
sl@0
|
1509 |
}
|
sl@0
|
1510 |
|
sl@0
|
1511 |
#define TEST_MATCH_ALL0(pattern, string, string_len, start_position) { \
|
sl@0
|
1512 |
total++; \
|
sl@0
|
1513 |
if (test_match_all_full (pattern, string, string_len, start_position, NULL)) \
|
sl@0
|
1514 |
PASS; \
|
sl@0
|
1515 |
else \
|
sl@0
|
1516 |
FAIL; \
|
sl@0
|
1517 |
if (string_len == -1 && start_position == 0) \
|
sl@0
|
1518 |
{ \
|
sl@0
|
1519 |
total++; \
|
sl@0
|
1520 |
if (test_match_all (pattern, string, NULL)) \
|
sl@0
|
1521 |
PASS; \
|
sl@0
|
1522 |
else \
|
sl@0
|
1523 |
FAIL; \
|
sl@0
|
1524 |
} \
|
sl@0
|
1525 |
}
|
sl@0
|
1526 |
|
sl@0
|
1527 |
#define TEST_MATCH_ALL1(pattern, string, string_len, start_position, \
|
sl@0
|
1528 |
t1, s1, e1) { \
|
sl@0
|
1529 |
total++; \
|
sl@0
|
1530 |
if (test_match_all_full (pattern, string, string_len, start_position, \
|
sl@0
|
1531 |
t1, s1, e1, NULL)) \
|
sl@0
|
1532 |
PASS; \
|
sl@0
|
1533 |
else \
|
sl@0
|
1534 |
FAIL; \
|
sl@0
|
1535 |
if (string_len == -1 && start_position == 0) \
|
sl@0
|
1536 |
{ \
|
sl@0
|
1537 |
total++; \
|
sl@0
|
1538 |
if (test_match_all (pattern, string, t1, s1, e1, NULL)) \
|
sl@0
|
1539 |
PASS; \
|
sl@0
|
1540 |
else \
|
sl@0
|
1541 |
FAIL; \
|
sl@0
|
1542 |
} \
|
sl@0
|
1543 |
}
|
sl@0
|
1544 |
|
sl@0
|
1545 |
#define TEST_MATCH_ALL2(pattern, string, string_len, start_position, \
|
sl@0
|
1546 |
t1, s1, e1, t2, s2, e2) { \
|
sl@0
|
1547 |
total++; \
|
sl@0
|
1548 |
if (test_match_all_full (pattern, string, string_len, start_position, \
|
sl@0
|
1549 |
t1, s1, e1, t2, s2, e2, NULL)) \
|
sl@0
|
1550 |
PASS; \
|
sl@0
|
1551 |
else \
|
sl@0
|
1552 |
FAIL; \
|
sl@0
|
1553 |
if (string_len == -1 && start_position == 0) \
|
sl@0
|
1554 |
{ \
|
sl@0
|
1555 |
total++; \
|
sl@0
|
1556 |
if (test_match_all (pattern, string, t1, s1, e1, t2, s2, e2, NULL)) \
|
sl@0
|
1557 |
PASS; \
|
sl@0
|
1558 |
else \
|
sl@0
|
1559 |
FAIL; \
|
sl@0
|
1560 |
} \
|
sl@0
|
1561 |
}
|
sl@0
|
1562 |
|
sl@0
|
1563 |
#define TEST_MATCH_ALL3(pattern, string, string_len, start_position, \
|
sl@0
|
1564 |
t1, s1, e1, t2, s2, e2, t3, s3, e3) { \
|
sl@0
|
1565 |
total++; \
|
sl@0
|
1566 |
if (test_match_all_full (pattern, string, string_len, start_position, \
|
sl@0
|
1567 |
t1, s1, e1, t2, s2, e2, t3, s3, e3, NULL)) \
|
sl@0
|
1568 |
PASS; \
|
sl@0
|
1569 |
else \
|
sl@0
|
1570 |
FAIL; \
|
sl@0
|
1571 |
if (string_len == -1 && start_position == 0) \
|
sl@0
|
1572 |
{ \
|
sl@0
|
1573 |
total++; \
|
sl@0
|
1574 |
if (test_match_all (pattern, string, t1, s1, e1, t2, s2, e2, t3, s3, e3, NULL)) \
|
sl@0
|
1575 |
PASS; \
|
sl@0
|
1576 |
else \
|
sl@0
|
1577 |
FAIL; \
|
sl@0
|
1578 |
} \
|
sl@0
|
1579 |
}
|
sl@0
|
1580 |
|
sl@0
|
1581 |
int
|
sl@0
|
1582 |
main (int argc, char *argv[])
|
sl@0
|
1583 |
{
|
sl@0
|
1584 |
gint total = 0;
|
sl@0
|
1585 |
gint passed = 0;
|
sl@0
|
1586 |
gint failed = 0;
|
sl@0
|
1587 |
gint i = 0;
|
sl@0
|
1588 |
#ifdef __SYMBIAN32__
|
sl@0
|
1589 |
g_log_set_handler (NULL, G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG, &mrtLogHandler, NULL);
|
sl@0
|
1590 |
g_set_print_handler(mrtPrintHandler);
|
sl@0
|
1591 |
#endif /*__SYMBIAN32__*/
|
sl@0
|
1592 |
setlocale (LC_ALL, "");
|
sl@0
|
1593 |
|
sl@0
|
1594 |
for (i = 1; i < argc; i++)
|
sl@0
|
1595 |
{
|
sl@0
|
1596 |
if (streq ("-noisy", argv[i]))
|
sl@0
|
1597 |
noisy = TRUE;
|
sl@0
|
1598 |
else if (streq ("-abort", argv[i]))
|
sl@0
|
1599 |
abort_on_fail = TRUE;
|
sl@0
|
1600 |
}
|
sl@0
|
1601 |
|
sl@0
|
1602 |
g_setenv ("G_DEBUG", "fatal_warnings", TRUE);
|
sl@0
|
1603 |
|
sl@0
|
1604 |
/* TEST_NEW(pattern, compile_opts, match_opts) */
|
sl@0
|
1605 |
TEST_NEW("", 0, 0);
|
sl@0
|
1606 |
TEST_NEW(".*", 0, 0);
|
sl@0
|
1607 |
TEST_NEW(".*", G_REGEX_OPTIMIZE, 0);
|
sl@0
|
1608 |
TEST_NEW(".*", G_REGEX_MULTILINE, 0);
|
sl@0
|
1609 |
TEST_NEW(".*", G_REGEX_DOTALL, 0);
|
sl@0
|
1610 |
TEST_NEW(".*", G_REGEX_DOTALL, G_REGEX_MATCH_NOTBOL);
|
sl@0
|
1611 |
TEST_NEW("(123\\d*)[a-zA-Z]+(?P<hello>.*)", 0, 0);
|
sl@0
|
1612 |
TEST_NEW("(123\\d*)[a-zA-Z]+(?P<hello>.*)", G_REGEX_CASELESS, 0);
|
sl@0
|
1613 |
TEST_NEW("(123\\d*)[a-zA-Z]+(?P<hello>.*)", G_REGEX_CASELESS | G_REGEX_OPTIMIZE, 0);
|
sl@0
|
1614 |
TEST_NEW("(?P<A>x)|(?P<A>y)", G_REGEX_DUPNAMES, 0);
|
sl@0
|
1615 |
TEST_NEW("(?P<A>x)|(?P<A>y)", G_REGEX_DUPNAMES | G_REGEX_OPTIMIZE, 0);
|
sl@0
|
1616 |
/* This gives "internal error: code overflow" with pcre 6.0 */
|
sl@0
|
1617 |
TEST_NEW("(?i)(?-i)", 0, 0);
|
sl@0
|
1618 |
|
sl@0
|
1619 |
/* TEST_NEW_FAIL(pattern, compile_opts, expected_error) */
|
sl@0
|
1620 |
TEST_NEW_FAIL("(", 0, G_REGEX_ERROR_UNMATCHED_PARENTHESIS);
|
sl@0
|
1621 |
TEST_NEW_FAIL(")", 0, G_REGEX_ERROR_UNMATCHED_PARENTHESIS);
|
sl@0
|
1622 |
TEST_NEW_FAIL("[", 0, G_REGEX_ERROR_UNTERMINATED_CHARACTER_CLASS);
|
sl@0
|
1623 |
TEST_NEW_FAIL("*", 0, G_REGEX_ERROR_NOTHING_TO_REPEAT);
|
sl@0
|
1624 |
TEST_NEW_FAIL("?", 0, G_REGEX_ERROR_NOTHING_TO_REPEAT);
|
sl@0
|
1625 |
TEST_NEW_FAIL("(?P<A>x)|(?P<A>y)", 0, G_REGEX_ERROR_DUPLICATE_SUBPATTERN_NAME);
|
sl@0
|
1626 |
|
sl@0
|
1627 |
/* TEST_MATCH_SIMPLE(pattern, string, compile_opts, match_opts, expected) */
|
sl@0
|
1628 |
TEST_MATCH_SIMPLE("a", "", 0, 0, FALSE);
|
sl@0
|
1629 |
TEST_MATCH_SIMPLE("a", "a", 0, 0, TRUE);
|
sl@0
|
1630 |
TEST_MATCH_SIMPLE("a", "ba", 0, 0, TRUE);
|
sl@0
|
1631 |
TEST_MATCH_SIMPLE("^a", "ba", 0, 0, FALSE);
|
sl@0
|
1632 |
TEST_MATCH_SIMPLE("a", "ba", G_REGEX_ANCHORED, 0, FALSE);
|
sl@0
|
1633 |
TEST_MATCH_SIMPLE("a", "ba", 0, G_REGEX_MATCH_ANCHORED, FALSE);
|
sl@0
|
1634 |
TEST_MATCH_SIMPLE("a", "ab", G_REGEX_ANCHORED, 0, TRUE);
|
sl@0
|
1635 |
TEST_MATCH_SIMPLE("a", "ab", 0, G_REGEX_MATCH_ANCHORED, TRUE);
|
sl@0
|
1636 |
TEST_MATCH_SIMPLE("a", "a", G_REGEX_CASELESS, 0, TRUE);
|
sl@0
|
1637 |
TEST_MATCH_SIMPLE("a", "A", G_REGEX_CASELESS, 0, TRUE);
|
sl@0
|
1638 |
/* These are needed to test extended properties. */
|
sl@0
|
1639 |
TEST_MATCH_SIMPLE(AGRAVE, AGRAVE, G_REGEX_CASELESS, 0, TRUE);
|
sl@0
|
1640 |
TEST_MATCH_SIMPLE(AGRAVE, AGRAVE_UPPER, G_REGEX_CASELESS, 0, TRUE);
|
sl@0
|
1641 |
TEST_MATCH_SIMPLE("\\p{L}", "a", 0, 0, TRUE);
|
sl@0
|
1642 |
TEST_MATCH_SIMPLE("\\p{L}", "1", 0, 0, FALSE);
|
sl@0
|
1643 |
TEST_MATCH_SIMPLE("\\p{L}", AGRAVE, 0, 0, TRUE);
|
sl@0
|
1644 |
TEST_MATCH_SIMPLE("\\p{L}", AGRAVE_UPPER, 0, 0, TRUE);
|
sl@0
|
1645 |
TEST_MATCH_SIMPLE("\\p{L}", SHEEN, 0, 0, TRUE);
|
sl@0
|
1646 |
TEST_MATCH_SIMPLE("\\p{L}", ETH30, 0, 0, FALSE);
|
sl@0
|
1647 |
TEST_MATCH_SIMPLE("\\p{Ll}", "a", 0, 0, TRUE);
|
sl@0
|
1648 |
TEST_MATCH_SIMPLE("\\p{Ll}", AGRAVE, 0, 0, TRUE);
|
sl@0
|
1649 |
TEST_MATCH_SIMPLE("\\p{Ll}", AGRAVE_UPPER, 0, 0, FALSE);
|
sl@0
|
1650 |
TEST_MATCH_SIMPLE("\\p{Ll}", ETH30, 0, 0, FALSE);
|
sl@0
|
1651 |
TEST_MATCH_SIMPLE("\\p{Sc}", AGRAVE, 0, 0, FALSE);
|
sl@0
|
1652 |
TEST_MATCH_SIMPLE("\\p{Sc}", EURO, 0, 0, TRUE);
|
sl@0
|
1653 |
TEST_MATCH_SIMPLE("\\p{Sc}", ETH30, 0, 0, FALSE);
|
sl@0
|
1654 |
TEST_MATCH_SIMPLE("\\p{N}", "a", 0, 0, FALSE);
|
sl@0
|
1655 |
TEST_MATCH_SIMPLE("\\p{N}", "1", 0, 0, TRUE);
|
sl@0
|
1656 |
TEST_MATCH_SIMPLE("\\p{N}", AGRAVE, 0, 0, FALSE);
|
sl@0
|
1657 |
TEST_MATCH_SIMPLE("\\p{N}", AGRAVE_UPPER, 0, 0, FALSE);
|
sl@0
|
1658 |
TEST_MATCH_SIMPLE("\\p{N}", SHEEN, 0, 0, FALSE);
|
sl@0
|
1659 |
TEST_MATCH_SIMPLE("\\p{N}", ETH30, 0, 0, TRUE);
|
sl@0
|
1660 |
TEST_MATCH_SIMPLE("\\p{Nd}", "a", 0, 0, FALSE);
|
sl@0
|
1661 |
TEST_MATCH_SIMPLE("\\p{Nd}", "1", 0, 0, TRUE);
|
sl@0
|
1662 |
TEST_MATCH_SIMPLE("\\p{Nd}", AGRAVE, 0, 0, FALSE);
|
sl@0
|
1663 |
TEST_MATCH_SIMPLE("\\p{Nd}", AGRAVE_UPPER, 0, 0, FALSE);
|
sl@0
|
1664 |
TEST_MATCH_SIMPLE("\\p{Nd}", SHEEN, 0, 0, FALSE);
|
sl@0
|
1665 |
TEST_MATCH_SIMPLE("\\p{Nd}", ETH30, 0, 0, FALSE);
|
sl@0
|
1666 |
TEST_MATCH_SIMPLE("\\p{Common}", SHEEN, 0, 0, FALSE);
|
sl@0
|
1667 |
TEST_MATCH_SIMPLE("\\p{Common}", "a", 0, 0, FALSE);
|
sl@0
|
1668 |
TEST_MATCH_SIMPLE("\\p{Common}", AGRAVE, 0, 0, FALSE);
|
sl@0
|
1669 |
TEST_MATCH_SIMPLE("\\p{Common}", AGRAVE_UPPER, 0, 0, FALSE);
|
sl@0
|
1670 |
TEST_MATCH_SIMPLE("\\p{Common}", ETH30, 0, 0, FALSE);
|
sl@0
|
1671 |
TEST_MATCH_SIMPLE("\\p{Common}", "%", 0, 0, TRUE);
|
sl@0
|
1672 |
TEST_MATCH_SIMPLE("\\p{Common}", "1", 0, 0, TRUE);
|
sl@0
|
1673 |
TEST_MATCH_SIMPLE("\\p{Arabic}", SHEEN, 0, 0, TRUE);
|
sl@0
|
1674 |
TEST_MATCH_SIMPLE("\\p{Arabic}", "a", 0, 0, FALSE);
|
sl@0
|
1675 |
TEST_MATCH_SIMPLE("\\p{Arabic}", AGRAVE, 0, 0, FALSE);
|
sl@0
|
1676 |
TEST_MATCH_SIMPLE("\\p{Arabic}", AGRAVE_UPPER, 0, 0, FALSE);
|
sl@0
|
1677 |
TEST_MATCH_SIMPLE("\\p{Arabic}", ETH30, 0, 0, FALSE);
|
sl@0
|
1678 |
TEST_MATCH_SIMPLE("\\p{Arabic}", "%", 0, 0, FALSE);
|
sl@0
|
1679 |
TEST_MATCH_SIMPLE("\\p{Arabic}", "1", 0, 0, FALSE);
|
sl@0
|
1680 |
TEST_MATCH_SIMPLE("\\p{Latin}", SHEEN, 0, 0, FALSE);
|
sl@0
|
1681 |
TEST_MATCH_SIMPLE("\\p{Latin}", "a", 0, 0, TRUE);
|
sl@0
|
1682 |
TEST_MATCH_SIMPLE("\\p{Latin}", AGRAVE, 0, 0, TRUE);
|
sl@0
|
1683 |
TEST_MATCH_SIMPLE("\\p{Latin}", AGRAVE_UPPER, 0, 0, TRUE);
|
sl@0
|
1684 |
TEST_MATCH_SIMPLE("\\p{Latin}", ETH30, 0, 0, FALSE);
|
sl@0
|
1685 |
TEST_MATCH_SIMPLE("\\p{Latin}", "%", 0, 0, FALSE);
|
sl@0
|
1686 |
TEST_MATCH_SIMPLE("\\p{Latin}", "1", 0, 0, FALSE);
|
sl@0
|
1687 |
TEST_MATCH_SIMPLE("\\p{Ethiopic}", SHEEN, 0, 0, FALSE);
|
sl@0
|
1688 |
TEST_MATCH_SIMPLE("\\p{Ethiopic}", "a", 0, 0, FALSE);
|
sl@0
|
1689 |
TEST_MATCH_SIMPLE("\\p{Ethiopic}", AGRAVE, 0, 0, FALSE);
|
sl@0
|
1690 |
TEST_MATCH_SIMPLE("\\p{Ethiopic}", AGRAVE_UPPER, 0, 0, FALSE);
|
sl@0
|
1691 |
TEST_MATCH_SIMPLE("\\p{Ethiopic}", ETH30, 0, 0, TRUE);
|
sl@0
|
1692 |
TEST_MATCH_SIMPLE("\\p{Ethiopic}", "%", 0, 0, FALSE);
|
sl@0
|
1693 |
TEST_MATCH_SIMPLE("\\p{Ethiopic}", "1", 0, 0, FALSE);
|
sl@0
|
1694 |
TEST_MATCH_SIMPLE("\\p{L}(?<=\\p{Arabic})", SHEEN, 0, 0, TRUE);
|
sl@0
|
1695 |
TEST_MATCH_SIMPLE("\\p{L}(?<=\\p{Latin})", SHEEN, 0, 0, FALSE);
|
sl@0
|
1696 |
/* Invalid patterns. */
|
sl@0
|
1697 |
TEST_MATCH_SIMPLE("\\", "a", 0, 0, FALSE);
|
sl@0
|
1698 |
TEST_MATCH_SIMPLE("[", "", 0, 0, FALSE);
|
sl@0
|
1699 |
|
sl@0
|
1700 |
/* TEST_MATCH(pattern, compile_opts, match_opts, string,
|
sl@0
|
1701 |
* string_len, start_position, match_opts2, expected) */
|
sl@0
|
1702 |
TEST_MATCH("a", 0, 0, "a", -1, 0, 0, TRUE);
|
sl@0
|
1703 |
TEST_MATCH("a", 0, 0, "A", -1, 0, 0, FALSE);
|
sl@0
|
1704 |
TEST_MATCH("a", G_REGEX_CASELESS, 0, "A", -1, 0, 0, TRUE);
|
sl@0
|
1705 |
TEST_MATCH("a", 0, 0, "ab", -1, 1, 0, FALSE);
|
sl@0
|
1706 |
TEST_MATCH("a", 0, 0, "ba", 1, 0, 0, FALSE);
|
sl@0
|
1707 |
TEST_MATCH("a", 0, 0, "bab", -1, 0, 0, TRUE);
|
sl@0
|
1708 |
TEST_MATCH("a", 0, 0, "b", -1, 0, 0, FALSE);
|
sl@0
|
1709 |
TEST_MATCH("a", 0, G_REGEX_ANCHORED, "a", -1, 0, 0, TRUE);
|
sl@0
|
1710 |
TEST_MATCH("a", 0, G_REGEX_ANCHORED, "ab", -1, 1, 0, FALSE);
|
sl@0
|
1711 |
TEST_MATCH("a", 0, G_REGEX_ANCHORED, "ba", 1, 0, 0, FALSE);
|
sl@0
|
1712 |
TEST_MATCH("a", 0, G_REGEX_ANCHORED, "bab", -1, 0, 0, FALSE);
|
sl@0
|
1713 |
TEST_MATCH("a", 0, G_REGEX_ANCHORED, "b", -1, 0, 0, FALSE);
|
sl@0
|
1714 |
TEST_MATCH("a", 0, 0, "a", -1, 0, G_REGEX_ANCHORED, TRUE);
|
sl@0
|
1715 |
TEST_MATCH("a", 0, 0, "ab", -1, 1, G_REGEX_ANCHORED, FALSE);
|
sl@0
|
1716 |
TEST_MATCH("a", 0, 0, "ba", 1, 0, G_REGEX_ANCHORED, FALSE);
|
sl@0
|
1717 |
TEST_MATCH("a", 0, 0, "bab", -1, 0, G_REGEX_ANCHORED, FALSE);
|
sl@0
|
1718 |
TEST_MATCH("a", 0, 0, "b", -1, 0, G_REGEX_ANCHORED, FALSE);
|
sl@0
|
1719 |
TEST_MATCH("a|b", 0, 0, "a", -1, 0, 0, TRUE);
|
sl@0
|
1720 |
TEST_MATCH("\\d", 0, 0, EURO, -1, 0, 0, FALSE);
|
sl@0
|
1721 |
TEST_MATCH("^.$", 0, 0, EURO, -1, 0, 0, TRUE);
|
sl@0
|
1722 |
TEST_MATCH("^.{3}$", 0, 0, EURO, -1, 0, 0, FALSE);
|
sl@0
|
1723 |
TEST_MATCH("^.$", G_REGEX_RAW, 0, EURO, -1, 0, 0, FALSE);
|
sl@0
|
1724 |
TEST_MATCH("^.{3}$", G_REGEX_RAW, 0, EURO, -1, 0, 0, TRUE);
|
sl@0
|
1725 |
TEST_MATCH(AGRAVE, G_REGEX_CASELESS, 0, AGRAVE_UPPER, -1, 0, 0, TRUE);
|
sl@0
|
1726 |
|
sl@0
|
1727 |
/* New lines handling. */
|
sl@0
|
1728 |
TEST_MATCH("^a\\Rb$", 0, 0, "a\r\nb", -1, 0, 0, TRUE);
|
sl@0
|
1729 |
TEST_MATCH("^a\\Rb$", 0, 0, "a\nb", -1, 0, 0, TRUE);
|
sl@0
|
1730 |
TEST_MATCH("^a\\Rb$", 0, 0, "a\rb", -1, 0, 0, TRUE);
|
sl@0
|
1731 |
TEST_MATCH("^a\\Rb$", 0, 0, "a\n\rb", -1, 0, 0, FALSE);
|
sl@0
|
1732 |
TEST_MATCH("^a\\R\\Rb$", 0, 0, "a\n\rb", -1, 0, 0, TRUE);
|
sl@0
|
1733 |
TEST_MATCH("^a\\nb$", 0, 0, "a\r\nb", -1, 0, 0, FALSE);
|
sl@0
|
1734 |
TEST_MATCH("^a\\r\\nb$", 0, 0, "a\r\nb", -1, 0, 0, TRUE);
|
sl@0
|
1735 |
|
sl@0
|
1736 |
TEST_MATCH("^b$", 0, 0, "a\nb\nc", -1, 0, 0, FALSE);
|
sl@0
|
1737 |
TEST_MATCH("^b$", G_REGEX_MULTILINE, 0, "a\nb\nc", -1, 0, 0, TRUE);
|
sl@0
|
1738 |
TEST_MATCH("^b$", G_REGEX_MULTILINE, 0, "a\r\nb\r\nc", -1, 0, 0, TRUE);
|
sl@0
|
1739 |
TEST_MATCH("^b$", G_REGEX_MULTILINE, 0, "a\rb\rc", -1, 0, 0, TRUE);
|
sl@0
|
1740 |
TEST_MATCH("^b$", G_REGEX_MULTILINE | G_REGEX_NEWLINE_CR, 0, "a\nb\nc", -1, 0, 0, FALSE);
|
sl@0
|
1741 |
TEST_MATCH("^b$", G_REGEX_MULTILINE | G_REGEX_NEWLINE_LF, 0, "a\nb\nc", -1, 0, 0, TRUE);
|
sl@0
|
1742 |
TEST_MATCH("^b$", G_REGEX_MULTILINE | G_REGEX_NEWLINE_CRLF, 0, "a\nb\nc", -1, 0, 0, FALSE);
|
sl@0
|
1743 |
TEST_MATCH("^b$", G_REGEX_MULTILINE | G_REGEX_NEWLINE_CR, 0, "a\r\nb\r\nc", -1, 0, 0, FALSE);
|
sl@0
|
1744 |
TEST_MATCH("^b$", G_REGEX_MULTILINE | G_REGEX_NEWLINE_LF, 0, "a\r\nb\r\nc", -1, 0, 0, FALSE);
|
sl@0
|
1745 |
TEST_MATCH("^b$", G_REGEX_MULTILINE | G_REGEX_NEWLINE_CRLF, 0, "a\r\nb\r\nc", -1, 0, 0, TRUE);
|
sl@0
|
1746 |
TEST_MATCH("^b$", G_REGEX_MULTILINE | G_REGEX_NEWLINE_CR, 0, "a\rb\rc", -1, 0, 0, TRUE);
|
sl@0
|
1747 |
TEST_MATCH("^b$", G_REGEX_MULTILINE | G_REGEX_NEWLINE_LF, 0, "a\rb\rc", -1, 0, 0, FALSE);
|
sl@0
|
1748 |
TEST_MATCH("^b$", G_REGEX_MULTILINE | G_REGEX_NEWLINE_CRLF, 0, "a\rb\rc", -1, 0, 0, FALSE);
|
sl@0
|
1749 |
TEST_MATCH("^b$", G_REGEX_MULTILINE, G_REGEX_MATCH_NEWLINE_CR, "a\nb\nc", -1, 0, 0, FALSE);
|
sl@0
|
1750 |
TEST_MATCH("^b$", G_REGEX_MULTILINE, G_REGEX_MATCH_NEWLINE_LF, "a\nb\nc", -1, 0, 0, TRUE);
|
sl@0
|
1751 |
TEST_MATCH("^b$", G_REGEX_MULTILINE, G_REGEX_MATCH_NEWLINE_CRLF, "a\nb\nc", -1, 0, 0, FALSE);
|
sl@0
|
1752 |
TEST_MATCH("^b$", G_REGEX_MULTILINE, G_REGEX_MATCH_NEWLINE_CR, "a\r\nb\r\nc", -1, 0, 0, FALSE);
|
sl@0
|
1753 |
TEST_MATCH("^b$", G_REGEX_MULTILINE, G_REGEX_MATCH_NEWLINE_LF, "a\r\nb\r\nc", -1, 0, 0, FALSE);
|
sl@0
|
1754 |
TEST_MATCH("^b$", G_REGEX_MULTILINE, G_REGEX_MATCH_NEWLINE_CRLF, "a\r\nb\r\nc", -1, 0, 0, TRUE);
|
sl@0
|
1755 |
TEST_MATCH("^b$", G_REGEX_MULTILINE, G_REGEX_MATCH_NEWLINE_CR, "a\rb\rc", -1, 0, 0, TRUE);
|
sl@0
|
1756 |
TEST_MATCH("^b$", G_REGEX_MULTILINE, G_REGEX_MATCH_NEWLINE_LF, "a\rb\rc", -1, 0, 0, FALSE);
|
sl@0
|
1757 |
TEST_MATCH("^b$", G_REGEX_MULTILINE, G_REGEX_MATCH_NEWLINE_CRLF, "a\rb\rc", -1, 0, 0, FALSE);
|
sl@0
|
1758 |
|
sl@0
|
1759 |
TEST_MATCH("^b$", G_REGEX_MULTILINE | G_REGEX_NEWLINE_CR, G_REGEX_MATCH_NEWLINE_ANY, "a\nb\nc", -1, 0, 0, TRUE);
|
sl@0
|
1760 |
TEST_MATCH("^b$", G_REGEX_MULTILINE | G_REGEX_NEWLINE_CR, G_REGEX_MATCH_NEWLINE_ANY, "a\rb\rc", -1, 0, 0, TRUE);
|
sl@0
|
1761 |
TEST_MATCH("^b$", G_REGEX_MULTILINE | G_REGEX_NEWLINE_CR, G_REGEX_MATCH_NEWLINE_ANY, "a\r\nb\r\nc", -1, 0, 0, TRUE);
|
sl@0
|
1762 |
TEST_MATCH("^b$", G_REGEX_MULTILINE | G_REGEX_NEWLINE_CR, G_REGEX_MATCH_NEWLINE_LF, "a\nb\nc", -1, 0, 0, TRUE);
|
sl@0
|
1763 |
TEST_MATCH("^b$", G_REGEX_MULTILINE | G_REGEX_NEWLINE_CR, G_REGEX_MATCH_NEWLINE_LF, "a\rb\rc", -1, 0, 0, FALSE);
|
sl@0
|
1764 |
TEST_MATCH("^b$", G_REGEX_MULTILINE | G_REGEX_NEWLINE_CR, G_REGEX_MATCH_NEWLINE_CRLF, "a\r\nb\r\nc", -1, 0, 0, TRUE);
|
sl@0
|
1765 |
TEST_MATCH("^b$", G_REGEX_MULTILINE | G_REGEX_NEWLINE_CR, G_REGEX_MATCH_NEWLINE_CRLF, "a\rb\rc", -1, 0, 0, FALSE);
|
sl@0
|
1766 |
|
sl@0
|
1767 |
TEST_MATCH("a#\nb", G_REGEX_EXTENDED, 0, "a", -1, 0, 0, FALSE);
|
sl@0
|
1768 |
TEST_MATCH("a#\r\nb", G_REGEX_EXTENDED, 0, "a", -1, 0, 0, FALSE);
|
sl@0
|
1769 |
TEST_MATCH("a#\rb", G_REGEX_EXTENDED, 0, "a", -1, 0, 0, FALSE);
|
sl@0
|
1770 |
TEST_MATCH("a#\nb", G_REGEX_EXTENDED, G_REGEX_MATCH_NEWLINE_CR, "a", -1, 0, 0, FALSE);
|
sl@0
|
1771 |
TEST_MATCH("a#\nb", G_REGEX_EXTENDED | G_REGEX_NEWLINE_CR, 0, "a", -1, 0, 0, TRUE);
|
sl@0
|
1772 |
|
sl@0
|
1773 |
/* TEST_MATCH_NEXT#(pattern, string, string_len, start_position, ...) */
|
sl@0
|
1774 |
TEST_MATCH_NEXT0("a", "x", -1, 0);
|
sl@0
|
1775 |
TEST_MATCH_NEXT0("a", "ax", -1, 1);
|
sl@0
|
1776 |
TEST_MATCH_NEXT0("a", "xa", 1, 0);
|
sl@0
|
1777 |
TEST_MATCH_NEXT0("a", "axa", 1, 2);
|
sl@0
|
1778 |
TEST_MATCH_NEXT1("a", "a", -1, 0, "a", 0, 1);
|
sl@0
|
1779 |
TEST_MATCH_NEXT1("a", "xax", -1, 0, "a", 1, 2);
|
sl@0
|
1780 |
TEST_MATCH_NEXT1(EURO, ENG EURO, -1, 0, EURO, 2, 5);
|
sl@0
|
1781 |
TEST_MATCH_NEXT1("a*", "", -1, 0, "", 0, 0);
|
sl@0
|
1782 |
TEST_MATCH_NEXT2("a*", "aa", -1, 0, "aa", 0, 2, "", 2, 2);
|
sl@0
|
1783 |
TEST_MATCH_NEXT2(EURO "*", EURO EURO, -1, 0, EURO EURO, 0, 6, "", 6, 6);
|
sl@0
|
1784 |
TEST_MATCH_NEXT2("a", "axa", -1, 0, "a", 0, 1, "a", 2, 3);
|
sl@0
|
1785 |
TEST_MATCH_NEXT2("a+", "aaxa", -1, 0, "aa", 0, 2, "a", 3, 4);
|
sl@0
|
1786 |
TEST_MATCH_NEXT2("a", "aa", -1, 0, "a", 0, 1, "a", 1, 2);
|
sl@0
|
1787 |
TEST_MATCH_NEXT2("a", "ababa", -1, 2, "a", 2, 3, "a", 4, 5);
|
sl@0
|
1788 |
TEST_MATCH_NEXT2(EURO "+", EURO "-" EURO, -1, 0, EURO, 0, 3, EURO, 4, 7);
|
sl@0
|
1789 |
TEST_MATCH_NEXT3("", "ab", -1, 0, "", 0, 0, "", 1, 1, "", 2, 2);
|
sl@0
|
1790 |
TEST_MATCH_NEXT3("", AGRAVE "b", -1, 0, "", 0, 0, "", 2, 2, "", 3, 3);
|
sl@0
|
1791 |
TEST_MATCH_NEXT3("a", "aaxa", -1, 0, "a", 0, 1, "a", 1, 2, "a", 3, 4);
|
sl@0
|
1792 |
TEST_MATCH_NEXT3("a", "aa" OGRAVE "a", -1, 0, "a", 0, 1, "a", 1, 2, "a", 4, 5);
|
sl@0
|
1793 |
TEST_MATCH_NEXT3("a*", "aax", -1, 0, "aa", 0, 2, "", 2, 2, "", 3, 3);
|
sl@0
|
1794 |
TEST_MATCH_NEXT3("(?=[A-Z0-9])", "RegExTest", -1, 0, "", 0, 0, "", 3, 3, "", 5, 5);
|
sl@0
|
1795 |
TEST_MATCH_NEXT4("a*", "aaxa", -1, 0, "aa", 0, 2, "", 2, 2, "a", 3, 4, "", 4, 4);
|
sl@0
|
1796 |
|
sl@0
|
1797 |
/* TEST_MATCH_COUNT(pattern, string, start_position, match_opts, expected_count) */
|
sl@0
|
1798 |
TEST_MATCH_COUNT("a", "", 0, 0, 0);
|
sl@0
|
1799 |
TEST_MATCH_COUNT("a", "a", 0, 0, 1);
|
sl@0
|
1800 |
TEST_MATCH_COUNT("a", "a", 1, 0, 0);
|
sl@0
|
1801 |
TEST_MATCH_COUNT("(.)", "a", 0, 0, 2);
|
sl@0
|
1802 |
TEST_MATCH_COUNT("(.)", EURO, 0, 0, 2);
|
sl@0
|
1803 |
TEST_MATCH_COUNT("(?:.)", "a", 0, 0, 1);
|
sl@0
|
1804 |
TEST_MATCH_COUNT("(?P<A>.)", "a", 0, 0, 2);
|
sl@0
|
1805 |
TEST_MATCH_COUNT("a$", "a", 0, G_REGEX_MATCH_NOTEOL, 0);
|
sl@0
|
1806 |
TEST_MATCH_COUNT("(a)?(b)", "b", 0, 0, 3);
|
sl@0
|
1807 |
TEST_MATCH_COUNT("(a)?(b)", "ab", 0, 0, 3);
|
sl@0
|
1808 |
|
sl@0
|
1809 |
/* TEST_PARTIAL(pattern, string, expected) */
|
sl@0
|
1810 |
TEST_PARTIAL("^ab", "a", TRUE);
|
sl@0
|
1811 |
TEST_PARTIAL("^ab", "xa", FALSE);
|
sl@0
|
1812 |
TEST_PARTIAL("ab", "xa", TRUE);
|
sl@0
|
1813 |
TEST_PARTIAL("ab", "ab", FALSE); /* normal match. */
|
sl@0
|
1814 |
TEST_PARTIAL("a+b", "aa", FALSE); /* PCRE_ERROR_BAD_PARTIAL */
|
sl@0
|
1815 |
TEST_PARTIAL("(a)+b", "aa", TRUE);
|
sl@0
|
1816 |
TEST_PARTIAL("a?b", "a", TRUE);
|
sl@0
|
1817 |
|
sl@0
|
1818 |
/* TEST_SUB_PATTERN(pattern, string, start_position, sub_n, expected_sub,
|
sl@0
|
1819 |
* expected_start, expected_end) */
|
sl@0
|
1820 |
TEST_SUB_PATTERN("a", "a", 0, 0, "a", 0, 1);
|
sl@0
|
1821 |
TEST_SUB_PATTERN("a(.)", "ab", 0, 1, "b", 1, 2);
|
sl@0
|
1822 |
TEST_SUB_PATTERN("a(.)", "a" EURO, 0, 1, EURO, 1, 4);
|
sl@0
|
1823 |
TEST_SUB_PATTERN("(?:.*)(a)(.)", "xxa" ENG, 0, 2, ENG, 3, 5);
|
sl@0
|
1824 |
TEST_SUB_PATTERN("(" HSTROKE ")", "a" HSTROKE ENG, 0, 1, HSTROKE, 1, 3);
|
sl@0
|
1825 |
TEST_SUB_PATTERN("a", "a", 0, 1, NULL, UNTOUCHED, UNTOUCHED);
|
sl@0
|
1826 |
TEST_SUB_PATTERN("a", "a", 0, 1, NULL, UNTOUCHED, UNTOUCHED);
|
sl@0
|
1827 |
TEST_SUB_PATTERN("(a)?(b)", "b", 0, 0, "b", 0, 1);
|
sl@0
|
1828 |
TEST_SUB_PATTERN("(a)?(b)", "b", 0, 1, "", -1, -1);
|
sl@0
|
1829 |
TEST_SUB_PATTERN("(a)?(b)", "b", 0, 2, "b", 0, 1);
|
sl@0
|
1830 |
|
sl@0
|
1831 |
/* TEST_NAMED_SUB_PATTERN(pattern, string, start_position, sub_name,
|
sl@0
|
1832 |
* expected_sub, expected_start, expected_end) */
|
sl@0
|
1833 |
TEST_NAMED_SUB_PATTERN("a(?P<A>.)(?P<B>.)?", "ab", 0, "A", "b", 1, 2);
|
sl@0
|
1834 |
TEST_NAMED_SUB_PATTERN("a(?P<A>.)(?P<B>.)?", "aab", 1, "A", "b", 2, 3);
|
sl@0
|
1835 |
TEST_NAMED_SUB_PATTERN("a(?P<A>.)(?P<B>.)?", EURO "ab", 0, "A", "b", 4, 5);
|
sl@0
|
1836 |
TEST_NAMED_SUB_PATTERN("a(?P<A>.)(?P<B>.)?", EURO "ab", 0, "B", NULL, UNTOUCHED, UNTOUCHED);
|
sl@0
|
1837 |
TEST_NAMED_SUB_PATTERN("a(?P<A>.)(?P<B>.)?", EURO "ab", 0, "C", NULL, UNTOUCHED, UNTOUCHED);
|
sl@0
|
1838 |
TEST_NAMED_SUB_PATTERN("a(?P<A>.)(?P<B>.)?", "a" EGRAVE "x", 0, "A", EGRAVE, 1, 3);
|
sl@0
|
1839 |
TEST_NAMED_SUB_PATTERN("a(?P<A>.)(?P<B>.)?", "a" EGRAVE "x", 0, "B", "x", 3, 4);
|
sl@0
|
1840 |
TEST_NAMED_SUB_PATTERN("(?P<A>a)?(?P<B>b)", "b", 0, "A", "", -1, -1);
|
sl@0
|
1841 |
TEST_NAMED_SUB_PATTERN("(?P<A>a)?(?P<B>b)", "b", 0, "B", "b", 0, 1);
|
sl@0
|
1842 |
|
sl@0
|
1843 |
/* TEST_NAMED_SUB_PATTERN_DUPNAMES(pattern, string, start_position, sub_name,
|
sl@0
|
1844 |
* expected_sub, expected_start, expected_end) */
|
sl@0
|
1845 |
TEST_NAMED_SUB_PATTERN_DUPNAMES("(?P<N>a)|(?P<N>b)", "ab", 0, "N", "a", 0, 1);
|
sl@0
|
1846 |
TEST_NAMED_SUB_PATTERN_DUPNAMES("(?P<N>aa)|(?P<N>a)", "aa", 0, "N", "aa", 0, 2);
|
sl@0
|
1847 |
TEST_NAMED_SUB_PATTERN_DUPNAMES("(?P<N>aa)(?P<N>a)", "aaa", 0, "N", "aa", 0, 2);
|
sl@0
|
1848 |
TEST_NAMED_SUB_PATTERN_DUPNAMES("(?P<N>x)|(?P<N>a)", "a", 0, "N", "a", 0, 1);
|
sl@0
|
1849 |
TEST_NAMED_SUB_PATTERN_DUPNAMES("(?P<N>x)y|(?P<N>a)b", "ab", 0, "N", "a", 0, 1);
|
sl@0
|
1850 |
|
sl@0
|
1851 |
/* DUPNAMES option inside the pattern */
|
sl@0
|
1852 |
TEST_NAMED_SUB_PATTERN("(?J)(?P<N>a)|(?P<N>b)", "ab", 0, "N", "a", 0, 1);
|
sl@0
|
1853 |
TEST_NAMED_SUB_PATTERN("(?J)(?P<N>aa)|(?P<N>a)", "aa", 0, "N", "aa", 0, 2);
|
sl@0
|
1854 |
TEST_NAMED_SUB_PATTERN("(?J)(?P<N>aa)(?P<N>a)", "aaa", 0, "N", "aa", 0, 2);
|
sl@0
|
1855 |
TEST_NAMED_SUB_PATTERN("(?J)(?P<N>x)|(?P<N>a)", "a", 0, "N", "a", 0, 1);
|
sl@0
|
1856 |
TEST_NAMED_SUB_PATTERN("(?J)(?P<N>x)y|(?P<N>a)b", "ab", 0, "N", "a", 0, 1);
|
sl@0
|
1857 |
|
sl@0
|
1858 |
/* TEST_FETCH_ALL#(pattern, string, ...) */
|
sl@0
|
1859 |
TEST_FETCH_ALL0("a", "");
|
sl@0
|
1860 |
TEST_FETCH_ALL0("a", "b");
|
sl@0
|
1861 |
TEST_FETCH_ALL1("a", "a", "a");
|
sl@0
|
1862 |
TEST_FETCH_ALL1("a+", "aa", "aa");
|
sl@0
|
1863 |
TEST_FETCH_ALL1("(?:a)", "a", "a");
|
sl@0
|
1864 |
TEST_FETCH_ALL2("(a)", "a", "a", "a");
|
sl@0
|
1865 |
TEST_FETCH_ALL2("a(.)", "ab", "ab", "b");
|
sl@0
|
1866 |
TEST_FETCH_ALL2("a(.)", "a" HSTROKE, "a" HSTROKE, HSTROKE);
|
sl@0
|
1867 |
TEST_FETCH_ALL3("(?:.*)(a)(.)", "xyazk", "xyaz", "a", "z");
|
sl@0
|
1868 |
TEST_FETCH_ALL3("(?P<A>.)(a)", "xa", "xa", "x", "a");
|
sl@0
|
1869 |
TEST_FETCH_ALL3("(?P<A>.)(a)", ENG "a", ENG "a", ENG, "a");
|
sl@0
|
1870 |
TEST_FETCH_ALL3("(a)?(b)", "b", "b", "", "b");
|
sl@0
|
1871 |
TEST_FETCH_ALL3("(a)?(b)", "ab", "ab", "a", "b");
|
sl@0
|
1872 |
|
sl@0
|
1873 |
/* TEST_SPLIT_SIMPLE#(pattern, string, ...) */
|
sl@0
|
1874 |
TEST_SPLIT_SIMPLE0("", "");
|
sl@0
|
1875 |
TEST_SPLIT_SIMPLE0("a", "");
|
sl@0
|
1876 |
TEST_SPLIT_SIMPLE1(",", "a", "a");
|
sl@0
|
1877 |
TEST_SPLIT_SIMPLE1("(,)\\s*", "a", "a");
|
sl@0
|
1878 |
TEST_SPLIT_SIMPLE2(",", "a,b", "a", "b");
|
sl@0
|
1879 |
TEST_SPLIT_SIMPLE3(",", "a,b,c", "a", "b", "c");
|
sl@0
|
1880 |
TEST_SPLIT_SIMPLE3(",\\s*", "a,b,c", "a", "b", "c");
|
sl@0
|
1881 |
TEST_SPLIT_SIMPLE3(",\\s*", "a, b, c", "a", "b", "c");
|
sl@0
|
1882 |
TEST_SPLIT_SIMPLE3("(,)\\s*", "a,b", "a", ",", "b");
|
sl@0
|
1883 |
TEST_SPLIT_SIMPLE3("(,)\\s*", "a, b", "a", ",", "b");
|
sl@0
|
1884 |
/* Not matched sub-strings. */
|
sl@0
|
1885 |
TEST_SPLIT_SIMPLE2("a|(b)", "xay", "x", "y");
|
sl@0
|
1886 |
TEST_SPLIT_SIMPLE3("a|(b)", "xby", "x", "b", "y");
|
sl@0
|
1887 |
/* Empty matches. */
|
sl@0
|
1888 |
TEST_SPLIT_SIMPLE3("", "abc", "a", "b", "c");
|
sl@0
|
1889 |
TEST_SPLIT_SIMPLE3(" *", "ab c", "a", "b", "c");
|
sl@0
|
1890 |
/* Invalid patterns. */
|
sl@0
|
1891 |
TEST_SPLIT_SIMPLE0("\\", "");
|
sl@0
|
1892 |
TEST_SPLIT_SIMPLE0("[", "");
|
sl@0
|
1893 |
|
sl@0
|
1894 |
/* TEST_SPLIT#(pattern, string, start_position, max_tokens, ...) */
|
sl@0
|
1895 |
TEST_SPLIT0("", "", 0, 0);
|
sl@0
|
1896 |
TEST_SPLIT0("a", "", 0, 0);
|
sl@0
|
1897 |
TEST_SPLIT0("a", "", 0, 1);
|
sl@0
|
1898 |
TEST_SPLIT0("a", "", 0, 2);
|
sl@0
|
1899 |
TEST_SPLIT0("a", "a", 1, 0);
|
sl@0
|
1900 |
TEST_SPLIT1(",", "a", 0, 0, "a");
|
sl@0
|
1901 |
TEST_SPLIT1(",", "a,b", 0, 1, "a,b");
|
sl@0
|
1902 |
TEST_SPLIT1("(,)\\s*", "a", 0, 0, "a");
|
sl@0
|
1903 |
TEST_SPLIT1(",", "a,b", 2, 0, "b");
|
sl@0
|
1904 |
TEST_SPLIT2(",", "a,b", 0, 0, "a", "b");
|
sl@0
|
1905 |
TEST_SPLIT2(",", "a,b,c", 0, 2, "a", "b,c");
|
sl@0
|
1906 |
TEST_SPLIT2(",", "a,b", 1, 0, "", "b");
|
sl@0
|
1907 |
TEST_SPLIT2(",", "a,", 0, 0, "a", "");
|
sl@0
|
1908 |
TEST_SPLIT3(",", "a,b,c", 0, 0, "a", "b", "c");
|
sl@0
|
1909 |
TEST_SPLIT3(",\\s*", "a,b,c", 0, 0, "a", "b", "c");
|
sl@0
|
1910 |
TEST_SPLIT3(",\\s*", "a, b, c", 0, 0, "a", "b", "c");
|
sl@0
|
1911 |
TEST_SPLIT3("(,)\\s*", "a,b", 0, 0, "a", ",", "b");
|
sl@0
|
1912 |
TEST_SPLIT3("(,)\\s*", "a, b", 0, 0, "a", ",", "b");
|
sl@0
|
1913 |
/* Not matched sub-strings. */
|
sl@0
|
1914 |
TEST_SPLIT2("a|(b)", "xay", 0, 0, "x", "y");
|
sl@0
|
1915 |
TEST_SPLIT3("a|(b)", "xby", 0, -1, "x", "b", "y");
|
sl@0
|
1916 |
/* Empty matches. */
|
sl@0
|
1917 |
TEST_SPLIT2(" *", "ab c", 1, 0, "b", "c");
|
sl@0
|
1918 |
TEST_SPLIT3("", "abc", 0, 0, "a", "b", "c");
|
sl@0
|
1919 |
TEST_SPLIT3(" *", "ab c", 0, 0, "a", "b", "c");
|
sl@0
|
1920 |
TEST_SPLIT1(" *", "ab c", 0, 1, "ab c");
|
sl@0
|
1921 |
TEST_SPLIT2(" *", "ab c", 0, 2, "a", "b c");
|
sl@0
|
1922 |
TEST_SPLIT3(" *", "ab c", 0, 3, "a", "b", "c");
|
sl@0
|
1923 |
TEST_SPLIT3(" *", "ab c", 0, 4, "a", "b", "c");
|
sl@0
|
1924 |
|
sl@0
|
1925 |
/* TEST_CHECK_REPLACEMENT(string_to_expand, expected, expected_refs) */
|
sl@0
|
1926 |
TEST_CHECK_REPLACEMENT("", TRUE, FALSE);
|
sl@0
|
1927 |
TEST_CHECK_REPLACEMENT("a", TRUE, FALSE);
|
sl@0
|
1928 |
TEST_CHECK_REPLACEMENT("\\t\\n\\v\\r\\f\\a\\b\\\\\\x{61}", TRUE, FALSE);
|
sl@0
|
1929 |
TEST_CHECK_REPLACEMENT("\\0", TRUE, TRUE);
|
sl@0
|
1930 |
TEST_CHECK_REPLACEMENT("\\n\\2", TRUE, TRUE);
|
sl@0
|
1931 |
TEST_CHECK_REPLACEMENT("\\g<foo>", TRUE, TRUE);
|
sl@0
|
1932 |
/* Invalid strings */
|
sl@0
|
1933 |
TEST_CHECK_REPLACEMENT("\\Q", FALSE, FALSE);
|
sl@0
|
1934 |
TEST_CHECK_REPLACEMENT("x\\Ay", FALSE, FALSE);
|
sl@0
|
1935 |
|
sl@0
|
1936 |
/* TEST_EXPAND(pattern, string, string_to_expand, raw, expected) */
|
sl@0
|
1937 |
TEST_EXPAND("a", "a", "", FALSE, "");
|
sl@0
|
1938 |
TEST_EXPAND("a", "a", "\\0", FALSE, "a");
|
sl@0
|
1939 |
TEST_EXPAND("a", "a", "\\1", FALSE, "");
|
sl@0
|
1940 |
TEST_EXPAND("(a)", "ab", "\\1", FALSE, "a");
|
sl@0
|
1941 |
TEST_EXPAND("(a)", "a", "\\1", FALSE, "a");
|
sl@0
|
1942 |
TEST_EXPAND("(a)", "a", "\\g<1>", FALSE, "a");
|
sl@0
|
1943 |
TEST_EXPAND("a", "a", "\\0130", FALSE, "X");
|
sl@0
|
1944 |
TEST_EXPAND("a", "a", "\\\\\\0", FALSE, "\\a");
|
sl@0
|
1945 |
TEST_EXPAND("a(?P<G>.)c", "xabcy", "X\\g<G>X", FALSE, "XbX");
|
sl@0
|
1946 |
TEST_EXPAND("(.)(?P<1>.)", "ab", "\\1", FALSE, "a");
|
sl@0
|
1947 |
TEST_EXPAND("(.)(?P<1>.)", "ab", "\\g<1>", FALSE, "a");
|
sl@0
|
1948 |
TEST_EXPAND(".", EURO, "\\0", FALSE, EURO);
|
sl@0
|
1949 |
TEST_EXPAND("(.)", EURO, "\\1", FALSE, EURO);
|
sl@0
|
1950 |
TEST_EXPAND("(?P<G>.)", EURO, "\\g<G>", FALSE, EURO);
|
sl@0
|
1951 |
TEST_EXPAND(".", "a", EURO, FALSE, EURO);
|
sl@0
|
1952 |
TEST_EXPAND(".", "a", EURO "\\0", FALSE, EURO "a");
|
sl@0
|
1953 |
TEST_EXPAND(".", "", "\\Lab\\Ec", FALSE, "abc");
|
sl@0
|
1954 |
TEST_EXPAND(".", "", "\\LaB\\EC", FALSE, "abC");
|
sl@0
|
1955 |
TEST_EXPAND(".", "", "\\Uab\\Ec", FALSE, "ABc");
|
sl@0
|
1956 |
TEST_EXPAND(".", "", "a\\ubc", FALSE, "aBc");
|
sl@0
|
1957 |
TEST_EXPAND(".", "", "a\\lbc", FALSE, "abc");
|
sl@0
|
1958 |
TEST_EXPAND(".", "", "A\\uBC", FALSE, "ABC");
|
sl@0
|
1959 |
TEST_EXPAND(".", "", "A\\lBC", FALSE, "AbC");
|
sl@0
|
1960 |
TEST_EXPAND(".", "", "A\\l\\\\BC", FALSE, "A\\BC");
|
sl@0
|
1961 |
TEST_EXPAND(".", "", "\\L" AGRAVE "\\E", FALSE, AGRAVE);
|
sl@0
|
1962 |
TEST_EXPAND(".", "", "\\U" AGRAVE "\\E", FALSE, AGRAVE_UPPER);
|
sl@0
|
1963 |
TEST_EXPAND(".", "", "\\u" AGRAVE "a", FALSE, AGRAVE_UPPER "a");
|
sl@0
|
1964 |
TEST_EXPAND(".", "ab", "x\\U\\0y\\Ez", FALSE, "xAYz");
|
sl@0
|
1965 |
TEST_EXPAND(".(.)", "AB", "x\\L\\1y\\Ez", FALSE, "xbyz");
|
sl@0
|
1966 |
TEST_EXPAND(".", "ab", "x\\u\\0y\\Ez", FALSE, "xAyz");
|
sl@0
|
1967 |
TEST_EXPAND(".(.)", "AB", "x\\l\\1y\\Ez", FALSE, "xbyz");
|
sl@0
|
1968 |
TEST_EXPAND(".(.)", "a" AGRAVE_UPPER, "x\\l\\1y", FALSE, "x" AGRAVE "y");
|
sl@0
|
1969 |
TEST_EXPAND("a", "bab", "\\x{61}", FALSE, "a");
|
sl@0
|
1970 |
TEST_EXPAND("a", "bab", "\\x61", FALSE, "a");
|
sl@0
|
1971 |
TEST_EXPAND("a", "bab", "\\x5a", FALSE, "Z");
|
sl@0
|
1972 |
TEST_EXPAND("a", "bab", "\\0\\x5A", FALSE, "aZ");
|
sl@0
|
1973 |
TEST_EXPAND("a", "bab", "\\1\\x{5A}", FALSE, "Z");
|
sl@0
|
1974 |
TEST_EXPAND("a", "bab", "\\x{00E0}", FALSE, AGRAVE);
|
sl@0
|
1975 |
TEST_EXPAND("", "bab", "\\x{0634}", FALSE, SHEEN);
|
sl@0
|
1976 |
TEST_EXPAND("", "bab", "\\x{634}", FALSE, SHEEN);
|
sl@0
|
1977 |
TEST_EXPAND("", "", "\\t", FALSE, "\t");
|
sl@0
|
1978 |
TEST_EXPAND("", "", "\\v", FALSE, "\v");
|
sl@0
|
1979 |
TEST_EXPAND("", "", "\\r", FALSE, "\r");
|
sl@0
|
1980 |
TEST_EXPAND("", "", "\\n", FALSE, "\n");
|
sl@0
|
1981 |
TEST_EXPAND("", "", "\\f", FALSE, "\f");
|
sl@0
|
1982 |
TEST_EXPAND("", "", "\\a", FALSE, "\a");
|
sl@0
|
1983 |
TEST_EXPAND("", "", "\\b", FALSE, "\b");
|
sl@0
|
1984 |
TEST_EXPAND("a(.)", "abc", "\\0\\b\\1", FALSE, "ab\bb");
|
sl@0
|
1985 |
TEST_EXPAND("a(.)", "abc", "\\0141", FALSE, "a");
|
sl@0
|
1986 |
TEST_EXPAND("a(.)", "abc", "\\078", FALSE, "\a8");
|
sl@0
|
1987 |
TEST_EXPAND("a(.)", "abc", "\\077", FALSE, "?");
|
sl@0
|
1988 |
TEST_EXPAND("a(.)", "abc", "\\0778", FALSE, "?8");
|
sl@0
|
1989 |
TEST_EXPAND("a(.)", "a" AGRAVE "b", "\\1", FALSE, AGRAVE);
|
sl@0
|
1990 |
TEST_EXPAND("a(.)", "a" AGRAVE "b", "\\1", TRUE, "\xc3");
|
sl@0
|
1991 |
TEST_EXPAND("a(.)", "a" AGRAVE "b", "\\0", TRUE, "a\xc3");
|
sl@0
|
1992 |
/* Invalid strings. */
|
sl@0
|
1993 |
TEST_EXPAND("", "", "\\Q", FALSE, NULL);
|
sl@0
|
1994 |
TEST_EXPAND("", "", "x\\Ay", FALSE, NULL);
|
sl@0
|
1995 |
TEST_EXPAND("", "", "\\g<", FALSE, NULL);
|
sl@0
|
1996 |
TEST_EXPAND("", "", "\\g<>", FALSE, NULL);
|
sl@0
|
1997 |
TEST_EXPAND("", "", "\\g<1a>", FALSE, NULL);
|
sl@0
|
1998 |
TEST_EXPAND("", "", "\\g<a$>", FALSE, NULL);
|
sl@0
|
1999 |
TEST_EXPAND("", "", "\\", FALSE, NULL);
|
sl@0
|
2000 |
TEST_EXPAND("a", "a", "\\x{61", FALSE, NULL);
|
sl@0
|
2001 |
TEST_EXPAND("a", "a", "\\x6X", FALSE, NULL);
|
sl@0
|
2002 |
/* Pattern-less. */
|
sl@0
|
2003 |
TEST_EXPAND(NULL, NULL, "", FALSE, "");
|
sl@0
|
2004 |
TEST_EXPAND(NULL, NULL, "\\n", FALSE, "\n");
|
sl@0
|
2005 |
/* Invalid strings */
|
sl@0
|
2006 |
TEST_EXPAND(NULL, NULL, "\\Q", FALSE, NULL);
|
sl@0
|
2007 |
TEST_EXPAND(NULL, NULL, "x\\Ay", FALSE, NULL);
|
sl@0
|
2008 |
|
sl@0
|
2009 |
/* TEST_REPLACE(pattern, string, start_position, replacement, expected) */
|
sl@0
|
2010 |
TEST_REPLACE("a", "ababa", 0, "A", "AbAbA");
|
sl@0
|
2011 |
TEST_REPLACE("a", "ababa", 1, "A", "abAbA");
|
sl@0
|
2012 |
TEST_REPLACE("a", "ababa", 2, "A", "abAbA");
|
sl@0
|
2013 |
TEST_REPLACE("a", "ababa", 3, "A", "ababA");
|
sl@0
|
2014 |
TEST_REPLACE("a", "ababa", 4, "A", "ababA");
|
sl@0
|
2015 |
TEST_REPLACE("a", "ababa", 5, "A", "ababa");
|
sl@0
|
2016 |
TEST_REPLACE("a", "ababa", 6, "A", "ababa");
|
sl@0
|
2017 |
TEST_REPLACE("a", "abababa", 2, "A", "abAbAbA");
|
sl@0
|
2018 |
TEST_REPLACE("a", "abab", 0, "A", "AbAb");
|
sl@0
|
2019 |
TEST_REPLACE("a", "baba", 0, "A", "bAbA");
|
sl@0
|
2020 |
TEST_REPLACE("a", "bab", 0, "A", "bAb");
|
sl@0
|
2021 |
TEST_REPLACE("$^", "abc", 0, "X", "abc");
|
sl@0
|
2022 |
TEST_REPLACE("(.)a", "ciao", 0, "a\\1", "caio");
|
sl@0
|
2023 |
TEST_REPLACE("a.", "abc", 0, "\\0\\0", "ababc");
|
sl@0
|
2024 |
TEST_REPLACE("a", "asd", 0, "\\0101", "Asd");
|
sl@0
|
2025 |
TEST_REPLACE("(a).\\1", "aba cda", 0, "\\1\\n", "a\n cda");
|
sl@0
|
2026 |
TEST_REPLACE("a" AGRAVE "a", "a" AGRAVE "a", 0, "x", "x");
|
sl@0
|
2027 |
TEST_REPLACE("a" AGRAVE "a", "a" AGRAVE "a", 0, OGRAVE, OGRAVE);
|
sl@0
|
2028 |
TEST_REPLACE("[^-]", "-" EURO "-x-" HSTROKE, 0, "a", "-a-a-a");
|
sl@0
|
2029 |
TEST_REPLACE("[^-]", "-" EURO "-" HSTROKE, 0, "a\\g<0>a", "-a" EURO "a-a" HSTROKE "a");
|
sl@0
|
2030 |
TEST_REPLACE("-", "-" EURO "-" HSTROKE, 0, "", EURO HSTROKE);
|
sl@0
|
2031 |
TEST_REPLACE(".*", "hello", 0, "\\U\\0\\E", "HELLO");
|
sl@0
|
2032 |
TEST_REPLACE(".*", "hello", 0, "\\u\\0", "Hello");
|
sl@0
|
2033 |
TEST_REPLACE("\\S+", "hello world", 0, "\\U-\\0-", "-HELLO- -WORLD-");
|
sl@0
|
2034 |
TEST_REPLACE(".", "a", 0, "\\A", NULL);
|
sl@0
|
2035 |
TEST_REPLACE(".", "a", 0, "\\g", NULL);
|
sl@0
|
2036 |
|
sl@0
|
2037 |
/* TEST_REPLACE_LIT(pattern, string, start_position, replacement, expected) */
|
sl@0
|
2038 |
TEST_REPLACE_LIT("a", "ababa", 0, "A", "AbAbA");
|
sl@0
|
2039 |
TEST_REPLACE_LIT("a", "ababa", 1, "A", "abAbA");
|
sl@0
|
2040 |
TEST_REPLACE_LIT("a", "ababa", 2, "A", "abAbA");
|
sl@0
|
2041 |
TEST_REPLACE_LIT("a", "ababa", 3, "A", "ababA");
|
sl@0
|
2042 |
TEST_REPLACE_LIT("a", "ababa", 4, "A", "ababA");
|
sl@0
|
2043 |
TEST_REPLACE_LIT("a", "ababa", 5, "A", "ababa");
|
sl@0
|
2044 |
TEST_REPLACE_LIT("a", "ababa", 6, "A", "ababa");
|
sl@0
|
2045 |
TEST_REPLACE_LIT("a", "abababa", 2, "A", "abAbAbA");
|
sl@0
|
2046 |
TEST_REPLACE_LIT("a", "abcadaa", 0, "A", "AbcAdAA");
|
sl@0
|
2047 |
TEST_REPLACE_LIT("$^", "abc", 0, "X", "abc");
|
sl@0
|
2048 |
TEST_REPLACE_LIT("(.)a", "ciao", 0, "a\\1", "ca\\1o");
|
sl@0
|
2049 |
TEST_REPLACE_LIT("a.", "abc", 0, "\\0\\0\\n", "\\0\\0\\nc");
|
sl@0
|
2050 |
TEST_REPLACE_LIT("a" AGRAVE "a", "a" AGRAVE "a", 0, "x", "x");
|
sl@0
|
2051 |
TEST_REPLACE_LIT("a" AGRAVE "a", "a" AGRAVE "a", 0, OGRAVE, OGRAVE);
|
sl@0
|
2052 |
TEST_REPLACE_LIT(AGRAVE, "-" AGRAVE "-" HSTROKE, 0, "a" ENG "a", "-a" ENG "a-" HSTROKE);
|
sl@0
|
2053 |
TEST_REPLACE_LIT("[^-]", "-" EURO "-" AGRAVE "-" HSTROKE, 0, "a", "-a-a-a");
|
sl@0
|
2054 |
TEST_REPLACE_LIT("[^-]", "-" EURO "-" AGRAVE, 0, "a\\g<0>a", "-a\\g<0>a-a\\g<0>a");
|
sl@0
|
2055 |
TEST_REPLACE_LIT("-", "-" EURO "-" AGRAVE "-" HSTROKE, 0, "", EURO AGRAVE HSTROKE);
|
sl@0
|
2056 |
TEST_REPLACE_LIT("(?=[A-Z0-9])", "RegExTest", 0, "_", "_Reg_Ex_Test");
|
sl@0
|
2057 |
TEST_REPLACE_LIT("(?=[A-Z0-9])", "RegExTest", 1, "_", "Reg_Ex_Test");
|
sl@0
|
2058 |
|
sl@0
|
2059 |
/* TEST_GET_STRING_NUMBER(pattern, name, expected_num) */
|
sl@0
|
2060 |
TEST_GET_STRING_NUMBER("", "A", -1);
|
sl@0
|
2061 |
TEST_GET_STRING_NUMBER("(?P<A>.)", "A", 1);
|
sl@0
|
2062 |
TEST_GET_STRING_NUMBER("(?P<A>.)", "B", -1);
|
sl@0
|
2063 |
TEST_GET_STRING_NUMBER("(?P<A>.)(?P<B>a)", "A", 1);
|
sl@0
|
2064 |
TEST_GET_STRING_NUMBER("(?P<A>.)(?P<B>a)", "B", 2);
|
sl@0
|
2065 |
TEST_GET_STRING_NUMBER("(?P<A>.)(?P<B>a)", "C", -1);
|
sl@0
|
2066 |
TEST_GET_STRING_NUMBER("(?P<A>.)(.)(?P<B>a)", "A", 1);
|
sl@0
|
2067 |
TEST_GET_STRING_NUMBER("(?P<A>.)(.)(?P<B>a)", "B", 3);
|
sl@0
|
2068 |
TEST_GET_STRING_NUMBER("(?P<A>.)(.)(?P<B>a)", "C", -1);
|
sl@0
|
2069 |
TEST_GET_STRING_NUMBER("(?:a)(?P<A>.)", "A", 1);
|
sl@0
|
2070 |
TEST_GET_STRING_NUMBER("(?:a)(?P<A>.)", "B", -1);
|
sl@0
|
2071 |
|
sl@0
|
2072 |
/* TEST_ESCAPE(string, length, expected) */
|
sl@0
|
2073 |
TEST_ESCAPE("hello world", -1, "hello world");
|
sl@0
|
2074 |
TEST_ESCAPE("hello world", 5, "hello");
|
sl@0
|
2075 |
TEST_ESCAPE("hello.world", -1, "hello\\.world");
|
sl@0
|
2076 |
TEST_ESCAPE("a(b\\b.$", -1, "a\\(b\\\\b\\.\\$");
|
sl@0
|
2077 |
TEST_ESCAPE("hello\0world", -1, "hello");
|
sl@0
|
2078 |
TEST_ESCAPE("hello\0world", 11, "hello\\0world");
|
sl@0
|
2079 |
TEST_ESCAPE(EURO "*" ENG, -1, EURO "\\*" ENG);
|
sl@0
|
2080 |
TEST_ESCAPE("a$", -1, "a\\$");
|
sl@0
|
2081 |
TEST_ESCAPE("$a", -1, "\\$a");
|
sl@0
|
2082 |
TEST_ESCAPE("a$a", -1, "a\\$a");
|
sl@0
|
2083 |
TEST_ESCAPE("$a$", -1, "\\$a\\$");
|
sl@0
|
2084 |
TEST_ESCAPE("$a$", 0, "");
|
sl@0
|
2085 |
TEST_ESCAPE("$a$", 1, "\\$");
|
sl@0
|
2086 |
TEST_ESCAPE("$a$", 2, "\\$a");
|
sl@0
|
2087 |
TEST_ESCAPE("$a$", 3, "\\$a\\$");
|
sl@0
|
2088 |
TEST_ESCAPE("$a$", 4, "\\$a\\$\\0");
|
sl@0
|
2089 |
TEST_ESCAPE("|()[]{}^$*+?.", -1, "\\|\\(\\)\\[\\]\\{\\}\\^\\$\\*\\+\\?\\.");
|
sl@0
|
2090 |
TEST_ESCAPE("a|a(a)a[a]a{a}a^a$a*a+a?a.a", -1,
|
sl@0
|
2091 |
"a\\|a\\(a\\)a\\[a\\]a\\{a\\}a\\^a\\$a\\*a\\+a\\?a\\.a");
|
sl@0
|
2092 |
|
sl@0
|
2093 |
/* TEST_MATCH_ALL#(pattern, string, string_len, start_position, ...) */
|
sl@0
|
2094 |
TEST_MATCH_ALL0("<.*>", "", -1, 0);
|
sl@0
|
2095 |
TEST_MATCH_ALL0("a+", "", -1, 0);
|
sl@0
|
2096 |
TEST_MATCH_ALL0("a+", "a", 0, 0);
|
sl@0
|
2097 |
TEST_MATCH_ALL0("a+", "a", -1, 1);
|
sl@0
|
2098 |
// TEST_MATCH_ALL1("<.*>", "<a>", -1, 0, "<a>", 0, 3);
|
sl@0
|
2099 |
TEST_MATCH_ALL1("a+", "a", -1, 0, "a", 0, 1);
|
sl@0
|
2100 |
TEST_MATCH_ALL1("a+", "aa", 1, 0, "a", 0, 1);
|
sl@0
|
2101 |
TEST_MATCH_ALL1("a+", "aa", -1, 1, "a", 1, 2);
|
sl@0
|
2102 |
TEST_MATCH_ALL1("a+", "aa", 2, 1, "a", 1, 2);
|
sl@0
|
2103 |
TEST_MATCH_ALL1(".+", ENG, -1, 0, ENG, 0, 2);
|
sl@0
|
2104 |
// TEST_MATCH_ALL2("<.*>", "<a><b>", -1, 0, "<a><b>", 0, 6, "<a>", 0, 3);
|
sl@0
|
2105 |
TEST_MATCH_ALL2("a+", "aa", -1, 0, "aa", 0, 2, "a", 0, 1);
|
sl@0
|
2106 |
TEST_MATCH_ALL2(".+", ENG EURO, -1, 0, ENG EURO, 0, 5, ENG, 0, 2);
|
sl@0
|
2107 |
// TEST_MATCH_ALL3("<.*>", "<a><b><c>", -1, 0, "<a><b><c>", 0, 9,
|
sl@0
|
2108 |
// "<a><b>", 0, 6, "<a>", 0, 3);
|
sl@0
|
2109 |
// TEST_MATCH_ALL3("a+", "aaa", -1, 0, "aaa", 0, 3, "aa", 0, 2, "a", 0, 1);
|
sl@0
|
2110 |
|
sl@0
|
2111 |
end: /* if abort_on_fail is TRUE the flow passes to this label. */
|
sl@0
|
2112 |
verbose ("\n%u tests passed, %u failed\n", passed, failed);
|
sl@0
|
2113 |
#if __SYMBIAN32__
|
sl@0
|
2114 |
testResultXml("regex-test");
|
sl@0
|
2115 |
#endif /* EMULATOR */
|
sl@0
|
2116 |
return failed;
|
sl@0
|
2117 |
}
|
sl@0
|
2118 |
|
sl@0
|
2119 |
#else /* ENABLE_REGEX false */
|
sl@0
|
2120 |
|
sl@0
|
2121 |
int
|
sl@0
|
2122 |
main (int argc, char *argv[])
|
sl@0
|
2123 |
{
|
sl@0
|
2124 |
g_print ("GRegex is disabled.\n");
|
sl@0
|
2125 |
return 0;
|
sl@0
|
2126 |
}
|
sl@0
|
2127 |
|
sl@0
|
2128 |
#endif /* ENABLE_REGEX */
|