#!/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 '" add_message "[id]=$1@two [$1]='Bob '" 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" 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" 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" notmuch search --output=messages tag:one tag:two > OUTPUT test_expect_equal_file /dev/null OUTPUT test_begin_subtest "'thread:' 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