• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1From 0831393dd08d5f9dcf2e0517dbb4ea546ff7156b Mon Sep 17 00:00:00 2001
2From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= <mail@3v1n0.net>
3Date: Wed, 7 Sep 2022 15:21:52 +0200
4Subject: [PATCH] tests/regex: Make possible to test replacements with options
5
6---
7 glib/tests/regex.c | 21 ++++++++++++++++++---
8 1 file changed, 18 insertions(+), 3 deletions(-)
9
10diff --git a/glib/tests/regex.c b/glib/tests/regex.c
11index 291c21b4c7..26844d63a7 100644
12--- a/glib/tests/regex.c
13+++ b/glib/tests/regex.c
14@@ -1207,6 +1207,8 @@ typedef struct {
15   gint         start_position;
16   const gchar *replacement;
17   const gchar *expected;
18+  GRegexCompileFlags compile_flags;
19+  GRegexMatchFlags match_flags;
20 } TestReplaceData;
21
22 static void
23@@ -1215,17 +1217,25 @@ test_replace (gconstpointer d)
24   const TestReplaceData *data = d;
25   GRegex *regex;
26   gchar *res;
27+  GError *error = NULL;
28
29-  regex = g_regex_new (data->pattern, G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, NULL);
30-  res = g_regex_replace (regex, data->string, -1, data->start_position, data->replacement, 0, NULL);
31+  regex = g_regex_new (data->pattern, data->compile_flags, G_REGEX_MATCH_DEFAULT, &error);
32+  g_assert_no_error (error);
33+
34+  res = g_regex_replace (regex, data->string, -1, data->start_position,
35+                         data->replacement, data->match_flags, &error);
36
37   g_assert_cmpstr (res, ==, data->expected);
38
39+  if (data->expected)
40+    g_assert_no_error (error);
41+
42   g_free (res);
43   g_regex_unref (regex);
44+  g_clear_error (&error);
45 }
46
47-#define TEST_REPLACE(_pattern, _string, _start_position, _replacement, _expected) { \
48+#define TEST_REPLACE_OPTIONS(_pattern, _string, _start_position, _replacement, _expected, _compile_flags, _match_flags) { \
49   TestReplaceData *data;                                                \
50   gchar *path;                                                          \
51   data = g_new0 (TestReplaceData, 1);                                   \
52@@ -1234,11 +1244,16 @@ test_replace (gconstpointer d)
53   data->start_position = _start_position;                               \
54   data->replacement = _replacement;                                     \
55   data->expected = _expected;                                           \
56+  data->compile_flags = _compile_flags;                                 \
57+  data->match_flags = _match_flags;                                     \
58   path = g_strdup_printf ("/regex/replace/%d", ++total);                \
59   g_test_add_data_func_full (path, data, test_replace, g_free);         \
60   g_free (path);                                                        \
61 }
62
63+#define TEST_REPLACE(_pattern, _string, _start_position, _replacement, _expected) \
64+  TEST_REPLACE_OPTIONS (_pattern, _string, _start_position, _replacement, _expected, 0, 0)
65+
66 static void
67 test_replace_lit (gconstpointer d)
68 {
69--
70GitLab
71
72