blob: 2529bbd74b21c5de7ca788b2de8340ff073c1c02 (
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
|
;;; devbook-mode-tests.el --- tests for devbook-mode.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 'devbook-mode)
(defmacro devbook-mode-test-run-silently (&rest body)
`(let ((inhibit-message t)) ,@body))
(ert-deftest devbook-mode-test-locate-schema ()
(cl-letf* ((rncfile "/home/larry/devmanual/devbook.rnc")
((symbol-function 'file-exists-p)
(lambda (file) (string-equal file rncfile)))
((symbol-function 'file-directory-p)
(lambda (_file) t))
((symbol-function 'insert-file-contents)
(lambda (file &rest _args)
(unless (string-equal file rncfile)
(signal 'file-missing nil))
(insert "start = element foo { empty }\n"))))
(let ((buffer-file-name "/home/larry/devmanual/quickstart/text.xml"))
(devbook-locate-schema-file)
(should (equal rng-current-schema-file-name rncfile)))
(let ((buffer-file-name "/home/larry/elsewhere/text.xml"))
(should (equal
(should-error (devbook-locate-schema-file))
'(error "Schema file devbook.rnc not found"))))))
(ert-deftest devbook-mode-test-skeleton ()
(with-temp-buffer
(cl-letf* ((buffer-file-name "/home/larry/devmanual/quickstart/text.xml")
(testinput '("Quickstart guide"))
(getinput (lambda (&rest _args)
(concat (pop testinput))))
((symbol-function 'read-from-minibuffer) getinput)
((symbol-function 'read-string) getinput))
(devbook-insert-skeleton))
(let ((buf1 (concat "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<guide self=\"quickstart/\">\n"
"<chapter>\n"
"<title>Quickstart guide</title>\n"))
(buf2 (concat "\n"
"</chapter>\n"
"</guide>\n")))
(should (equal (point)
(+ (point-min) (length buf1))))
(should (string-equal (buffer-string)
(concat buf1 buf2))))))
(ert-deftest devbook-mode-test-keybindings ()
(should (equal (lookup-key devbook-mode-map "\C-c\C-n")
'devbook-insert-skeleton))
(with-temp-buffer
(devbook-mode-test-run-silently
(devbook-mode))
(should (equal (local-key-binding "\C-c\C-n")
'devbook-insert-skeleton))))
(provide 'devbook-mode-tests)
;; Local Variables:
;; coding: utf-8
;; End:
;;; devbook-mode-tests.el ends here
|