[WIP2 2/5] test: add known broken tests for implicit operators

Subject:[WIP2 2/5] test: add known broken tests for implicit operators

Date:Sat, 31 Aug 2019 22:37:45 -0300

To:notmuch@notmuchmail.org

Cc:

From:David Bremner


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

_______________________________________________
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch

Thread: