1 ;;; sgml-mode-tests.el --- Tests for sgml-mode
3 ;; Copyright (C) 2015 Free Software Foundation, Inc.
5 ;; Author: Przemysław Wojnowski <esperanto@cumego.com>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
30 (defmacro sgml-with-content
(content &rest body
)
31 "Insert CONTENT into a temporary `sgml-mode' buffer and execute BODY on it.
32 The point is set to the beginning of the buffer."
36 (goto-char (point-min))
41 (ert-deftest sgml-delete-tag-should-not-delete-tags-when-wrong-args
()
42 "Don't delete tag, when number of tags to delete is not positive number."
43 (let ((content "<p>Valar Morghulis</p>"))
47 (should (string= content
(buffer-string)))
49 (should (string= content
(buffer-string))))))
51 (ert-deftest sgml-delete-tag-should-delete-tags-n-times
()
52 ;; Delete only 1, when 1 available:
56 (should (string= "" (buffer-string))))
57 ;; Delete from position on whitespaces before tag:
61 (should (string= "" (buffer-string))))
62 ;; Delete from position on tag:
67 (should (string= "" (buffer-string))))
70 "<h1><p>You know nothing, Jon Snow.</p></h1>"
72 (should (string= "<p>You know nothing, Jon Snow.</p>" (buffer-string)))
74 (should (string= "You know nothing, Jon Snow." (buffer-string))))
75 ;; Delete 2 at a time, when 2 available:
77 "<h1><p>You know nothing, Jon Snow.</p></h1>"
79 (should (string= "You know nothing, Jon Snow." (buffer-string)))))
81 (ert-deftest sgml-delete-tag-should-delete-unclosed-tag
()
83 "<ul><li>Keep your stones connected.</ul>"
84 (goto-char 5) ; position on "li" tag
86 (should (string= "<ul>Keep your stones connected.</ul>" (buffer-string)))))
88 (ert-deftest sgml-delete-tag-should-signal-error-for-malformed-tags
()
89 (let ((content "<h1><h2>Drakaris!</h1></h2>"))
90 ;; Delete outside tag:
94 (should (string= "<h2>Drakaris!</h2>" (buffer-string))))
98 (goto-char 5) ; position the inner tag
100 (should (string= "<h1>Drakaris!</h1>" (buffer-string))))))
102 (ert-deftest sgml-delete-tag-should-signal-error-when-deleting-too-much
()
103 (let ((content "<emph>Drakaris!</emph>"))
104 ;; No tags to delete:
107 (should-error (sgml-delete-tag 1) :type
'error
)
108 (should (string= "Drakaris!" (buffer-string))))
109 ;; Trying to delete 2 tags, when only 1 available:
112 (should-error (sgml-delete-tag 2) :type
'error
)
113 (should (string= "Drakaris!" (buffer-string))))
114 ;; Trying to delete a tag, but not on/before a tag:
117 (goto-char 7) ; D in Drakaris
118 (should-error (sgml-delete-tag 1) :type
'error
)
119 (should (string= content
(buffer-string))))
120 ;; Trying to delete a tag from position outside tag:
123 (goto-char (point-max))
124 (should-error (sgml-delete-tag 1) :type
'error
)
125 (should (string= content
(buffer-string))))))
127 (ert-deftest sgml-delete-tag-bug-8203-should-not-delete-apostrophe
()
128 :expected-result
:failed
130 "<title>Winter is comin'</title>"
132 (should (string= "Winter is comin'" (buffer-string)))))
134 (provide 'sgml-mode-tests
)
135 ;;; sgml-mode-tests.el ends here