summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2011-03-08 10:09:47 +0100
committerBruno Haible <bruno@clisp.org>2011-03-08 10:09:47 +0100
commitfbfced515f325dd000c80fa35ade86e567d0ea3c (patch)
tree15edd13725f7da5660cd80cd1d968df9a7d24569 /tests
parent6ff7b70e24f0e84e9f65ef6d021ff239cad0b2b4 (diff)
downloadgnulib-fbfced515f325dd000c80fa35ade86e567d0ea3c.tar.gz
regex-quote: New API.
* lib/regex-quote.h: Include <stdbool.h>. (struct regex_quote_spec): New type. (regex_quote_spec_posix, regex_quote_spec_gnu, regex_quote_spec_pcre): New declarations. (regex_quote_length, regex_quote_copy, regex_quote): Take a 'const struct regex_quote_spec *' argument. * lib/regex-quote.c (RE_*, PCRE_*): New macros. (pcre_special): New constant. (regex_quote_spec_posix, regex_quote_spec_gnu, regex_quote_spec_pcre): New functions. (regex_quote_length, regex_quote_copy, regex_quote): Take a 'const struct regex_quote_spec *' argument. * modules/regex-quote (Depends-on): Add stdbool. * tests/test-regex-quote.c (check): Update for new API. Add test for anchored results. * NEWS: Mention the API change. Reported by Reuben Thomas and Eric Blake.
Diffstat (limited to 'tests')
-rw-r--r--tests/test-regex-quote.c25
1 files changed, 22 insertions, 3 deletions
diff --git a/tests/test-regex-quote.c b/tests/test-regex-quote.c
index 7f1e8f0857..02728f9347 100644
--- a/tests/test-regex-quote.c
+++ b/tests/test-regex-quote.c
@@ -29,18 +29,37 @@
static void
check (const char *literal, int cflags, const char *expected)
{
+ struct regex_quote_spec spec;
char *result;
size_t length;
- result = regex_quote (literal, cflags);
+ spec = regex_quote_spec_posix (cflags, false);
+ result = regex_quote (literal, &spec);
ASSERT (strcmp (result, expected) == 0);
- length = regex_quote_length (literal, cflags);
+ length = regex_quote_length (literal, &spec);
ASSERT (length == strlen (result));
free (result);
result = (char *) xmalloc (1 + length + 1 + 1);
result[0] = '^';
- strcpy (regex_quote_copy (result + 1, literal, cflags), "$");
+ strcpy (regex_quote_copy (result + 1, literal, &spec), "$");
+ {
+ regex_t regex;
+ regmatch_t match[1];
+
+ ASSERT (regcomp (&regex, result, cflags) == 0);
+
+ ASSERT (regexec (&regex, literal, 1, match, 0) == 0);
+ ASSERT (match[0].rm_so == 0);
+ ASSERT (match[0].rm_eo == strlen (literal));
+ regfree (&regex);
+ }
+ free (result);
+
+ spec = regex_quote_spec_posix (cflags, true);
+ result = regex_quote (literal, &spec);
+ length = regex_quote_length (literal, &spec);
+ ASSERT (length == strlen (result));
{
regex_t regex;
regmatch_t match[1];