gpattern: Implement copy function

Add copy ability for pattern spec, so that it can be used as a boxed
type.
This commit is contained in:
Marco Trevisan (Treviño)
2021-04-25 02:30:57 +02:00
parent 232d008ec8
commit 474ece6d61
4 changed files with 53 additions and 0 deletions

View File

@@ -84,6 +84,24 @@ test_compilation (gconstpointer d)
g_pattern_spec_free (spec);
}
static void
test_copy (gconstpointer d)
{
const CompileTest *test = d;
GPatternSpec *p1, *p2;
p1 = g_pattern_spec_new (test->src);
p2 = g_pattern_spec_copy (p1);
g_assert_cmpint (p2->match_type, ==, test->match_type);
g_assert_cmpstr (p2->pattern, ==, test->pattern);
g_assert_cmpint (p2->pattern_length, ==, strlen (p1->pattern));
g_assert_cmpint (p2->min_length, ==, test->min);
g_pattern_spec_free (p1);
g_pattern_spec_free (p2);
}
typedef struct _MatchTest MatchTest;
struct _MatchTest
@@ -222,6 +240,13 @@ main (int argc, char** argv)
g_free (path);
}
for (i = 0; i < G_N_ELEMENTS (compile_tests); i++)
{
path = g_strdup_printf ("/pattern/copy/%" G_GSIZE_FORMAT, i);
g_test_add_data_func (path, &compile_tests[i], test_copy);
g_free (path);
}
for (i = 0; i < G_N_ELEMENTS (match_tests); i++)
{
path = g_strdup_printf ("/pattern/match/%" G_GSIZE_FORMAT, i);