lib: only trigger phrase processing for regexp fields when needed
[notmuch] / test / T650-regexp-query.sh
1 #!/usr/bin/env bash
2 test_description='regular expression searches'
3 . ./test-lib.sh || exit 1
4
5 add_email_corpus
6
7
8 if [ $NOTMUCH_HAVE_XAPIAN_FIELD_PROCESSOR -eq 0 ]; then
9     test_done
10 fi
11
12 notmuch search --output=messages from:cworth > cworth.msg-ids
13
14 test_begin_subtest "xapian wildcard search for from:"
15 notmuch search --output=messages 'from:cwo*' > OUTPUT
16 test_expect_equal_file cworth.msg-ids OUTPUT
17
18 test_begin_subtest "xapian wildcard search for subject:"
19 test_expect_equal $(notmuch count 'subject:count*') 1
20
21 test_begin_subtest "regexp from search, case sensitive"
22 notmuch search --output=messages from:/carl/ > OUTPUT
23 test_expect_equal_file /dev/null OUTPUT
24
25 test_begin_subtest "empty regexp or query"
26 notmuch search --output=messages from:/carl/ or from:/cworth/ > OUTPUT
27 test_expect_equal_file cworth.msg-ids OUTPUT
28
29 test_begin_subtest "non-empty regexp and query"
30 notmuch search  from:/cworth@cworth.org/ and subject:patch | notmuch_search_sanitize > OUTPUT
31 cat <<EOF > EXPECTED
32 thread:XXX   2009-11-18 [1/2] Carl Worth| Alex Botero-Lowry; [notmuch] [PATCH] Error out if no query is supplied to search instead of going into an infinite loop (attachment inbox unread)
33 thread:XXX   2009-11-18 [1/2] Carl Worth| Ingmar Vanhassel; [notmuch] [PATCH] Typsos (inbox unread)
34 thread:XXX   2009-11-18 [1/2] Carl Worth| Jan Janak; [notmuch] [PATCH] Older versions of install do not support -C. (inbox unread)
35 thread:XXX   2009-11-18 [1/2] Carl Worth| Keith Packard; [notmuch] [PATCH] Make notmuch-show 'X' (and 'x') commands remove inbox (and unread) tags (inbox unread)
36 thread:XXX   2009-11-18 [2/5] Carl Worth| Mikhail Gusarov, Keith Packard; [notmuch] [PATCH 1/2] Close message file after parsing message headers (inbox unread)
37 EOF
38 test_expect_equal_file EXPECTED OUTPUT
39
40 test_begin_subtest "regexp from search, duplicate term search"
41 notmuch search --output=messages from:/cworth/ > OUTPUT
42 test_expect_equal_file cworth.msg-ids OUTPUT
43
44 test_begin_subtest "long enough regexp matches only desired senders"
45 notmuch search --output=messages 'from:"/C.* Wo/"' > OUTPUT
46 test_expect_equal_file cworth.msg-ids OUTPUT
47
48 test_begin_subtest "shorter regexp matches one more sender"
49 notmuch search --output=messages 'from:"/C.* W/"' > OUTPUT
50 { echo id:1258544095-16616-1-git-send-email-chris@chris-wilson.co.uk; cat cworth.msg-ids; } > EXPECTED
51 test_expect_equal_file EXPECTED OUTPUT
52
53 test_begin_subtest "regexp subject search, non-ASCII"
54 notmuch search --output=messages subject:/accentuĂ©/ > OUTPUT
55 echo id:877h1wv7mg.fsf@inf-8657.int-evry.fr > EXPECTED
56 test_expect_equal_file EXPECTED OUTPUT
57
58 test_begin_subtest "regexp subject search, punctuation"
59 notmuch search subject:/\'X\'/ | notmuch_search_sanitize > OUTPUT
60 cat <<EOF > EXPECTED
61 thread:XXX   2009-11-18 [2/2] Keith Packard, Carl Worth; [notmuch] [PATCH] Make notmuch-show 'X' (and 'x') commands remove inbox (and unread) tags (inbox unread)
62 EOF
63 test_expect_equal_file EXPECTED OUTPUT
64
65 test_begin_subtest "regexp subject search, no punctuation"
66 notmuch search  subject:/X/ | notmuch_search_sanitize > OUTPUT
67 cat <<EOF > EXPECTED
68 thread:XXX   2009-11-18 [2/2] Keith Packard, Carl Worth; [notmuch] [PATCH] Make notmuch-show 'X' (and 'x') commands remove inbox (and unread) tags (inbox unread)
69 thread:XXX   2009-11-18 [4/4] Jjgod Jiang, Alexander Botero-Lowry; [notmuch] Mac OS X/Darwin compatibility issues (inbox unread)
70 EOF
71 test_expect_equal_file EXPECTED OUTPUT
72
73 test_begin_subtest "combine regexp from and subject"
74 notmuch search  subject:/-C/ and from:/.an.k/ | notmuch_search_sanitize > OUTPUT
75 cat <<EOF > EXPECTED
76 thread:XXX   2009-11-17 [1/2] Jan Janak| Carl Worth; [notmuch] [PATCH] Older versions of install do not support -C. (inbox unread)
77 EOF
78 test_expect_equal_file EXPECTED OUTPUT
79
80 test_begin_subtest "regexp error reporting"
81 notmuch search 'from:/unbalanced[/' 1>OUTPUT 2>&1
82 cat <<EOF > EXPECTED
83 notmuch search: A Xapian exception occurred
84 A Xapian exception occurred parsing query: Invalid regular expression
85 Query string was: from:/unbalanced[/
86 EOF
87 test_expect_equal_file EXPECTED OUTPUT
88
89 test_done