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