Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id D0E03431FD0 for ; Thu, 20 Jan 2011 22:40:07 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id jA8UcThkPqfM for ; Thu, 20 Jan 2011 22:40:07 -0800 (PST) Received: from dmz-mailsec-scanner-2.mit.edu (DMZ-MAILSEC-SCANNER-2.MIT.EDU [18.9.25.13]) by olra.theworths.org (Postfix) with ESMTP id 48926431FB6 for ; Thu, 20 Jan 2011 22:40:07 -0800 (PST) X-AuditID: 1209190d-b7cacae000000a14-5b-4d392a46dc74 Received: from mailhub-auth-2.mit.edu ( [18.7.62.36]) by dmz-mailsec-scanner-2.mit.edu (Symantec Brightmail Gateway) with SMTP id 68.9C.02580.64A293D4; Fri, 21 Jan 2011 01:40:06 -0500 (EST) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id p0L6e5JS018056; Fri, 21 Jan 2011 01:40:05 -0500 Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id p0L6e4Sh004864 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Fri, 21 Jan 2011 01:40:04 -0500 (EST) Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.72) (envelope-from ) id 1PgAfE-0000zj-08; Fri, 21 Jan 2011 01:40:04 -0500 Date: Fri, 21 Jan 2011 01:40:03 -0500 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH 3.5/8] Query parser tests for wildcard queries. Message-ID: <20110121064003.GK13226@mit.edu> References: <1295165458-9573-1-git-send-email-amdragon@mit.edu> <1295165458-9573-4-git-send-email-amdragon@mit.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1295165458-9573-4-git-send-email-amdragon@mit.edu> User-Agent: Mutt/1.5.20 (2009-06-14) X-Brightmail-Tracker: AAAAAA== Cc: amdragon@mit.edu X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 21 Jan 2011 06:40:08 -0000 Since wildcard queries require a database, qparser-test can now open a database. --- This is intended to be applied after patch 3/5 in this series, id:1295165458-9573-4-git-send-email-amdragon@mit.edu test/qparser | 7 +++++++ test/qparser-test.cc | 25 ++++++++++++++++++++++++- test/qparser.expected-output/wildcards | 20 ++++++++++++++++++++ 3 files changed, 51 insertions(+), 1 deletions(-) create mode 100644 test/qparser.expected-output/wildcards diff --git a/test/qparser b/test/qparser index 7ed5c97..d77e2b2 100755 --- a/test/qparser +++ b/test/qparser @@ -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 diff --git a/test/qparser-test.cc b/test/qparser-test.cc index 01d6bae..ae6c8b9 100644 --- a/test/qparser-test.cc +++ b/test/qparser-test.cc @@ -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 index 0000000..6f62829 --- /dev/null +++ b/test/qparser.expected-output/wildcards @@ -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] +[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] -- 1.7.2.3