unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: David Bremner <david@tethera.net>
To: notmuch@notmuchmail.org
Subject: [WIP2 2/5] test: add known broken tests for implicit operators
Date: Sat, 31 Aug 2019 22:37:45 -0300	[thread overview]
Message-ID: <20190901013748.7470-3-david@tethera.net> (raw)
In-Reply-To: <20190901013748.7470-1-david@tethera.net>

Given we want 'a b' to parse as 'a AND b', then for any
probabilistic (free text) prefix foo:, we should also get 'foo:a
foo:b' expanding to 'foo:a AND foo:b'. Currently this is not true due
to the implimentation of regex fields. On the other hand for
"exclusive" (i.e. one per message) fields, we want the 'foo:a foo:b'
to expand to (foo:a OR foo:b) since otherwise it will be empty unless
a=b.  The regex variants complicate things, but we stick to the same
rules.

Some of these tests pass, when we are following the Xapian defaults,
and not trying to tricky things with boolean fields impersonating
probabilistic ones.
---
 test/T760-implicit-operators.sh | 161 ++++++++++++++++++++++++++++++++
 1 file changed, 161 insertions(+)
 create mode 100755 test/T760-implicit-operators.sh

diff --git a/test/T760-implicit-operators.sh b/test/T760-implicit-operators.sh
new file mode 100755
index 00000000..40f0bc22
--- /dev/null
+++ b/test/T760-implicit-operators.sh
@@ -0,0 +1,161 @@
+#!/usr/bin/env bash
+test_description='implicit operators in query parser'
+. $(dirname "$0")/test-lib.sh || exit 1
+
+# test expected behaviour for probabilistic fields
+
+test_prob() {
+    add_message  "[id]=$1@one [$1]='Alice <agent@tla.galactic.over.lord>'"
+    add_message  "[id]=$1@two [$1]='Bob <bungler@tla.galactic.over.lord>'"
+
+    test_begin_subtest "phrase search for '$1': matches"
+    notmuch search --output=messages id:$1@one > EXPECTED
+    notmuch search --output=messages "$1:\"alice agent\"" > OUTPUT
+    test_expect_equal_file EXPECTED OUTPUT
+
+    test_begin_subtest "out of order phrase '$1': does not match"
+    notmuch search --output=messages "$1:\"agent alice\"" > OUTPUT
+    test_expect_equal_file /dev/null OUTPUT
+
+    test_begin_subtest "field '$1' is implicit AND"
+    $2
+    notmuch search $1:agent and $1:tla > EXPECTED
+    notmuch search $1:agent $1:tla > OUTPUT
+    test_expect_equal_file EXPECTED OUTPUT
+}
+
+# test expected behaviour for probabilistic fields that also support
+# regex search
+
+test_prob_regex() {
+    test_prob $1 $2
+
+    test_begin_subtest "regex for '$1': matches"
+    notmuch search --output=messages id:$1@one > EXPECTED
+    notmuch search --output=messages "$1:/agent@tla/" > OUTPUT
+    test_expect_equal_file EXPECTED OUTPUT
+
+    test_begin_subtest "regex wrong punctation for '$1': does not"
+    notmuch search --output=messages "$1:/agent-tla/" > OUTPUT
+    test_expect_equal_file /dev/null OUTPUT
+
+    test_begin_subtest "regex for '$1' implicit AND"
+    $2
+    notmuch search --output=messages id:$1@one > EXPECTED
+    notmuch search --output=messages $1:/agent/ $1:/tla/ > OUTPUT
+    test_expect_equal_file EXPECTED OUTPUT
+
+    test_begin_subtest "subquery for '$1' implicit AND"
+    $2
+    notmuch search --output=messages id:$1@one > EXPECTED
+    notmuch search --output=messages "$1:\"(agent alice)\"" > OUTPUT
+    test_expect_equal_file EXPECTED OUTPUT
+}
+
+
+# we have to test this separately because the quoting is sadly different
+test_prob_not_regex() {
+    test_prob $1
+
+    test_begin_subtest "subquery for '$1' implicit AND"
+    notmuch search --output=messages id:$1@one > EXPECTED
+    notmuch search --output=messages "$1:(agent alice)" > OUTPUT
+    test_expect_equal_file EXPECTED OUTPUT
+}
+
+test_bool_exclusive () {
+    add_message "[id]=$1@one [$2]=$1@one"
+    add_message "[id]=$1@two [$2]=$1@two"
+
+    test_begin_subtest "'$1' implicit OR"
+    notmuch search --output=messages $1:$1@one OR $1:$1@two > EXPECTED
+    notmuch search --output=messages $1:$1@one $1:$1@two > OUTPUT
+    test_expect_equal_file EXPECTED OUTPUT
+}
+
+test_bool_exclusive_regex () {
+    test_bool_exclusive $1 $2
+
+    test_begin_subtest "regex '$1' implicit OR"
+    notmuch search --output=messages $1:$1@one OR $1:$1@two > EXPECTED
+    notmuch search --output=messages $1:/^$1@one/ $1:/^$1@two/ > OUTPUT
+    test_expect_equal_file EXPECTED OUTPUT
+}
+
+add_email_corpus
+
+test_prob_not_regex to
+test_prob_not_regex body
+test_prob_regex from test_subtest_known_broken
+test_prob_regex subject test_subtest_known_broken
+
+test_bool_exclusive id id
+test_bool_exclusive_regex mid id
+test_bool_exclusive_regex path dir
+test_bool_exclusive folder dir
+
+add_message "[id]=aug@2019 [date]='Sat, 31 Aug 2019 01:14:40 -0400'"
+add_message "[id]=may@2014 [date]='Thu, 22 May 2014 11:45:01 -0700'"
+test_begin_subtest "'date' is implicit OR"
+notmuch search --output=messages date:2019 OR date:2014 > EXPECTED
+notmuch search --output=messages date:2019 date:2014 > OUTPUT
+test_expect_equal_file EXPECTED OUTPUT
+
+add_message "[id]=tag@one"
+add_message "[id]=tag@two"
+notmuch tag +one id:tag@one
+notmuch tag +two id:tag@two
+
+test_begin_subtest "'tag' is implicit AND"
+test_subtest_known_broken
+notmuch search --output=messages tag:one tag:two > OUTPUT
+test_expect_equal_file /dev/null OUTPUT
+
+test_begin_subtest "'thread:<thread-id>' is implicit OR"
+notmuch search --output=messages thread:0000000000000001 OR thread:0000000000000002 > EXPECTED
+notmuch search --output=messages thread:0000000000000001 thread:0000000000000002 > OUTPUT
+test_expect_equal_file EXPECTED OUTPUT
+
+test_begin_subtest "sanity check for non-zero output"
+test_expect_success "test -s OUTPUT"
+
+test_begin_subtest "'mimetype' is implicit AND"
+notmuch search --output=messages mimetype:application/pgp-signature AND \
+        mimetype:multipart/signed > EXPECTED
+notmuch search --output=messages mimetype:application/pgp-signature \
+        mimetype:multipart/signed > OUTPUT
+test_expect_equal_file EXPECTED OUTPUT
+
+test_begin_subtest "sanity check for non-zero output"
+test_expect_success "test -s OUTPUT"
+
+test_begin_subtest "'mimetype' is implicit AND (II)"
+notmuch search --output=messages is:signed > EXPECTED
+notmuch search --output=messages mimetype:application/pgp-signature  mimetype:multipart/signed > OUTPUT
+test_expect_equal_file EXPECTED OUTPUT
+
+test_begin_subtest "'attachment' with OR is non-empty"
+notmuch search --output=messages attachment:notmuch-help.patch \
+        OR attachment:signature.asc > OUTPUT
+test_expect_success "test -s OUTPUT"
+
+test_begin_subtest "'attachment' is implicit AND"
+notmuch search --output=messages attachment:notmuch-help.patch AND \
+        attachment:signature.asc > OUTPUT
+test_expect_equal_file /dev/null OUTPUT
+
+test_begin_subtest "'folder' with OR is non-empty"
+notmuch search --output=messages folder:bar/baz \
+        folder:foo/baz > OUTPUT
+test_expect_success "test -s OUTPUT"
+
+test_begin_subtest "'folder' is implicit AND"
+notmuch search --output=messages folder:bar/baz \
+        attachment:signature.asc > OUTPUT
+test_expect_equal_file /dev/null OUTPUT
+
+test_begin_subtest "'lastmod' is implicit OR"
+notmuch search lastmod:0..1 lastmod:2..1000 > OUTPUT
+test_expect_success "test -s OUTPUT"
+
+test_done
-- 
2.23.0.rc1

  parent reply	other threads:[~2019-09-01  1:49 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-01  1:37 WIP: fixes for implicit operators and subqueries David Bremner
2019-09-01  1:37 ` [WIP2 1/5] lib: rename _debug_query to _notmuch_query_debug, make extern David Bremner
2019-09-01  1:37 ` David Bremner [this message]
2019-09-01  1:37 ` [WIP2 3/5] lib: introduce N_F_GROUP and use it to fix implicit AND for from: David Bremner
2019-09-01  1:37 ` [WIP2 4/5] test: add known broken tests for parenthesized subqueries David Bremner
2019-09-01  1:37 ` [WIP2 5/5] lib: special case parenthesized subqueries in regex fields David Bremner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190901013748.7470-3-david@tethera.net \
    --to=david@tethera.net \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).