mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-04-01 21:33:09 +02:00
tests/regex: Make possible to test replacements with options
This commit is contained in:
parent
5e76cde5ff
commit
0831393dd0
@ -1207,6 +1207,8 @@ typedef struct {
|
|||||||
gint start_position;
|
gint start_position;
|
||||||
const gchar *replacement;
|
const gchar *replacement;
|
||||||
const gchar *expected;
|
const gchar *expected;
|
||||||
|
GRegexCompileFlags compile_flags;
|
||||||
|
GRegexMatchFlags match_flags;
|
||||||
} TestReplaceData;
|
} TestReplaceData;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -1215,17 +1217,25 @@ test_replace (gconstpointer d)
|
|||||||
const TestReplaceData *data = d;
|
const TestReplaceData *data = d;
|
||||||
GRegex *regex;
|
GRegex *regex;
|
||||||
gchar *res;
|
gchar *res;
|
||||||
|
GError *error = NULL;
|
||||||
|
|
||||||
regex = g_regex_new (data->pattern, G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, NULL);
|
regex = g_regex_new (data->pattern, data->compile_flags, G_REGEX_MATCH_DEFAULT, &error);
|
||||||
res = g_regex_replace (regex, data->string, -1, data->start_position, data->replacement, 0, NULL);
|
g_assert_no_error (error);
|
||||||
|
|
||||||
|
res = g_regex_replace (regex, data->string, -1, data->start_position,
|
||||||
|
data->replacement, data->match_flags, &error);
|
||||||
|
|
||||||
g_assert_cmpstr (res, ==, data->expected);
|
g_assert_cmpstr (res, ==, data->expected);
|
||||||
|
|
||||||
|
if (data->expected)
|
||||||
|
g_assert_no_error (error);
|
||||||
|
|
||||||
g_free (res);
|
g_free (res);
|
||||||
g_regex_unref (regex);
|
g_regex_unref (regex);
|
||||||
|
g_clear_error (&error);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define TEST_REPLACE(_pattern, _string, _start_position, _replacement, _expected) { \
|
#define TEST_REPLACE_OPTIONS(_pattern, _string, _start_position, _replacement, _expected, _compile_flags, _match_flags) { \
|
||||||
TestReplaceData *data; \
|
TestReplaceData *data; \
|
||||||
gchar *path; \
|
gchar *path; \
|
||||||
data = g_new0 (TestReplaceData, 1); \
|
data = g_new0 (TestReplaceData, 1); \
|
||||||
@ -1234,11 +1244,16 @@ test_replace (gconstpointer d)
|
|||||||
data->start_position = _start_position; \
|
data->start_position = _start_position; \
|
||||||
data->replacement = _replacement; \
|
data->replacement = _replacement; \
|
||||||
data->expected = _expected; \
|
data->expected = _expected; \
|
||||||
|
data->compile_flags = _compile_flags; \
|
||||||
|
data->match_flags = _match_flags; \
|
||||||
path = g_strdup_printf ("/regex/replace/%d", ++total); \
|
path = g_strdup_printf ("/regex/replace/%d", ++total); \
|
||||||
g_test_add_data_func_full (path, data, test_replace, g_free); \
|
g_test_add_data_func_full (path, data, test_replace, g_free); \
|
||||||
g_free (path); \
|
g_free (path); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define TEST_REPLACE(_pattern, _string, _start_position, _replacement, _expected) \
|
||||||
|
TEST_REPLACE_OPTIONS (_pattern, _string, _start_position, _replacement, _expected, 0, 0)
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_replace_lit (gconstpointer d)
|
test_replace_lit (gconstpointer d)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user