File: emacs-subject-warnings.el

package info (click to toggle)
notmuch 0.39-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,104 kB
  • sloc: sh: 21,888; ansic: 14,897; lisp: 9,061; cpp: 7,990; python: 6,221; perl: 391; makefile: 231; javascript: 34; ruby: 13
file content (48 lines) | stat: -rw-r--r-- 1,373 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
(require 'cl-lib)
(require 'notmuch-mua)

(defun subject-check-test (&optional fn)
  "Test `notmuch-mua-subject-check'.
Optionally, evaluate FN before doing the test.

Return t if the message would be sent, and nil otherwise."
  (notmuch-mua-mail)
  (message-goto-subject)
  (when fn
    (funcall fn))
  (prog1
      (condition-case nil
	  ;; Force `y-or-n-p' to always return `nil', as if the user
	  ;; pressed "n".
	  (cl-letf (((symbol-function 'y-or-n-p)
		     (lambda (&rest args) nil)))
	    (notmuch-mua-subject-check)
	    t)
	('error nil))
    (set-buffer-modified-p nil)
    (kill-buffer (current-buffer))))

(defvar subject-check-tests
  '(;; These are okay.
    (t . (lambda () (insert "something")))
    ;; These should not be okay.
    (nil)
    (nil . (lambda () (insert "         ")))
    (nil . (lambda () (insert "		  	")))
    (nil . (lambda () (insert " ")))	; NON-BREAKING SPACE
    ))

(defun notmuch-test-subject-warning-1 ()
  (let (output expected)
    (dolist (test subject-check-tests)
      (let* ((expect (car test))
	     (body (cdr test))
	     (result (subject-check-test body)))
	(push expect expected)
	(push (if (eq result expect)
		  result
		;; In the case of a failure, include the test
		;; details to make it simpler to debug.
		(format "%S <-- %S" result body))
	      output)))
    (notmuch-test-expect-equal output expected)))