* mu-str.c: do some more massaging for xapian queries with brackets, add unit tests

This commit is contained in:
djcb 2012-05-04 20:58:34 +03:00
parent 858c874fbd
commit 9db172792d
3 changed files with 45 additions and 5 deletions

View File

@ -406,6 +406,13 @@ check_for_field (const char *str, gboolean *is_field, gboolean *is_range_field)
CheckPrefix pfx;
pfx.str = str;
/* skip any non-alphanum starts in cpfx->str; this is to
* handle the case where we have e.g. "(maildir:/abc)"
*/
while (pfx.str && !isalnum(*pfx.str))
++pfx.str;
pfx.match = pfx.range_field = FALSE;
mu_msg_field_foreach ((MuMsgFieldForeachFunc)each_check_prefix,
@ -454,6 +461,8 @@ mu_str_xapian_escape_in_place (char *term, gboolean esc_space)
*cur = escchar;
++colon;
break;
case '(':
case ')':
case '\'':
case '*': /* wildcard */
break;

View File

@ -223,7 +223,6 @@ test_mu_query_03 (void)
g_assert_cmpuint (run_and_count_matches (xpath, queries[i].query),
==, queries[i].count);
g_free (xpath);
}
@ -234,10 +233,10 @@ test_mu_query_04 (void)
int i;
QResults queries[] = {
{ "frodo@example.com", 1}, /* does not match: see mu-find (1) */
{ "frodo@example.com", 1},
{ "f:frodo@example.com", 1},
{ "f:Frodo Baggins", 1},
{ "bilbo@anotherexample.com", 1}, /* same things */
{ "bilbo@anotherexample.com", 1},
{ "t:bilbo@anotherexample.com", 1},
{ "t:bilbo", 1},
{ "f:bilbo", 0},
@ -256,10 +255,38 @@ test_mu_query_04 (void)
g_assert_cmpuint (run_and_count_matches (xpath, queries[i].query),
==, queries[i].count);
g_free (xpath);
}
static void
test_mu_query_logic (void)
{
gchar *xpath;
int i;
QResults queries[] = {
{ "subject:gcc" , 1},
{ "subject:lisp" , 1},
{ "subject:gcc OR subject:lisp" , 2},
{ "subject:gcc or subject:lisp" , 2},
{ "subject:gcc AND subject:lisp" , 0},
{ "subject:gcc OR (subject:scheme AND subject:elisp)" , 2},
{ "(subject:gcc OR subject:scheme) AND subject:elisp" , 1}
};
xpath = fill_database (MU_TESTMAILDIR);
g_assert (xpath != NULL);
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
g_assert_cmpuint (run_and_count_matches (xpath, queries[i].query),
==, queries[i].count);
g_free (xpath);
}
static void
test_mu_query_accented_chars_01 (void)
{
@ -599,6 +626,9 @@ main (int argc, char *argv[])
g_test_add_func ("/mu-query/test-mu-query-02", test_mu_query_02);
g_test_add_func ("/mu-query/test-mu-query-03", test_mu_query_03);
g_test_add_func ("/mu-query/test-mu-query-04", test_mu_query_04);
g_test_add_func ("/mu-query/test-mu-query-logic", test_mu_query_logic);
g_test_add_func ("/mu-query/test-mu-query-accented-chars-1",
test_mu_query_accented_chars_01);
g_test_add_func ("/mu-query/test-mu-query-accented-chars-2",

View File

@ -199,7 +199,8 @@ test_mu_str_xapian_escape (void)
{ "size:10..20", "size:10..20"},
{ "x:2010..2012", "x:2010__2012"},
{ "q:2010..2012", "q_2010__2012"},
{ "subject:2010..2012", "subject:2010__2012"}
{ "subject:2010..2012", "subject:2010__2012"},
{ "(maildir:foo)", "(maildir:foo)"}
};
for (i = 0; i != G_N_ELEMENTS(words); ++i) {