Blame posix/bug-regex18.c

Packit Service 82fcde
/* Turkish regular expression tests.
Packit Service 82fcde
   Copyright (C) 2002-2018 Free Software Foundation, Inc.
Packit Service 82fcde
   This file is part of the GNU C Library.
Packit Service 82fcde
   Contributed by Jakub Jelinek <jakub@redhat.com>, 2002.
Packit Service 82fcde
Packit Service 82fcde
   The GNU C Library is free software; you can redistribute it and/or
Packit Service 82fcde
   modify it under the terms of the GNU Lesser General Public
Packit Service 82fcde
   License as published by the Free Software Foundation; either
Packit Service 82fcde
   version 2.1 of the License, or (at your option) any later version.
Packit Service 82fcde
Packit Service 82fcde
   The GNU C Library is distributed in the hope that it will be useful,
Packit Service 82fcde
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 82fcde
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 82fcde
   Lesser General Public License for more details.
Packit Service 82fcde
Packit Service 82fcde
   You should have received a copy of the GNU Lesser General Public
Packit Service 82fcde
   License along with the GNU C Library; if not, see
Packit Service 82fcde
   <http://www.gnu.org/licenses/>.  */
Packit Service 82fcde
Packit Service 82fcde
#include <sys/types.h>
Packit Service 82fcde
#include <mcheck.h>
Packit Service 82fcde
#include <regex.h>
Packit Service 82fcde
#include <stdio.h>
Packit Service 82fcde
#include <stdlib.h>
Packit Service 82fcde
#include <locale.h>
Packit Service 82fcde
Packit Service 82fcde
/* Tests supposed to match.  */
Packit Service 82fcde
struct
Packit Service 82fcde
{
Packit Service 82fcde
  const char *pattern;
Packit Service 82fcde
  const char *string;
Packit Service 82fcde
  int flags, nmatch;
Packit Service 82fcde
  regmatch_t rm[5];
Packit Service 82fcde
} tests[] = {
Packit Service 82fcde
  /* \xc4\xb0		LATIN CAPITAL LETTER I WITH DOT ABOVE
Packit Service 82fcde
     \xc4\xb1		LATIN SMALL LETTER DOTLESS I
Packit Service 82fcde
     \xe2\x80\x94	EM DASH  */
Packit Service 82fcde
  { "\xc4\xb0I*\xc4\xb1$", "aBi\xc4\xb1\xc4\xb1I", REG_ICASE, 2,
Packit Service 82fcde
    { { 2, 8 }, { -1, -1 } } },
Packit Service 82fcde
  { "[\xc4\xb0x]I*\xc4\xb1$", "aBi\xc4\xb1\xc4\xb1I", REG_ICASE, 2,
Packit Service 82fcde
    { { 2, 8 }, { -1, -1 } } },
Packit Service 82fcde
  { "[^x]I*\xc4\xb1$", "aBi\xc4\xb1\xc4\xb1I", REG_ICASE, 2,
Packit Service 82fcde
    { { 2, 8 }, { -1, -1 } } },
Packit Service 82fcde
  { "([[:alpha:]]i[[:xdigit:]])(\xc4\xb1*)(\xc4\xb0{2})",
Packit Service 82fcde
    "\xe2\x80\x94\xc4\xb1\xc4\xb0""fIi\xc4\xb0ii", REG_ICASE | REG_EXTENDED,
Packit Service 82fcde
    4, { { 3, 12 }, { 3, 8 }, { 8, 9 }, { 9, 12 } } },
Packit Service 82fcde
  { "\xc4\xb1i(i)*()(\\s\xc4\xb0|\\SI)", "SIi\xc4\xb0\xc4\xb0 is",
Packit Service 82fcde
    REG_ICASE | REG_EXTENDED, 4, { { 1, 9 }, { 5, 7 }, { 7, 7 }, { 7, 9 } } },
Packit Service 82fcde
  { "\xc4\xb1i(i)*()(\\s\xc4\xb0|\\SI)", "\xc4\xb1\xc4\xb0\xc4\xb0iJ\xc4\xb1",
Packit Service 82fcde
    REG_ICASE | REG_EXTENDED, 4,
Packit Service 82fcde
    { { 0, 10 }, { 6, 7 }, { 7, 7 }, { 7, 10 } } },
Packit Service 82fcde
};
Packit Service 82fcde
Packit Service 82fcde
int
Packit Service 82fcde
main (void)
Packit Service 82fcde
{
Packit Service 82fcde
  regex_t re;
Packit Service 82fcde
  regmatch_t rm[5];
Packit Service 82fcde
  size_t i;
Packit Service 82fcde
  int n, ret = 0;
Packit Service 82fcde
Packit Service 82fcde
  setlocale (LC_ALL, "tr_TR.UTF-8");
Packit Service 82fcde
  for (i = 0; i < sizeof (tests) / sizeof (tests[0]); ++i)
Packit Service 82fcde
    {
Packit Service 82fcde
      n = regcomp (&re, tests[i].pattern, tests[i].flags);
Packit Service 82fcde
      if (n != 0)
Packit Service 82fcde
	{
Packit Service 82fcde
	  char buf[500];
Packit Service 82fcde
	  regerror (n, &re, buf, sizeof (buf));
Packit Service 82fcde
	  printf ("regcomp %zd failed: %s\n", i, buf);
Packit Service 82fcde
	  ret = 1;
Packit Service 82fcde
	  continue;
Packit Service 82fcde
	}
Packit Service 82fcde
Packit Service 82fcde
      if (regexec (&re, tests[i].string, tests[i].nmatch, rm, 0))
Packit Service 82fcde
	{
Packit Service 82fcde
	  printf ("regexec %zd failed\n", i);
Packit Service 82fcde
	  ret = 1;
Packit Service 82fcde
	  regfree (&re);
Packit Service 82fcde
	  continue;
Packit Service 82fcde
	}
Packit Service 82fcde
Packit Service 82fcde
      for (n = 0; n < tests[i].nmatch; ++n)
Packit Service 82fcde
	if (rm[n].rm_so != tests[i].rm[n].rm_so
Packit Service 82fcde
              || rm[n].rm_eo != tests[i].rm[n].rm_eo)
Packit Service 82fcde
	  {
Packit Service 82fcde
	    if (tests[i].rm[n].rm_so == -1 && tests[i].rm[n].rm_eo == -1)
Packit Service 82fcde
	      break;
Packit Service 82fcde
	    printf ("regexec match failure rm[%d] %d..%d\n",
Packit Service 82fcde
		    n, rm[n].rm_so, rm[n].rm_eo);
Packit Service 82fcde
	    ret = 1;
Packit Service 82fcde
	    break;
Packit Service 82fcde
	  }
Packit Service 82fcde
Packit Service 82fcde
      regfree (&re);
Packit Service 82fcde
    }
Packit Service 82fcde
Packit Service 82fcde
  return ret;
Packit Service 82fcde
}