Undo removal of x_clear_area call on expose for GTK3 or cairo.
[emacs.git] / test / automated / sgml-mode-tests.el
blobeeb5c7d60ae999edf81e374edc2864704f08d39f
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>
6 ;; Keywords: tests
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/>.
23 ;;; Commentary:
25 ;;; Code:
27 (require 'sgml-mode)
28 (require 'ert)
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."
33 `(with-temp-buffer
34 (sgml-mode)
35 (insert ,content)
36 (goto-char (point-min))
37 ,@body))
39 ;;; sgml-delete-tag
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>"))
44 (sgml-with-content
45 content
46 (sgml-delete-tag -1)
47 (should (string= content (buffer-string)))
48 (sgml-delete-tag 0)
49 (should (string= content (buffer-string))))))
51 (ert-deftest sgml-delete-tag-should-delete-tags-n-times ()
52 ;; Delete only 1, when 1 available:
53 (sgml-with-content
54 "<br />"
55 (sgml-delete-tag 1)
56 (should (string= "" (buffer-string))))
57 ;; Delete from position on whitespaces before tag:
58 (sgml-with-content
59 " \t\n<br />"
60 (sgml-delete-tag 1)
61 (should (string= "" (buffer-string))))
62 ;; Delete from position on tag:
63 (sgml-with-content
64 "<br />"
65 (goto-char 3)
66 (sgml-delete-tag 1)
67 (should (string= "" (buffer-string))))
68 ;; Delete one by one:
69 (sgml-with-content
70 "<h1><p>You know nothing, Jon Snow.</p></h1>"
71 (sgml-delete-tag 1)
72 (should (string= "<p>You know nothing, Jon Snow.</p>" (buffer-string)))
73 (sgml-delete-tag 1)
74 (should (string= "You know nothing, Jon Snow." (buffer-string))))
75 ;; Delete 2 at a time, when 2 available:
76 (sgml-with-content
77 "<h1><p>You know nothing, Jon Snow.</p></h1>"
78 (sgml-delete-tag 2)
79 (should (string= "You know nothing, Jon Snow." (buffer-string)))))
81 (ert-deftest sgml-delete-tag-should-delete-unclosed-tag ()
82 (sgml-with-content
83 "<ul><li>Keep your stones connected.</ul>"
84 (goto-char 5) ; position on "li" tag
85 (sgml-delete-tag 1)
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:
91 (sgml-with-content
92 content
93 (sgml-delete-tag 1)
94 (should (string= "<h2>Drakaris!</h2>" (buffer-string))))
95 ;; Delete inner tag:
96 (sgml-with-content
97 content
98 (goto-char 5) ; position the inner tag
99 (sgml-delete-tag 1)
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:
105 (sgml-with-content
106 "Drakaris!"
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:
110 (sgml-with-content
111 content
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:
115 (sgml-with-content
116 content
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:
121 (sgml-with-content
122 content
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
129 (sgml-with-content
130 "<title>Winter is comin'</title>"
131 (sgml-delete-tag 1)
132 (should (string= "Winter is comin'" (buffer-string)))))
134 (provide 'sgml-mode-tests)
135 ;;; sgml-mode-tests.el ends here