]> git.notmuchmail.org Git - notmuch/blob - test/T330-emacs-subject-to-filename.sh
lib/database: delete stemmer on destroy
[notmuch] / test / T330-emacs-subject-to-filename.sh
1 #!/usr/bin/env bash
2
3 test_description="emacs: mail subject to filename"
4 . $(dirname "$0")/test-lib.sh || exit 1
5 . $NOTMUCH_SRCDIR/test/test-lib-emacs.sh || exit 1
6
7 test_require_emacs
8
9 # emacs server can't be started in a child process with $(test_emacs ...)
10 test_emacs '(ignore)' > /dev/null
11
12 # test notmuch-wash-subject-to-patch-sequence-number (subject)
13 test_begin_subtest "no patch sequence number"
14 output=$(test_emacs '(format "%S" (notmuch-wash-subject-to-patch-sequence-number
15       "[PATCH] A normal patch subject without numbers"))'
16 )
17 test_expect_equal "$output" '"nil"'
18
19 test_begin_subtest "patch sequence number #1"
20 output=$(test_emacs '(notmuch-wash-subject-to-patch-sequence-number
21       "[PATCH 2/3] A most regular patch subject")'
22 )
23 test_expect_equal "$output" 2
24
25 test_begin_subtest "patch sequence number #2"
26 output=$(test_emacs '(notmuch-wash-subject-to-patch-sequence-number
27       "  [dummy list prefix]  [RFC PATCH v2 13/42]  Special prefixes")'
28 )
29 test_expect_equal "$output" 13
30
31 test_begin_subtest "patch sequence number #3"
32 output=$(test_emacs '(notmuch-wash-subject-to-patch-sequence-number
33       "[PATCH 2/3] [PATCH 032/037] use the last prefix")'
34 )
35 test_expect_equal "$output" 32
36
37 test_begin_subtest "patch sequence number #4"
38 output=$(test_emacs '(notmuch-wash-subject-to-patch-sequence-number
39       "[dummy list prefix] [PATCH 2/3] PATCH 3/3] do not use a broken prefix")'
40 )
41 test_expect_equal "$output" 2
42
43 test_begin_subtest "patch sequence number #5"
44 output=$(test_emacs '(notmuch-wash-subject-to-patch-sequence-number
45       "[RFC][PATCH 3/5][PATCH 4/5][PATCH 5/5] A made up test")'
46 )
47 test_expect_equal "$output" 5
48
49 test_begin_subtest "patch sequence number #6"
50 output=$(test_emacs '(notmuch-wash-subject-to-patch-sequence-number
51       "[PATCH 2/3] this -> [PATCH 3/3] is not a prefix anymore [nor this 4/4]")'
52 )
53 test_expect_equal "$output" 2
54
55 test_begin_subtest "patch sequence number #7"
56 output=$(test_emacs '(notmuch-wash-subject-to-patch-sequence-number
57       "[liberally accept crapola right before123/456and after] the numbers")'
58 )
59 test_expect_equal "$output" 123
60
61 # test notmuch-wash-subject-to-filename (subject &optional maxlen)
62 test_begin_subtest "filename #1"
63 output=$(test_emacs '(notmuch-wash-subject-to-filename
64       "just a subject line")'
65 )
66 test_expect_equal "$output" '"just-a-subject-line"'
67
68 test_begin_subtest "filename #2"
69 output=$(test_emacs '(notmuch-wash-subject-to-filename
70       " [any]  [prefixes are ] [removed!] from the subject")'
71 )
72 test_expect_equal "$output" '"from-the-subject"'
73
74 test_begin_subtest "filename #3"
75 output=$(test_emacs '(notmuch-wash-subject-to-filename
76       "  leading and trailing space  ")'
77 )
78 test_expect_equal "$output" '"leading-and-trailing-space"'
79
80 test_begin_subtest "filename #4"
81 output=$(test_emacs '(notmuch-wash-subject-to-filename
82       "!#  leading ()// &%, and in between_and_trailing garbage ()(&%%")'
83 )
84 test_expect_equal "$output" '"-leading-and-in-between_and_trailing-garbage"'
85
86 test_begin_subtest "filename #5"
87 output=$(test_emacs '(notmuch-wash-subject-to-filename
88       "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-_01234567890")'
89 )
90 test_expect_equal "$output" '"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-_01234567890"'
91
92 test_begin_subtest "filename #6"
93 output=$(test_emacs '(notmuch-wash-subject-to-filename
94       "sequences of ... are squashed and trailing are removed ...")'
95 )
96 test_expect_equal "$output" '"sequences-of-.-are-squashed-and-trailing-are-removed"'
97
98 test_begin_subtest "filename #7"
99 output=$(test_emacs '(notmuch-wash-subject-to-filename
100       "max length test" 1)'
101 )
102 test_expect_equal "$output" '"m"'
103
104 test_begin_subtest "filename #8"
105 output=$(test_emacs '(notmuch-wash-subject-to-filename
106       "max length test /&(/%&/%%&¤%¤" 20)'
107 )
108 test_expect_equal "$output" '"max-length-test"'
109
110 test_begin_subtest "filename #9"
111 output=$(test_emacs '(notmuch-wash-subject-to-filename
112       "[a prefix] [is only separated] by [spaces], so \"by\" is not okay!")'
113 )
114 test_expect_equal "$output" '"by-spaces-so-by-is-not-okay"'
115
116 # test notmuch-wash-subject-to-patch-filename (subject)
117 test_begin_subtest "patch filename #1"
118 output=$(test_emacs '(notmuch-wash-subject-to-patch-filename
119       "[RFC][PATCH 099/100] rewrite notmuch")'
120 )
121 test_expect_equal "$output" '"0099-rewrite-notmuch.patch"'
122
123 test_begin_subtest "patch filename #2"
124 output=$(test_emacs '(notmuch-wash-subject-to-patch-filename
125       "[RFC PATCH v1] has no patch number, default to 1")'
126 )
127 test_expect_equal "$output" '"0001-has-no-patch-number-default-to-1.patch"'
128
129 test_begin_subtest "patch filename #3"
130 output=$(test_emacs '(notmuch-wash-subject-to-patch-filename
131       "[PATCH 4/5] the maximum length of a patch filename is 52 + patch sequence number + .patch extension")'
132 )
133 test_expect_equal "$output" '"0004-the-maximum-length-of-a-patch-filename-is-52-patch-s.patch"'
134
135 test_begin_subtest "patch filename #4"
136 output=$(test_emacs '(notmuch-wash-subject-to-patch-filename
137       "[PATCH 4/5] the maximum length of a patch filename is 52 + patchh ! sequence number + .patch extension, *before* trimming trailing - and .")'
138 )
139 test_expect_equal "$output" '"0004-the-maximum-length-of-a-patch-filename-is-52-patchh.patch"'
140
141 test_done