]> rtime.felk.cvut.cz Git - notmuch.git/commitdiff
Query parser tests for wildcard queries.
authorAustin Clements <amdragon@MIT.EDU>
Fri, 21 Jan 2011 06:40:03 +0000 (01:40 -0500)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Sat, 22 Jan 2011 16:27:39 +0000 (17:27 +0100)
Since wildcard queries require a database, qparser-test can now open a
database.

test/qparser
test/qparser-test.cc
test/qparser.expected-output/wildcards [new file with mode: 0644]

index 7ed5c97222270fcbf078068a79fc8c643d95dcbc..d77e2b2bc0d9971614341501e03f7d8bd557e25b 100755 (executable)
@@ -34,4 +34,11 @@ output=$(../qparser-test < $EXPECTED/probs)
 expected=$(cat $EXPECTED/probs)
 test_expect_equal "$output" "$expected"
 
+add_message '[body]="Peter Piper picked a peck of pickled peppers"'
+
+test_begin_subtest "Wildcards"
+output=$(../qparser-test -d < $EXPECTED/wildcards)
+expected=$(cat $EXPECTED/wildcards)
+test_expect_equal "$output" "$expected"
+
 test_done
index 69a1c158e674eb84c06580fefae2962adb1d01da..18318aaececf7b9012f1aabff7cd8aabb0f87393 100644 (file)
@@ -42,6 +42,7 @@ extern "C" {
 #include "../notmuch-client.h"
 }
 
+static notmuch_database_t *notmuch;
 static _notmuch_qparser_t *qparser;
 static Xapian::QueryParser xqparser;
 
@@ -98,7 +99,7 @@ test_one (void *ctx, const char *query_str)
 static _notmuch_qparser_t *
 create_qparser (void *ctx)
 {
-    _notmuch_qparser_t *qparser = _notmuch_qparser_create (ctx, NULL);
+    _notmuch_qparser_t *qparser = _notmuch_qparser_create (ctx, notmuch);
     _notmuch_qparser_add_db_prefix (qparser, "prob", "P", FALSE);
     _notmuch_qparser_add_db_prefix (qparser, "lit", "L", TRUE);
     _notmuch_qparser_add_db_prefix (qparser, "tag", "K", TRUE);
@@ -109,6 +110,8 @@ static Xapian::QueryParser
 create_xapian_qparser (void)
 {
     Xapian::QueryParser xq;
+    if (notmuch)
+       xq.set_database (*notmuch->xapian_db);
     xq.set_default_op (Xapian::Query::OP_AND);
     xq.add_prefix ("prob", "P");
     xq.add_boolean_prefix ("lit", "L");
@@ -120,9 +123,27 @@ int
 main (int argc, char **argv)
 {
     void *ctx;
+    notmuch_config_t *config;
 
     ctx = talloc_new (NULL);
 
+    if (argc > 1 && strcmp(argv[1], "-d") == 0) {
+       argc--;
+       argv++;
+
+       /* Open the database */
+       config = notmuch_config_open (ctx, NULL, NULL);
+       if (config == NULL)
+           return 1;
+
+       notmuch = notmuch_database_open (notmuch_config_get_database_path (config),
+                                        NOTMUCH_DATABASE_MODE_READ_ONLY);
+       if (notmuch == NULL)
+           return 1;
+    } else {
+       notmuch = NULL;
+    }
+
     qparser = create_qparser (ctx);
     xqparser = create_xapian_qparser ();
 
@@ -149,5 +170,7 @@ main (int argc, char **argv)
        }
     }
 
+    if (notmuch)
+       notmuch_database_close (notmuch);
     return 0;
 }
diff --git a/test/qparser.expected-output/wildcards b/test/qparser.expected-output/wildcards
new file mode 100644 (file)
index 0000000..6f62829
--- /dev/null
@@ -0,0 +1,20 @@
+# Basic wildcard expansion
+p* AND x
+[lex]    "p"* AND "x"
+[parse]  (AND "p"* "x")
+[gen]    ((peck:(pos=1) SYNONYM peppers:(pos=1) SYNONYM peter:(pos=1) SYNONYM picked:(pos=1) SYNONYM pickled:(pos=1) SYNONYM piper:(pos=1)) AND x:(pos=2))
+
+# Incompatible; Xapian considers this a syntax error
+*
+[lex]    ""*
+[parse]  ""*
+[gen]    <alldocuments>
+[xapian] 
+
+# Wildcard that matches nothing.  Xapian handles this differently
+# but equivalently.
+nosuchterm* AND x
+[lex]    "nosuchterm"* AND "x"
+[parse]  (AND "nosuchterm"* "x")
+[gen]    (nosuchterm AND x:(pos=1))
+[xapian]