18 static const char *match =
"this is a string";
19 static const regmatch_t submatches[] = {
20 { .rm_so = 0, .rm_eo = 16 },
21 { .rm_so = 5, .rm_eo = 7 },
22 { .rm_so = 9, .rm_eo = 9 },
24 static const int nmatches = 3;
27 assert_submatch(
const char *
string,
const char *reference)
29 char *expanded = NULL;
32 if ((expanded == NULL) || (reference == NULL)) {
33 assert_null(expanded);
34 assert_null(reference);
36 assert_int_equal(strcmp(expanded, reference), 0);
42 no_source(
void **state)
45 assert_submatch(NULL, NULL);
46 assert_submatch(
"", NULL);
50 source_has_no_variables(
void **state)
53 match, submatches, nmatches));
55 match, submatches, nmatches));
57 match, submatches, nmatches));
61 without_matches(
void **state)
63 assert_submatch(
"this has an empty submatch %2",
64 "this has an empty submatch ");
65 assert_submatch(
"this has a nonexistent submatch %3",
66 "this has a nonexistent submatch ");
70 with_matches(
void **state)
72 assert_submatch(
"%0", match);
73 assert_submatch(
"this %1",
"this is");
74 assert_submatch(
"%1 this %ok",
"is this %ok");
78 cmocka_unit_test(no_source),
79 cmocka_unit_test(source_has_no_variables),
80 cmocka_unit_test(without_matches),
81 cmocka_unit_test(with_matches))
#define PCMK__UNIT_TEST(group_setup, group_teardown,...)
char * pcmk__replace_submatches(const char *string, const char *match, const regmatch_t submatches[], int nmatches)