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