summaryrefslogtreecommitdiffstats
path: root/gnu/lib/libregex/test/test.c
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/lib/libregex/test/test.c')
-rw-r--r--gnu/lib/libregex/test/test.c232
1 files changed, 116 insertions, 116 deletions
diff --git a/gnu/lib/libregex/test/test.c b/gnu/lib/libregex/test/test.c
index a8de23e..74b43b2 100644
--- a/gnu/lib/libregex/test/test.c
+++ b/gnu/lib/libregex/test/test.c
@@ -55,32 +55,32 @@ boolean test_should_match;
static void
-set_all_registers (start0, end0, start1, end1,
+set_all_registers (start0, end0, start1, end1,
start2, end2, start3, end3,
- start4, end4, start5, end5,
+ start4, end4, start5, end5,
start6, end6, start7, end7,
start8, end8, start9, end9, regs)
- int start0; int end0; int start1; int end1;
+ int start0; int end0; int start1; int end1;
int start2; int end2; int start3; int end3;
- int start4; int end4; int start5; int end5;
+ int start4; int end4; int start5; int end5;
int start6; int end6; int start7; int end7;
- int start8; int end8; int start9; int end9;
+ int start8; int end8; int start9; int end9;
struct re_registers *regs;
{
unsigned r;
-
- regs->start[0] = start0; regs->end[0] = end0;
- regs->start[1] = start1; regs->end[1] = end1;
- regs->start[2] = start2; regs->end[2] = end2;
- regs->start[3] = start3; regs->end[3] = end3;
- regs->start[4] = start4; regs->end[4] = end4;
- regs->start[5] = start5; regs->end[5] = end5;
- regs->start[6] = start6; regs->end[6] = end6;
- regs->start[7] = start7; regs->end[7] = end7;
- regs->start[8] = start8; regs->end[8] = end8;
- regs->start[9] = start9; regs->end[9] = end9;
+
+ regs->start[0] = start0; regs->end[0] = end0;
+ regs->start[1] = start1; regs->end[1] = end1;
+ regs->start[2] = start2; regs->end[2] = end2;
+ regs->start[3] = start3; regs->end[3] = end3;
+ regs->start[4] = start4; regs->end[4] = end4;
+ regs->start[5] = start5; regs->end[5] = end5;
+ regs->start[6] = start6; regs->end[6] = end6;
+ regs->start[7] = start7; regs->end[7] = end7;
+ regs->start[8] = start8; regs->end[8] = end8;
+ regs->start[9] = start9; regs->end[9] = end9;
for (r = 10; r < regs->num_regs; r++)
{
regs->start[r] = -1;
@@ -111,16 +111,16 @@ concat (s1, s2)
/* We ignore the `can_be_null' argument. Should just be removed. */
-void
+void
general_test (pattern_should_be_valid, match_whole_string,
pat, str1, str2, start, range, end, correct_fastmap,
correct_regs, can_be_null)
- unsigned pattern_should_be_valid;
+ unsigned pattern_should_be_valid;
unsigned match_whole_string;
const char *pat;
char *str1, *str2;
- int start, range, end;
- char *correct_fastmap;
+ int start, range, end;
+ char *correct_fastmap;
struct re_registers *correct_regs;
int can_be_null;
{
@@ -138,8 +138,8 @@ general_test (pattern_should_be_valid, match_whole_string,
unsigned invalid_pattern = 0;
boolean internal_error_1 = false;
boolean internal_error_2 = false;
-
-
+
+
nonconst_buf.allocated = 8;
nonconst_buf.buffer = xmalloc (nonconst_buf.allocated);
nonconst_buf.fastmap = fastmap;
@@ -147,7 +147,7 @@ general_test (pattern_should_be_valid, match_whole_string,
assert (pat != NULL);
r = re_compile_pattern (pat, strlen (pat), &nonconst_buf);
-
+
/* Kludge: if we are doing POSIX testing, we really should have
called regcomp, not re_compile_pattern. As it happens, the only
way in which it matters is that re_compile_pattern sets the
@@ -156,7 +156,7 @@ general_test (pattern_should_be_valid, match_whole_string,
matching. */
if (t == posix_basic_test || t == posix_extended_test)
nonconst_buf.newline_anchor = 0;
-
+
invalid_pattern = r != NULL;
if (!r)
@@ -168,27 +168,27 @@ general_test (pattern_should_be_valid, match_whole_string,
else
{
fastmap_internal_error = (re_compile_fastmap (&nonconst_buf) == -2);
-
+
if (correct_fastmap)
- nonconst_buf.fastmap_accurate =
+ nonconst_buf.fastmap_accurate =
memcmp (nonconst_buf.fastmap, correct_fastmap, 1 << BYTEWIDTH)
== 0;
-
+
if (OK_TO_SEARCH)
{
old_buf = nonconst_buf;
old_buf.buffer = (unsigned char *) xmalloc (nonconst_buf.used);
memcpy (old_buf.buffer, nonconst_buf.buffer, nonconst_buf.used);
-
+
/* If only one string is null, call re_match or re_search,
- which is what the user would probably do. */
+ which is what the user would probably do. */
if (str1 == NULL && str2 != NULL
|| str2 == NULL && str1 != NULL)
{
char *the_str = str1 == NULL ? str2 : str1;
-
+
match_1
- = match_whole_string
+ = match_whole_string
? (r = re_match (&nonconst_buf, the_str,
strlen (the_str), start, &regs))
== strlen (the_str)
@@ -200,16 +200,16 @@ general_test (pattern_should_be_valid, match_whole_string,
if (r == -2)
internal_error_1 = true;
}
- else
+ else
match_1 = 1;
-
+
/* Also call with re_match_2 or re_search_2, as they might
do this. (Also can check calling with either string1
or string2 or both null.) */
if (match_whole_string)
{
r = re_match_2 (&nonconst_buf,
- str1, SAFE_STRLEN (str1),
+ str1, SAFE_STRLEN (str1),
str2, SAFE_STRLEN (str2),
start, &regs, end);
match_2 = r == SAFE_STRLEN (str1) + SAFE_STRLEN (str2);
@@ -217,7 +217,7 @@ general_test (pattern_should_be_valid, match_whole_string,
else
{
r = re_search_2 (&nonconst_buf,
- str1, SAFE_STRLEN (str1),
+ str1, SAFE_STRLEN (str1),
str2, SAFE_STRLEN (str2),
start, range, &regs, end);
match_2 = r >= 0;
@@ -225,16 +225,16 @@ general_test (pattern_should_be_valid, match_whole_string,
if (r == -2)
internal_error_2 = true;
-
+
match = match_1 & match_2;
-
+
if (correct_regs)
{
unsigned reg;
if (regs_correct != NULL)
free (regs_correct);
-
- regs_correct
+
+ regs_correct
= (unsigned *) xmalloc (regs.num_regs * sizeof (unsigned));
for (reg = 0;
@@ -256,9 +256,9 @@ general_test (pattern_should_be_valid, match_whole_string,
|| (regs.start[reg] == -1 && regs.end[reg] == -1
&& correct_regs->start[reg]
== correct_regs->end[reg])
-#endif
+#endif
;
-
+
all_regs_correct &= regs_correct[reg];
}
}
@@ -268,15 +268,15 @@ general_test (pattern_should_be_valid, match_whole_string,
if (fastmap_internal_error)
printf ("\n\nInternal error in re_compile_fastmap:");
-
+
if (internal_error_1)
{
if (!fastmap_internal_error)
printf ("\n");
-
+
printf ("\nInternal error in re_match or re_search:");
}
-
+
if (internal_error_2)
{
if (!internal_error_1)
@@ -285,11 +285,11 @@ general_test (pattern_should_be_valid, match_whole_string,
printf ("\nInternal error in re_match_2 or re_search_2:");
}
- if ((OK_TO_SEARCH && ((match && !test_should_match)
+ if ((OK_TO_SEARCH && ((match && !test_should_match)
|| (!match && test_should_match))
|| (correct_regs && !all_regs_correct))
|| !nonconst_buf.fastmap_accurate
- || invalid_pattern
+ || invalid_pattern
|| !pattern_should_be_valid
|| internal_error_1 || internal_error_2
|| verbose)
@@ -324,8 +324,8 @@ general_test (pattern_should_be_valid, match_whole_string,
if ((!(invalid_pattern && !pattern_should_be_valid)) || verbose)
printf (" Pattern: `%s'.\n", pat);
-
- if (pattern_should_be_valid || verbose
+
+ if (pattern_should_be_valid || verbose
|| internal_error_1 || internal_error_2)
{
printf(" Strings: ");
@@ -335,7 +335,7 @@ general_test (pattern_should_be_valid, match_whole_string,
if ((OK_TO_SEARCH || verbose || internal_error_1 || internal_error_2)
&& !invalid_pattern)
{
- if (memcmp (old_buf.buffer, nonconst_buf.buffer,
+ if (memcmp (old_buf.buffer, nonconst_buf.buffer,
nonconst_buf.used) != 0
&& !invalid_pattern)
{
@@ -346,16 +346,16 @@ general_test (pattern_should_be_valid, match_whole_string,
}
else
printf ("\n Compiled pattern: ");
-
+
print_compiled_pattern (&nonconst_buf);
}
if (correct_fastmap && (!nonconst_buf.fastmap_accurate || verbose))
{
- printf ("\n The fastmap should have been: ");
+ printf ("\n The fastmap should have been: ");
print_fastmap (correct_fastmap);
- printf ("\n Fastmap: ");
+ printf ("\n Fastmap: ");
print_fastmap (fastmap);
printf ("\n Compiled pattern before matching: ");
@@ -366,25 +366,25 @@ general_test (pattern_should_be_valid, match_whole_string,
{
unsigned this_reg;
printf ("\n Incorrect registers:");
-
+
for (this_reg = 0; this_reg < regs.num_regs; this_reg++)
{
if (!regs_correct[this_reg])
{
printf ("\n Register %d's start was %2d. ", this_reg,
regs.start[this_reg]);
- printf ("\tIt should have been %d.\n",
+ printf ("\tIt should have been %d.\n",
correct_regs->start[this_reg]);
printf (" Register %d's end was %2d. ", this_reg,
regs.end[this_reg]);
- printf ("\tIt should have been %d.\n",
+ printf ("\tIt should have been %d.\n",
correct_regs->end[this_reg]);
}
}
}
}
}
-
+
if (nonconst_buf.buffer != NULL)
free (nonconst_buf.buffer);
@@ -396,7 +396,7 @@ general_test (pattern_should_be_valid, match_whole_string,
free (regs_correct);
}
-
+
nonconst_buf.buffer = old_buf.buffer = NULL;
regs_correct = NULL;
regs.start = regs.end = NULL;
@@ -419,17 +419,17 @@ test_search_return (match_start_wanted, pattern, string)
num_times_called++;
buf.allocated = 1;
buf.buffer = xmalloc (buf.allocated);
-
+
assert (pattern != NULL);
buf.translate = 0;
compile_return = re_compile_pattern (pattern, strlen (pattern), &buf);
-
+
if (compile_return)
{
printf ("\n\nInvalid pattern in test_match_start:\n");
printf ("%s\n", compile_return);
}
- else
+ else
{
buf.fastmap = fastmap;
match_start = re_search (&buf, string, strlen (string),
@@ -453,8 +453,8 @@ test_search_return (match_start_wanted, pattern, string)
for (this_char = 0; this_char < strlen (fastmap_string); this_char++)\
correct_fastmap[fastmap_string[this_char]] = !invert; \
correct_fastmap['\n'] = match_newline; \
- }
-
+ }
+
void
test_fastmap (pat, fastmap_string, invert, match_newline)
@@ -463,7 +463,7 @@ test_fastmap (pat, fastmap_string, invert, match_newline)
unsigned invert;
unsigned match_newline;
{
- char correct_fastmap[(1 << BYTEWIDTH)];
+ char correct_fastmap[(1 << BYTEWIDTH)];
SET_FASTMAP ();
general_test (1, 0, pat, NULL, NULL, -1, 0, -1, correct_fastmap, 0, -1);
@@ -471,25 +471,25 @@ test_fastmap (pat, fastmap_string, invert, match_newline)
void
-test_fastmap_search (pat, str, fastmap_string, invert, match_newline,
+test_fastmap_search (pat, str, fastmap_string, invert, match_newline,
can_be_null, start0, end0)
- const char *pat;
- char *str;
+ const char *pat;
+ char *str;
char *fastmap_string;
- unsigned invert;
- unsigned match_newline;
- int can_be_null;
- int start0;
+ unsigned invert;
+ unsigned match_newline;
+ int can_be_null;
+ int start0;
int end0;
{
- char correct_fastmap[(1 << BYTEWIDTH)];
+ char correct_fastmap[(1 << BYTEWIDTH)];
struct re_registers correct_regs;
correct_regs.num_regs = RE_NREGS;
correct_regs.start = (int *) xmalloc (RE_NREGS * sizeof (int));
correct_regs.end = (int *) xmalloc (RE_NREGS * sizeof (int));
-
- set_all_registers (start0, end0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+
+ set_all_registers (start0, end0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, &correct_regs);
SET_FASTMAP ();
general_test (1, 0, pat, str, NULL, 0, SAFE_STRLEN (str), SAFE_STRLEN (str),
@@ -503,34 +503,34 @@ test_fastmap_search (pat, str, fastmap_string, invert, match_newline,
void
-test_all_registers (pat, str1, str2,
- start0, end0, start1, end1,
- start2, end2, start3, end3,
- start4, end4, start5, end5,
- start6, end6, start7, end7,
+test_all_registers (pat, str1, str2,
+ start0, end0, start1, end1,
+ start2, end2, start3, end3,
+ start4, end4, start5, end5,
+ start6, end6, start7, end7,
start8, end8, start9, end9)
- char *pat; char *str1; char *str2;
- int start0; int end0; int start1; int end1;
- int start2; int end2; int start3; int end3;
- int start4; int end4; int start5; int end5;
- int start6; int end6; int start7; int end7;
+ char *pat; char *str1; char *str2;
+ int start0; int end0; int start1; int end1;
+ int start2; int end2; int start3; int end3;
+ int start4; int end4; int start5; int end5;
+ int start6; int end6; int start7; int end7;
int start8; int end8; int start9; int end9;
{
struct re_registers correct_regs;
-
+
if (omit_register_tests) return;
-
+
correct_regs.num_regs = RE_NREGS;
correct_regs.start = (int *) xmalloc (RE_NREGS * sizeof (int));
correct_regs.end = (int *) xmalloc (RE_NREGS * sizeof (int));
- set_all_registers (start0, end0, start1, end1, start2, end2, start3, end3,
- start4, end4, start5, end5, start6, end6, start7, end7,
+ set_all_registers (start0, end0, start1, end1, start2, end2, start3, end3,
+ start4, end4, start5, end5, start6, end6, start7, end7,
start8, end8, start9, end9, &correct_regs);
- general_test (1, 0, pat, str1, str2, 0,
- SAFE_STRLEN (str1) + SAFE_STRLEN (str2),
- SAFE_STRLEN (str1) + SAFE_STRLEN (str2),
+ general_test (1, 0, pat, str1, str2, 0,
+ SAFE_STRLEN (str1) + SAFE_STRLEN (str2),
+ SAFE_STRLEN (str1) + SAFE_STRLEN (str2),
NULL, &correct_regs, -1);
free (correct_regs.start);
@@ -547,8 +547,8 @@ invalid_pattern (error_code_expected, pattern)
int cflags
= re_syntax_options == RE_SYNTAX_POSIX_EXTENDED
|| re_syntax_options == RE_SYNTAX_POSIX_MINIMAL_EXTENDED
- ? REG_EXTENDED : 0;
-
+ ? REG_EXTENDED : 0;
+
test_compile (0, error_code_expected, pattern, &pattern_buffer, cflags);
}
@@ -561,8 +561,8 @@ valid_pattern (pattern)
int cflags
= re_syntax_options == RE_SYNTAX_POSIX_EXTENDED
|| re_syntax_options == RE_SYNTAX_POSIX_MINIMAL_EXTENDED
- ? REG_EXTENDED : 0;
-
+ ? REG_EXTENDED : 0;
+
test_compile (1, 0, pattern, &pattern_buffer, cflags);
}
@@ -578,7 +578,7 @@ delimiters_to_ops (source, left_delimiter, right_delimiter)
boolean double_size = false;
unsigned source_char;
unsigned answer_char = 0;
-
+
assert (source != NULL);
switch (left_delimiter)
@@ -608,7 +608,7 @@ delimiters_to_ops (source, left_delimiter, right_delimiter)
answer = NULL;
}
- answer = (char *) xmalloc ((double_size
+ answer = (char *) xmalloc ((double_size
? strlen (source) << 1
: strlen (source))
+ 1);
@@ -618,7 +618,7 @@ delimiters_to_ops (source, left_delimiter, right_delimiter)
{
for (source_char = 0; source_char < strlen (source); source_char++)
{
- if (source[source_char] == left_delimiter
+ if (source[source_char] == left_delimiter
|| source[source_char] == right_delimiter)
answer[answer_char++] = '\\';
@@ -626,14 +626,14 @@ delimiters_to_ops (source, left_delimiter, right_delimiter)
}
answer[answer_char] = 0;
}
-
+
return answer;
}
void
print_pattern_info (pattern, pattern_buffer_ptr)
- const char *pattern;
+ const char *pattern;
regex_t *pattern_buffer_ptr;
{
printf (" Pattern: `%s'.\n", pattern);
@@ -647,13 +647,13 @@ valid_nonposix_pattern (pattern)
char *pattern;
{
struct re_pattern_buffer nonconst_buf;
-
+
nonconst_buf.allocated = 0;
nonconst_buf.buffer = NULL;
nonconst_buf.translate = NULL;
-
+
assert (pattern != NULL);
-
+
if (re_compile_pattern (pattern, strlen (pattern), &nonconst_buf))
{
printf ("Couldn't compile the pattern.\n");
@@ -667,13 +667,13 @@ compile_and_print_pattern (pattern)
char *pattern;
{
struct re_pattern_buffer nonconst_buf;
-
+
nonconst_buf.allocated = 0;
nonconst_buf.buffer = NULL;
-
+
if (re_compile_pattern (pattern, strlen (pattern), &nonconst_buf))
printf ("Couldn't compile the pattern.\n");
-
+
print_pattern_info (pattern, &nonconst_buf);
}
@@ -691,7 +691,7 @@ test_case_fold (pattern, string)
assert (pattern != NULL);
ret = re_compile_pattern (pattern, strlen (pattern), &nonconst_buf);
-
+
if (ret)
{
printf ("\nShould have been a valid pattern but wasn't.\n");
@@ -699,8 +699,8 @@ test_case_fold (pattern, string)
}
else
{
- if (test_should_match
- && re_match (&nonconst_buf, string, strlen (string), 0, 0)
+ if (test_should_match
+ && re_match (&nonconst_buf, string, strlen (string), 0, 0)
!= strlen (string))
{
printf ("Match failed for case fold.\n");
@@ -727,7 +727,7 @@ test_match_n_times (n, pattern, string)
buf.translate = 0;
assert (pattern != NULL);
-
+
r = re_compile_pattern (pattern, strlen (pattern), &buf);
if (r)
{
@@ -738,14 +738,14 @@ test_match_n_times (n, pattern, string)
{
for (this_match = 1; this_match <= n; this_match++)
match = (re_match (&buf, string, strlen (string),
- 0, 0)
+ 0, 0)
== strlen (string));
if (match && !test_should_match)
printf ("\n\nMatched but shouldn't have:\n");
else if (!match && test_should_match)
printf ("\n\nDidn't match but should have:\n");
-
+
if ((match && !test_should_match) || (!match && test_should_match))
{
printf(" The string to match was: ");
@@ -753,7 +753,7 @@ test_match_n_times (n, pattern, string)
printf ("`%s' and ", string);
else
printf ("`'");
-
+
printf (" Pattern: %s.\n", pattern);
printf (" Compiled pattern: %s.\n", pattern);
print_compiled_pattern (&buf);
@@ -762,17 +762,17 @@ test_match_n_times (n, pattern, string)
}
-void
+void
test_match_2 (pat, str1, str2)
- const char *pat;
- char *str1;
+ const char *pat;
+ char *str1;
char *str2;
{
general_test (1, 1, pat, str1, str2, 0, 1,
SAFE_STRLEN (str1) + SAFE_STRLEN (str2), NULL, 0, -1);
}
-void
+void
test_match (pat, str)
const char *pat;
char *str;
OpenPOWER on IntegriCloud