public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: наб <nabijaczleweli@nabijaczleweli.xyz>
To: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>
Cc: libc-alpha@sourceware.org, Carlos O'Donell <carlos@redhat.com>
Subject: [PATCH v7 3/3] posix: add test for REG_STARTEND
Date: Mon, 12 Jun 2023 02:47:56 +0200	[thread overview]
Message-ID: <081705a028f41d488ff81dbe198674aa4df83b1c.1686530834.git.nabijaczleweli@nabijaczleweli.xyz> (raw)
In-Reply-To: <4450a8f3-3774-5bbc-ebe2-64d8a25fdacc@linaro.org>

[-- Attachment #1: Type: text/plain, Size: 6178 bytes --]

This test passes on NetBSD, the illumos gate, musl with
https://www.openwall.com/lists/musl/2023/05/14/1,
and now glibc.
It's nothing revolutionary and the behaviour it tests
is largely guaranteed by the 4.4BSD-Lite manual;
nevertheless, it used to fail with
  tst-reg-startend.c: ^a: a^@c: no match$
  tst-reg-startend.c: ^a: a^@c: wanted {1, 2}, got {1, 4}$
  tst-reg-startend.c: ^a: abc: no match$
  tst-reg-startend.c: ^a: abc: wanted {1, 2}, got {1, 4}$
  tst-reg-startend.c: ^a.c$: a^@c: no match$
  tst-reg-startend.c: ^a.c$: abc: no match$
  tst-reg-startend.c: ^a.*c$: a^@c: no match$
  tst-reg-startend.c: ^a.*c$: abc: no match$
  tst-reg-startend.c: ^a[^c]c$: a^@c: no match$
  tst-reg-startend.c: ^a[^c]c$: abc: no match$
  tst-reg-startend.c: ^a..: a^@c: no match$
  tst-reg-startend.c: ^a..: abc: no match$
  tst-reg-startend.c: ..c: a^@c: no match$

Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
---
 posix/Makefile           |   1 +
 posix/tst-reg-startend.c | 142 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 143 insertions(+)
 create mode 100644 posix/tst-reg-startend.c

diff --git a/posix/Makefile b/posix/Makefile
index e19b74cd67..abc0ff1f60 100644
--- a/posix/Makefile
+++ b/posix/Makefile
@@ -295,6 +295,7 @@ tests := \
   tst-posix_spawn-setsid \
   tst-preadwrite \
   tst-preadwrite64 \
+  tst-reg-startend \
   tst-regcomp-truncated \
   tst-regex \
   tst-regex2 \
diff --git a/posix/tst-reg-startend.c b/posix/tst-reg-startend.c
new file mode 100644
index 0000000000..854d430676
--- /dev/null
+++ b/posix/tst-reg-startend.c
@@ -0,0 +1,142 @@
+/* This is free and unencumbered software released into the public domain.
+
+   Anyone is free to copy, modify, publish, use, compile, sell, or
+   distribute this software, either in source code form or as a compiled
+   binary, for any purpose, commercial or non-commercial, and by any
+   means.
+
+   In jurisdictions that recognize copyright laws, the author or authors
+   of this software dedicate any and all copyright interest in the
+   software to the public domain. We make this dedication for the benefit
+   of the public at large and to the detriment of our heirs and
+   successors. We intend this dedication to be an overt act of
+   relinquishment in perpetuity of all present and future rights to this
+   software under copyright law.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+   OTHER DEALINGS IN THE SOFTWARE.  */
+
+
+#include <assert.h>
+#include <locale.h>
+#include <string.h>
+#include <regex.h>
+#include <stdio.h>
+#include <stdbool.h>
+#include <support/check.h>
+
+
+static const regmatch_t bound = {1, 4};
+
+
+struct reg_res {
+  const char *regex;
+  regmatch_t result;
+};
+static const struct reg_res reg_res_ac[] = {
+  {"^a",       {1, 2}},
+  {"c$",       {3, 4}},
+  {"^a.c$",    {1, 4}},
+  {"^a.*c$",   {1, 4}},
+  {"^a[^c]c$", {1, 4}},
+  {"^a..",     {1, 4}},
+  {"..c",      {1, 4}},
+  {"[^z]c",    {2, 4}},
+  {}
+};
+static const char *const data_ac[] = {"_a\0cdef", "_abcdef", NULL};
+
+static const struct reg_res reg_res_aa[] = {
+  {"^",             {1, 1}},
+  {"^a",            {1, 2}},
+  {"a$",            {3, 4}},
+  {"^\\(a\\).\\1$", {1, 4}},
+  {"^a[^a]*" ,      {1, 3}},
+  {}
+};
+static const char *const data_aa[] = {"_a\0adef", "_abadef", NULL};
+
+
+static void
+testbunch (const struct reg_res *reg_reses, const char *const *const data)
+{
+#define BASEERR(data)                                      \
+  support_record_failure (),                               \
+    fprintf (stdout, __FILE__ ": %s: ", reg_reses->regex), \
+    fwrite (data + bound.rm_so, 1, bound.rm_eo - bound.rm_so, stdout)
+
+  for (; reg_reses->regex; ++reg_reses)
+    {
+      regex_t rgx;
+      assert (!regcomp (&rgx, reg_reses->regex, 0));
+
+      for (const char *const *dt = data; *dt; ++dt)
+        {
+          regmatch_t match = bound;
+          if (regexec (&rgx, *dt, 1, &match, REG_STARTEND))
+            BASEERR(dt), fputs (": no match\n", stdout);
+
+          if (memcmp(&match, &reg_reses->result, sizeof (regmatch_t)))
+            BASEERR(dt), fprintf (stdout, ": wanted {%d, %d}, got {%d, %d}\n",
+                                  (int)reg_reses->result.rm_so,
+                                  (int)reg_reses->result.rm_eo,
+                                  (int)match.rm_so, (int)match.rm_eo);
+        }
+
+      regfree(&rgx);
+    }
+}
+
+
+struct mb_data_exp {
+  const char *data;
+  bool exp;
+};
+static const struct mb_data_exp mb_data_exp[] = {
+  {"_aaćdef", false},
+  {"_aćdef", true},
+  {}
+};
+
+static void
+testmb (void)
+{
+  regex_t rgx;
+  const struct reg_res reg_reses[] = {{"ać"}};
+  assert (!regcomp (&rgx, reg_reses->regex, 0));
+
+  for (const struct mb_data_exp *de = mb_data_exp; de->data; ++de)
+    {
+      regmatch_t match = bound;
+      if (regexec (&rgx, de->data, 1, &match, REG_STARTEND) == de->exp)
+        BASEERR(de->data), fprintf (stdout, ": %s match\n",
+                                    de->exp ? "no" : "yes");
+
+      if (memcmp(&match, &bound, sizeof (regmatch_t)))
+        BASEERR(de->data), fprintf (stdout, ": wanted {%d, %d}, got {%d, %d}\n",
+                                    (int)bound.rm_so, (int)bound.rm_eo,
+                                    (int)match.rm_so, (int)match.rm_eo);
+    }
+
+  regfree(&rgx);
+}
+
+
+static int
+do_test (void)
+{
+  assert (setlocale (LC_ALL, "C.UTF-8"));
+
+  testbunch (reg_res_ac, data_ac);
+  testbunch (reg_res_aa, data_aa);
+  testmb ();
+  return 0;
+}
+
+
+#include <support/test-driver.c>
-- 
2.39.2

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

      parent reply	other threads:[~2023-06-12  0:47 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-07 22:56 [PATCH v4 1/3] posix: add (failing) " наб
2023-05-07 22:56 ` [PATCH v4 2/3] posix: regcomp(): clear RE_DOT_NOT_NULL наб
2023-05-07 22:56 ` [PATCH v4 3/3] posix: regexec(): fix REG_STARTEND, pmatch->rm_so != 0 w/^ anchor наб
2023-05-29 18:11   ` Adhemerval Zanella Netto
2023-05-29 13:22 ` [PATCH v5 1/3] posix: add (failing) test for REG_STARTEND наб
2023-05-29 13:22 ` [PATCH v5 2/3] posix: regcomp(): clear RE_DOT_NOT_NULL наб
2023-05-29 13:22 ` [PATCH v5 3/3] posix: regexec(): fix REG_STARTEND, pmatch->rm_so != 0 w/^ anchor наб
2023-05-29 17:37 ` [PATCH v4 1/3] posix: add (failing) test for REG_STARTEND Adhemerval Zanella Netto
2023-05-29 20:10   ` наб
2023-05-29 20:23     ` Adhemerval Zanella Netto
2023-06-12  0:47       ` [PATCH v7 1/3] posix: regcomp(): clear RE_DOT_NOT_NULL наб
2023-06-12 13:11         ` Carlos O'Donell
2023-06-12  0:47       ` [PATCH v7 2/3] posix: regexec(): fix REG_STARTEND, pmatch->rm_so != 0 w/^ anchor наб
2023-06-12 13:11         ` Carlos O'Donell
2023-06-12 14:03           ` наб
2023-06-12  0:47       ` наб [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=081705a028f41d488ff81dbe198674aa4df83b1c.1686530834.git.nabijaczleweli@nabijaczleweli.xyz \
    --to=nabijaczleweli@nabijaczleweli.xyz \
    --cc=adhemerval.zanella@linaro.org \
    --cc=carlos@redhat.com \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).