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