summaryrefslogtreecommitdiff
blob: b1363bd08a16860801e7262ac3cc5c499855cc42 (plain)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
;;; gentoo-newsitem-mode-tests.el  -*-lexical-binding:t-*-

;; Copyright 2024 Gentoo Authors

;; Author: Ulrich Müller <ulm@gentoo.org>
;; Maintainer: <emacs@gentoo.org>

;; This file is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 2 of the License, or
;; (at your option) any later version.

;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.

;;; Code:

(require 'ert)
(require 'gentoo-newsitem-mode)

(eval-when-compile
  (unless (fboundp 'cl-letf)
    (defalias 'cl-letf  #'letf)
    (defalias 'cl-letf* #'letf*)))

(defvar gentoo-newsitem-mode-test-input nil)

(defun gentoo-newsitem-mode-test-input (&rest _args)
  (concat (pop gentoo-newsitem-mode-test-input)))

(ert-deftest gentoo-newsitem-mode-test-font-lock ()
  (with-temp-buffer
    (gentoo-newsitem-mode)
    (insert "Author: Larry the Cow\n")
    (if (fboundp 'font-lock-ensure)
	(font-lock-ensure)
      (font-lock-fontify-region (point-min) (point-max)))
    (goto-char (point-min))
    (search-forward "Author")
    (should (equal (get-text-property (match-beginning 0) 'face)
		   'font-lock-keyword-face))
    (search-forward "Larry")
    (should-not (get-text-property (match-beginning 0) 'face))))

(ert-deftest gentoo-newsitem-mode-test-skeleton ()
  (with-temp-buffer
    (cl-letf (((symbol-function 'read-from-minibuffer)
	       #'gentoo-newsitem-mode-test-input)
	      ((symbol-function 'read-string)
	       #'gentoo-newsitem-mode-test-input))
      (setq gentoo-newsitem-mode-test-input
	    '("Skeleton test"		; Title
	      "Larry the Cow <larry@example.org>" "" ; Author
	      ""			; Translator
	      "2024-08-10"		; Posted
	      ""			; News-Item-Format
	      ""			; Display-If-Installed
	      ""			; Display-If-Keyword
	      ""))			; Display-If-Profile
      (if (featurep 'xemacs)
	  ;; prevent a segfault (seen with XEmacs 21.4.24 and 21.5.35)
	  (cl-letf (((symbol-function 'pos-visible-in-window-p)
		     (lambda (&rest _args) t)))
	    (gentoo-newsitem-insert-skeleton))
	(gentoo-newsitem-insert-skeleton))
      (should (string-equal
	       (buffer-string)
	       (concat "Title: Skeleton test\n"
		       "Author: Larry the Cow <larry@example.org>\n"
		       "Posted: 2024-08-10\n"
		       "Revision: 1\n"
		       "News-Item-Format: 2.0\n\n"))))))

(ert-deftest gentoo-newsitem-mode-test-keybindings ()
  (should (equal (lookup-key gentoo-newsitem-mode-map "\C-c\C-n")
		 'gentoo-newsitem-insert-skeleton))
  (with-temp-buffer
    (gentoo-newsitem-mode)
    (should (equal (local-key-binding "\C-c\C-n")
		   'gentoo-newsitem-insert-skeleton))))

(provide 'gentoo-newsitem-mode-tests)

;; Local Variables:
;; coding: utf-8
;; End:

;;; gentoo-newsitem-mode-tests.el ends here