test/tagging: add tests for exotic tags
[notmuch] / test / tagging
1 #!/usr/bin/env bash
2 test_description='"notmuch tag"'
3 . ./test-lib.sh
4
5 add_message '[subject]=One'
6 add_message '[subject]=Two'
7
8 test_begin_subtest "Adding tags"
9 notmuch tag +tag1 +tag2 +tag3 \*
10 output=$(notmuch search \* | notmuch_search_sanitize)
11 test_expect_equal "$output" "\
12 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; One (inbox tag1 tag2 tag3 unread)
13 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Two (inbox tag1 tag2 tag3 unread)"
14
15 test_begin_subtest "Removing tags"
16 notmuch tag -tag1 -tag2 \*
17 output=$(notmuch search \* | notmuch_search_sanitize)
18 test_expect_equal "$output" "\
19 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; One (inbox tag3 unread)
20 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Two (inbox tag3 unread)"
21
22 test_expect_code 1 "No tag operations" 'notmuch tag One'
23 test_expect_code 1 "No query" 'notmuch tag +tag2'
24
25 test_begin_subtest "Redundant tagging"
26 notmuch tag +tag1 -tag3 One
27 notmuch tag +tag1 -tag3 \*
28 output=$(notmuch search \* | notmuch_search_sanitize)
29 test_expect_equal "$output" "\
30 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; One (inbox tag1 unread)
31 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Two (inbox tag1 unread)"
32
33 test_begin_subtest "Special characters in tags"
34 notmuch tag +':" ' \*
35 notmuch tag -':" ' Two
36 output=$(notmuch search \* | notmuch_search_sanitize)
37 test_expect_equal "$output" "\
38 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; One (:\"  inbox tag1 unread)
39 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Two (inbox tag1 unread)"
40
41 test_begin_subtest "Tagging order"
42 notmuch tag +tag4 -tag4 One
43 notmuch tag -tag4 +tag4 Two
44 output=$(notmuch search \* | notmuch_search_sanitize)
45 test_expect_equal "$output" "\
46 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; One (:\"  inbox tag1 unread)
47 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Two (inbox tag1 tag4 unread)"
48
49 test_begin_subtest "--batch"
50 notmuch tag --batch <<EOF
51 # %20 is a space in tag
52 -:"%20 -tag1 +tag5 +tag6 -- One
53 +tag1 -tag1 -tag4 +tag4 -- Two
54 -tag6 One
55 +tag5 Two
56 EOF
57 output=$(notmuch search \* | notmuch_search_sanitize)
58 test_expect_equal "$output" "\
59 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; One (inbox tag5 unread)
60 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Two (inbox tag4 tag5 unread)"
61
62 # generate a common input file for the next several tests.
63 cat > batch.in  <<EOF
64 # %40 is an @ in tag
65 +%40 -tag5 +tag6 -- One
66 +tag1 -tag1 -tag4 +tag4 -- Two
67 -tag5 +tag6 Two
68 EOF
69
70 cat > batch.expected <<EOF
71 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; One (@ inbox tag6 unread)
72 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Two (inbox tag4 tag6 unread)
73 EOF
74
75 test_begin_subtest "--input"
76 notmuch dump --format=batch-tag > backup.tags
77 notmuch tag --input=batch.in
78 notmuch search \* | notmuch_search_sanitize > OUTPUT
79 notmuch restore --format=batch-tag < backup.tags
80 test_expect_equal_file batch.expected OUTPUT
81
82 test_begin_subtest "--batch --input"
83 notmuch dump --format=batch-tag > backup.tags
84 notmuch tag --batch --input=batch.in
85 notmuch search \* | notmuch_search_sanitize > OUTPUT
86 notmuch restore --format=batch-tag < backup.tags
87 test_expect_equal_file batch.expected OUTPUT
88
89 test_begin_subtest "--batch, blank lines and comments"
90 notmuch dump | sort > EXPECTED
91 notmuch tag --batch <<EOF
92 # this line is a comment; the next has only white space
93          
94
95 # the previous line is empty
96 EOF
97 notmuch dump | sort > OUTPUT
98 test_expect_equal_file EXPECTED OUTPUT
99
100 test_begin_subtest '--batch: checking error messages'
101 notmuch dump --format=batch-tag > BACKUP
102 notmuch tag --batch <<EOF 2>OUTPUT
103 # the next line has a space
104  
105 # this line has no tag operations, but this is permitted in batch format.
106 a
107 +0
108 +a +b
109 # trailing whitespace
110 +a +b 
111 +c +d --
112 # this is a harmless comment, do not yell about it.
113
114 # the previous line was blank; also no yelling please
115 +%zz -- id:whatever
116 # the next non-comment line should report an an empty tag error for
117 # batch tagging, but not for restore
118 + +e -- id:foo
119 +- -- id:foo
120 EOF
121
122 cat <<EOF > EXPECTED
123 Warning: no query string [+0]
124 Warning: no query string [+a +b]
125 Warning: missing query string [+a +b ]
126 Warning: no query string after -- [+c +d --]
127 Warning: hex decoding of tag %zz failed [+%zz -- id:whatever]
128 Warning: empty tag forbidden [+ +e -- id:foo]
129 Warning: tag starting with '-' forbidden [+- -- id:foo]
130 EOF
131
132 notmuch restore --format=batch-tag < BACKUP
133 test_expect_equal_file EXPECTED OUTPUT
134
135 test_begin_subtest '--batch: tags with quotes'
136 notmuch dump --format=batch-tag > BACKUP
137
138 notmuch tag --batch <<EOF
139 +%22%27%22%27%22%22%27%27 -- One
140 -%22%27%22%27%22%22%27%27 -- One
141 +%22%27%22%22%22%27 -- One
142 +%22%27%22%27%22%22%27%27 -- Two
143 EOF
144
145 cat <<EOF > EXPECTED
146 +%22%27%22%22%22%27 +inbox +tag5 +unread -- id:msg-001@notmuch-test-suite
147 +%22%27%22%27%22%22%27%27 +inbox +tag4 +tag5 +unread -- id:msg-002@notmuch-test-suite
148 EOF
149
150 notmuch dump --format=batch-tag | sort > OUTPUT
151 notmuch restore --format=batch-tag < BACKUP
152 test_expect_equal_file EXPECTED OUTPUT
153
154 test_begin_subtest '--batch: tags with punctuation and space'
155 notmuch dump --format=batch-tag > BACKUP
156
157 notmuch tag --batch <<EOF
158 +%21@%23%24%25%5e%26%2a%29-_=+%5b%7b%5c%20%7c%3b%3a%27%20%22,.%3c%60%7e -- One
159 -%21@%23%24%25%5e%26%2a%29-_=+%5b%7b%5c%20%7c%3b%3a%27%20%22,.%3c%60%7e -- One
160 +%21@%23%24%25%5e%26%2a%29-_=+%5b%7b%5c%20%7c%3b%3a%27%20%22,.%3c%20%60%7e -- Two
161 -%21@%23%24%25%5e%26%2a%29-_=+%5b%7b%5c%20%7c%3b%3a%27%20%22,.%3c%20%60%7e -- Two
162 +%21@%23%20%24%25%5e%26%2a%29-_=+%5b%7b%5c%20%7c%3b%3a%27%20%22,.%3c%60%7e -- One
163 +%21@%23%20%24%25%5e%26%2a%29-_=+%5b%7b%5c%20%7c%3b%3a%27%20%22,.%3c%60%7e -- Two
164 EOF
165
166 cat <<EOF > EXPECTED
167 +%21@%23%20%24%25%5e%26%2a%29-_=+%5b%7b%5c%20%7c%3b%3a%27%20%22,.%3c%60%7e +inbox +tag4 +tag5 +unread -- id:msg-002@notmuch-test-suite
168 +%21@%23%20%24%25%5e%26%2a%29-_=+%5b%7b%5c%20%7c%3b%3a%27%20%22,.%3c%60%7e +inbox +tag5 +unread -- id:msg-001@notmuch-test-suite
169 EOF
170
171 notmuch dump --format=batch-tag | sort > OUTPUT
172 notmuch restore --format=batch-tag < BACKUP
173 test_expect_equal_file EXPECTED OUTPUT
174
175 test_begin_subtest '--batch: unicode tags'
176 notmuch dump --format=batch-tag > BACKUP
177
178 notmuch tag --batch <<EOF
179 +%2a@%7d%cf%b5%f4%85%80%adO3%da%a7 -- One
180 +=%e0%ac%95%c8%b3+%ef%aa%95%c8%a64w%c7%9d%c9%a2%cf%b3%d6%82%24B%c4%a9%c5%a1UX%ee%99%b0%27E7%ca%a4%d0%8b%5d -- One
181 +A%e1%a0%bc%de%8b%d5%b2V%d9%9b%f3%b5%a2%a3M%d8%a1u@%f0%a0%ac%948%7e%f0%ab%86%af%27 -- One
182 +R -- One
183 +%da%88=f%cc%b9I%ce%af%7b%c9%97%e3%b9%8bH%cb%92X%d2%8c6 -- One
184 +%dc%9crh%d2%86B%e5%97%a2%22t%ed%99%82d -- One
185 +L%df%85%ef%a1%a5m@%d3%96%c2%ab%d4%9f%ca%b8%f3%b3%a2%bf%c7%b1_u%d7%b4%c7%b1 -- One
186 +P%c4%98%2f -- One
187 +%7e%d1%8b%25%ec%a0%ae%d1%a0M%3b%e3%b6%b7%e9%a4%87%3c%db%9a%cc%a8%e1%96%9d -- One
188 +%c4%bf7%c7%ab9H%c4%99k%ea%91%bd%c3%8ck%e2%b3%8dk%c5%952V%e4%99%b2%d9%b3%e4%8b%bda%5b%24%c7%9b -- One
189 +%2a@%7d%cf%b5%f4%85%80%adO3%da%a7  +=%e0%ac%95%c8%b3+%ef%aa%95%c8%a64w%c7%9d%c9%a2%cf%b3%d6%82%24B%c4%a9%c5%a1UX%ee%99%b0%27E7%ca%a4%d0%8b%5d  +A%e1%a0%bc%de%8b%d5%b2V%d9%9b%f3%b5%a2%a3M%d8%a1u@%f0%a0%ac%948%7e%f0%ab%86%af%27  +R  +%da%88=f%cc%b9I%ce%af%7b%c9%97%e3%b9%8bH%cb%92X%d2%8c6  +%dc%9crh%d2%86B%e5%97%a2%22t%ed%99%82d  +L%df%85%ef%a1%a5m@%d3%96%c2%ab%d4%9f%ca%b8%f3%b3%a2%bf%c7%b1_u%d7%b4%c7%b1  +P%c4%98%2f  +%7e%d1%8b%25%ec%a0%ae%d1%a0M%3b%e3%b6%b7%e9%a4%87%3c%db%9a%cc%a8%e1%96%9d  +%c4%bf7%c7%ab9H%c4%99k%ea%91%bd%c3%8ck%e2%b3%8dk%c5%952V%e4%99%b2%d9%b3%e4%8b%bda%5b%24%c7%9b -- Two
190 EOF
191
192 cat <<EOF > EXPECTED
193 +%2a@%7d%cf%b5%f4%85%80%adO3%da%a7 +=%e0%ac%95%c8%b3+%ef%aa%95%c8%a64w%c7%9d%c9%a2%cf%b3%d6%82%24B%c4%a9%c5%a1UX%ee%99%b0%27E7%ca%a4%d0%8b%5d +A%e1%a0%bc%de%8b%d5%b2V%d9%9b%f3%b5%a2%a3M%d8%a1u@%f0%a0%ac%948%7e%f0%ab%86%af%27 +L%df%85%ef%a1%a5m@%d3%96%c2%ab%d4%9f%ca%b8%f3%b3%a2%bf%c7%b1_u%d7%b4%c7%b1 +P%c4%98%2f +R +inbox +tag4 +tag5 +unread +%7e%d1%8b%25%ec%a0%ae%d1%a0M%3b%e3%b6%b7%e9%a4%87%3c%db%9a%cc%a8%e1%96%9d +%c4%bf7%c7%ab9H%c4%99k%ea%91%bd%c3%8ck%e2%b3%8dk%c5%952V%e4%99%b2%d9%b3%e4%8b%bda%5b%24%c7%9b +%da%88=f%cc%b9I%ce%af%7b%c9%97%e3%b9%8bH%cb%92X%d2%8c6 +%dc%9crh%d2%86B%e5%97%a2%22t%ed%99%82d -- id:msg-002@notmuch-test-suite
194 +%2a@%7d%cf%b5%f4%85%80%adO3%da%a7 +=%e0%ac%95%c8%b3+%ef%aa%95%c8%a64w%c7%9d%c9%a2%cf%b3%d6%82%24B%c4%a9%c5%a1UX%ee%99%b0%27E7%ca%a4%d0%8b%5d +A%e1%a0%bc%de%8b%d5%b2V%d9%9b%f3%b5%a2%a3M%d8%a1u@%f0%a0%ac%948%7e%f0%ab%86%af%27 +L%df%85%ef%a1%a5m@%d3%96%c2%ab%d4%9f%ca%b8%f3%b3%a2%bf%c7%b1_u%d7%b4%c7%b1 +P%c4%98%2f +R +inbox +tag5 +unread +%7e%d1%8b%25%ec%a0%ae%d1%a0M%3b%e3%b6%b7%e9%a4%87%3c%db%9a%cc%a8%e1%96%9d +%c4%bf7%c7%ab9H%c4%99k%ea%91%bd%c3%8ck%e2%b3%8dk%c5%952V%e4%99%b2%d9%b3%e4%8b%bda%5b%24%c7%9b +%da%88=f%cc%b9I%ce%af%7b%c9%97%e3%b9%8bH%cb%92X%d2%8c6 +%dc%9crh%d2%86B%e5%97%a2%22t%ed%99%82d -- id:msg-001@notmuch-test-suite
195 EOF
196
197 notmuch dump --format=batch-tag | sort > OUTPUT
198 notmuch restore --format=batch-tag < BACKUP
199 test_expect_equal_file EXPECTED OUTPUT
200
201 test_expect_code 1 "Empty tag names" 'notmuch tag + One'
202
203 test_expect_code 1 "Tag name beginning with -" 'notmuch tag +- One'
204
205 test_done