From 0fc6c7288aff6d735f2e05c2139f85d31ea26319 Mon Sep 17 00:00:00 2001 From: Marco Barisione Date: Tue, 29 May 2007 09:32:34 +0000 Subject: Fix g_regex_fetch_named() and g_regex_fetch_named_pos() when 2007-05-29 Marco Barisione * glib/gregex.c: Fix g_regex_fetch_named() and g_regex_fetch_named_pos() when G_REGEX_DUPNAMES is used (#434358, Yevgen Muntyan and #419376, Marco Barisione, patch by Yevgen Muntyan) svn path=/trunk/; revision=5518 --- tests/regex-test.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/regex-test.c b/tests/regex-test.c index e1eeb272f..9a18e767a 100644 --- a/tests/regex-test.c +++ b/tests/regex-test.c @@ -573,6 +573,7 @@ test_sub_pattern (const gchar *pattern, static gboolean test_named_sub_pattern (const gchar *pattern, + GRegexCompileFlags flags, const gchar *string, gint start_position, const gchar *sub_name, @@ -588,7 +589,7 @@ test_named_sub_pattern (const gchar *pattern, verbose ("fetching sub-pattern \"%s\" from \"%s\" (pattern: \"%s\") \t", sub_name, string, pattern); - regex = g_regex_new (pattern, 0, 0, NULL); + regex = g_regex_new (pattern, flags, 0, NULL); g_regex_match_full (regex, string, -1, start_position, 0, &match_info, NULL); sub_expr = g_match_info_fetch_named (match_info, sub_name); @@ -621,13 +622,23 @@ test_named_sub_pattern (const gchar *pattern, #define TEST_NAMED_SUB_PATTERN(pattern, string, start_position, sub_name, \ expected_sub, expected_start, expected_end) { \ total++; \ - if (test_named_sub_pattern (pattern, string, start_position, sub_name, \ + if (test_named_sub_pattern (pattern, 0, string, start_position, sub_name, \ expected_sub, expected_start, expected_end)) \ PASS; \ else \ FAIL; \ } +#define TEST_NAMED_SUB_PATTERN_DUPNAMES(pattern, string, start_position, sub_name, \ + expected_sub, expected_start, expected_end) { \ + total++; \ + if (test_named_sub_pattern (pattern, G_REGEX_DUPNAMES, string, start_position, \ + sub_name, expected_sub, expected_start, expected_end)) \ + PASS; \ + else \ + FAIL; \ +} + static gboolean test_fetch_all (const gchar *pattern, const gchar *string, @@ -1766,6 +1777,14 @@ main (int argc, char *argv[]) TEST_NAMED_SUB_PATTERN("(?Pa)?(?Pb)", "b", 0, "A", "", -1, -1); TEST_NAMED_SUB_PATTERN("(?Pa)?(?Pb)", "b", 0, "B", "b", 0, 1); + /* TEST_NAMED_SUB_PATTERN_DUPNAMES(pattern, string, start_position, sub_name, + * expected_sub, expected_start, expected_end) */ + TEST_NAMED_SUB_PATTERN_DUPNAMES("(?Pa)|(?Pb)", "ab", 0, "N", "a", 0, 1); + TEST_NAMED_SUB_PATTERN_DUPNAMES("(?Paa)|(?Pa)", "aa", 0, "N", "aa", 0, 2); + TEST_NAMED_SUB_PATTERN_DUPNAMES("(?Paa)(?Pa)", "aaa", 0, "N", "aa", 0, 2); + TEST_NAMED_SUB_PATTERN_DUPNAMES("(?Px)|(?Pa)", "a", 0, "N", "a", 0, 1); + TEST_NAMED_SUB_PATTERN_DUPNAMES("(?Px)y|(?Pa)b", "ab", 0, "N", "a", 0, 1); + /* TEST_FETCH_ALL#(pattern, string, ...) */ TEST_FETCH_ALL0("a", ""); TEST_FETCH_ALL0("a", "b"); -- cgit v1.2.3