diff options
author | Marco Barisione <marco@barisione.org> | 2007-05-29 09:32:34 +0000 |
---|---|---|
committer | Marco Barisione <mbari@src.gnome.org> | 2007-05-29 09:32:34 +0000 |
commit | 0fc6c7288aff6d735f2e05c2139f85d31ea26319 (patch) | |
tree | a30ac564745ba809777ba372942dba91ab7222dd /tests | |
parent | 07d778754a27b617457f253b006328f3d20af9b0 (diff) |
Fix g_regex_fetch_named() and g_regex_fetch_named_pos() when
2007-05-29 Marco Barisione <marco@barisione.org>
* 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
Diffstat (limited to 'tests')
-rw-r--r-- | tests/regex-test.c | 23 |
1 files changed, 21 insertions, 2 deletions
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("(?P<A>a)?(?P<B>b)", "b", 0, "A", "", -1, -1); TEST_NAMED_SUB_PATTERN("(?P<A>a)?(?P<B>b)", "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("(?P<N>a)|(?P<N>b)", "ab", 0, "N", "a", 0, 1); + TEST_NAMED_SUB_PATTERN_DUPNAMES("(?P<N>aa)|(?P<N>a)", "aa", 0, "N", "aa", 0, 2); + TEST_NAMED_SUB_PATTERN_DUPNAMES("(?P<N>aa)(?P<N>a)", "aaa", 0, "N", "aa", 0, 2); + TEST_NAMED_SUB_PATTERN_DUPNAMES("(?P<N>x)|(?P<N>a)", "a", 0, "N", "a", 0, 1); + TEST_NAMED_SUB_PATTERN_DUPNAMES("(?P<N>x)y|(?P<N>a)b", "ab", 0, "N", "a", 0, 1); + /* TEST_FETCH_ALL#(pattern, string, ...) */ TEST_FETCH_ALL0("a", ""); TEST_FETCH_ALL0("a", "b"); |