#!/usr/bin/env bash test_description='"notmuch search" in several variations' . $(dirname "$0")/test-lib.sh || exit 1 add_email_corpus for query in '()' '(not)' '(and)' '(or ())' '(or (not))' '(or (and))' \ '(or (and) (or) (not (and)))'; do test_begin_subtest "all messages: $query" notmuch search '*' > EXPECTED notmuch search --query-syntax=sexp "$query" > OUTPUT test_expect_equal_file EXPECTED OUTPUT done for query in '(or)' '(not ())' '(not (not))' '(not (and))' \ '(not (or (and) (or) (not (and))))'; do test_begin_subtest "no messages: $query" notmuch search --query-syntax=sexp "$query" > OUTPUT test_expect_equal_file /dev/null OUTPUT done test_begin_subtest "Search by subject" add_message [subject]=subjectsearchtest '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' output=$(notmuch search --query-syntax=sexp '(subject subjectsearchtest)' | notmuch_search_sanitize) test_expect_equal "$output" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; subjectsearchtest (inbox unread)" test_begin_subtest "Search by subject (case insensitive)" notmuch search tag:inbox and subject:maildir | notmuch_search_sanitize > EXPECTED notmuch search --query-syntax=sexp '(subject Maildir)' | notmuch_search_sanitize > OUTPUT test_expect_equal_file EXPECTED OUTPUT test_begin_subtest "Search by subject (utf-8):" add_message [subject]=utf8-sübjéct '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' output=$(notmuch search --query-syntax=sexp '(subject utf8 sübjéct)' | notmuch_search_sanitize) test_expect_equal "$output" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; utf8-sübjéct (inbox unread)" test_begin_subtest "Search by 'subject' (utf-8, phrase-token):" output=$(notmuch search --query-syntax=sexp '(subject utf8-sübjéct)' | notmuch_search_sanitize) test_expect_equal "$output" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; utf8-sübjéct (inbox unread)" test_begin_subtest "Search by 'subject' (utf-8, quoted string):" output=$(notmuch search --query-syntax=sexp '(subject "utf8 sübjéct")' | notmuch_search_sanitize) test_expect_equal "$output" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; utf8-sübjéct (inbox unread)" test_done