diff options
Diffstat (limited to 'test')
6 files changed, 488 insertions, 0 deletions
diff --git a/test/lisp/emacs-lisp/faceup-resources/faceup-test-mode.el b/test/lisp/emacs-lisp/faceup-resources/faceup-test-mode.el new file mode 100644 index 00000000000..ec2cf272368 --- /dev/null +++ b/test/lisp/emacs-lisp/faceup-resources/faceup-test-mode.el | |||
| @@ -0,0 +1,76 @@ | |||
| 1 | ;;; faceup-test-mode.el --- Dummy major mode for testing `faceup'. | ||
| 2 | |||
| 3 | ;; Copyright (C) 2014-2017 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; Author: Anders Lindgren | ||
| 6 | ;; Keywords: languages, faces | ||
| 7 | |||
| 8 | ;; This file is part of GNU Emacs. | ||
| 9 | |||
| 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. | ||
| 14 | |||
| 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. | ||
| 19 | |||
| 20 | ;; You should have received a copy of the GNU General Public License | ||
| 21 | ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. | ||
| 22 | |||
| 23 | ;;; Commentary: | ||
| 24 | |||
| 25 | ;; Dummy major-mode for testing `faceup', a regression test system for | ||
| 26 | ;; font-lock keywords (syntax highlighting rules for Emacs). | ||
| 27 | ;; | ||
| 28 | ;; This mode use `syntax-propertize' to set the `syntax-table' | ||
| 29 | ;; property on "<" and ">" in "<TEXT>" to make them act like | ||
| 30 | ;; parentheses. | ||
| 31 | ;; | ||
| 32 | ;; This mode also sets the `help-echo' property on the text WARNING, | ||
| 33 | ;; the effect is that Emacs displays a tooltip when you move your | ||
| 34 | ;; mouse on to the text. | ||
| 35 | |||
| 36 | ;;; Code: | ||
| 37 | |||
| 38 | (defvar faceup-test-mode-syntax-table | ||
| 39 | (make-syntax-table) | ||
| 40 | "Syntax table for `faceup-test-mode'.") | ||
| 41 | |||
| 42 | (defvar faceup-test-font-lock-keywords | ||
| 43 | '(("\\_<WARNING\\_>" | ||
| 44 | (0 (progn | ||
| 45 | (add-text-properties (match-beginning 0) | ||
| 46 | (match-end 0) | ||
| 47 | '(help-echo "Baloon tip: Fly smoothly!")) | ||
| 48 | font-lock-warning-face)))) | ||
| 49 | "Highlight rules for `faceup-test-mode'.") | ||
| 50 | |||
| 51 | (defun faceup-test-syntax-propertize (start end) | ||
| 52 | (goto-char start) | ||
| 53 | (funcall | ||
| 54 | (syntax-propertize-rules | ||
| 55 | ("\\(<\\)\\([^<>\n]*\\)\\(>\\)" | ||
| 56 | (1 "() ") | ||
| 57 | (3 ")( "))) | ||
| 58 | start end)) | ||
| 59 | |||
| 60 | (defmacro faceup-test-define-prog-mode (mode name &rest args) | ||
| 61 | "Define a major mode for a programming language. | ||
| 62 | If `prog-mode' is defined, inherit from it." | ||
| 63 | (declare (indent defun)) | ||
| 64 | `(define-derived-mode | ||
| 65 | ,mode ,(and (fboundp 'prog-mode) 'prog-mode) | ||
| 66 | ,name ,@args)) | ||
| 67 | |||
| 68 | (faceup-test-define-prog-mode faceup-test-mode "faceup-test" | ||
| 69 | "Dummy major mode for testing `faceup', a test system for font-lock." | ||
| 70 | (set (make-local-variable 'syntax-propertize-function) | ||
| 71 | #'faceup-test-syntax-propertize) | ||
| 72 | (setq font-lock-defaults '(faceup-test-font-lock-keywords nil))) | ||
| 73 | |||
| 74 | (provide 'faceup-test-mode) | ||
| 75 | |||
| 76 | ;;; faceup-test-mode.el ends here | ||
diff --git a/test/lisp/emacs-lisp/faceup-resources/faceup-test-this-file-directory.el b/test/lisp/emacs-lisp/faceup-resources/faceup-test-this-file-directory.el new file mode 100644 index 00000000000..e9d8b7074c2 --- /dev/null +++ b/test/lisp/emacs-lisp/faceup-resources/faceup-test-this-file-directory.el | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | ;;; faceup-test-this-file-directory.el --- Support file for faceup tests | ||
| 2 | |||
| 3 | ;; Copyright (C) 2014-2017 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; Author: Anders Lindgren | ||
| 6 | ;; Keywords: languages, faces | ||
| 7 | |||
| 8 | ;; This file is part of GNU Emacs. | ||
| 9 | |||
| 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. | ||
| 14 | |||
| 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. | ||
| 19 | |||
| 20 | ;; You should have received a copy of the GNU General Public License | ||
| 21 | ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. | ||
| 22 | |||
| 23 | ;;; Commentary: | ||
| 24 | |||
| 25 | ;; Support file for `faceup-test-basics.el'. This file is used to test | ||
| 26 | ;; `faceup-this-file-directory' in various contexts. | ||
| 27 | |||
| 28 | ;;; Code: | ||
| 29 | |||
| 30 | (defvar faceup-test-this-file-directory (faceup-this-file-directory)) | ||
| 31 | |||
| 32 | ;;; faceup-test-this-file-directory.el ends here | ||
diff --git a/test/lisp/emacs-lisp/faceup-resources/files/test1.txt b/test/lisp/emacs-lisp/faceup-resources/files/test1.txt new file mode 100644 index 00000000000..d971f364c2d --- /dev/null +++ b/test/lisp/emacs-lisp/faceup-resources/files/test1.txt | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | This is a test of `faceup', a regression test system for font-lock | ||
| 2 | keywords. It should use major mode `faceup-test-mode'. | ||
| 3 | |||
| 4 | WARNING: The first word on this line should use | ||
| 5 | `font-lock-warning-face', and a tooltip should be displayed if the | ||
| 6 | mouse pointer is moved over it. | ||
| 7 | |||
| 8 | In this mode "<" and ">" are parentheses, but only when on the same | ||
| 9 | line without any other "<" and ">" characters between them. | ||
| 10 | <OK> <NOT <OK> > | ||
| 11 | < | ||
| 12 | NOT OK | ||
| 13 | > | ||
| 14 | |||
| 15 | test1.txt ends here. | ||
diff --git a/test/lisp/emacs-lisp/faceup-resources/files/test1.txt.faceup b/test/lisp/emacs-lisp/faceup-resources/files/test1.txt.faceup new file mode 100644 index 00000000000..7d4938adf17 --- /dev/null +++ b/test/lisp/emacs-lisp/faceup-resources/files/test1.txt.faceup | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | This is a test of `faceup', a regression test system for font-lock | ||
| 2 | keywords. It should use major mode `faceup-test-mode'. | ||
| 3 | |||
| 4 | «(help-echo):"Baloon tip: Fly smoothly!":«w:WARNING»»: The first word on this line should use | ||
| 5 | `font-lock-warning-face', and a tooltip should be displayed if the | ||
| 6 | mouse pointer is moved over it. | ||
| 7 | |||
| 8 | In this mode «s:"«(syntax-table):(4 . 41):<»"» and «s:"«(syntax-table):(5 . 40):>»"» are parentheses, but only when on the same | ||
| 9 | line without any other «s:"«(syntax-table):(4 . 41):<»"» and «s:"«(syntax-table):(5 . 40):>»"» characters between them. | ||
| 10 | «(syntax-table):(4 . 41):<»OK«(syntax-table):(5 . 40):>» <NOT «(syntax-table):(4 . 41):<»OK«(syntax-table):(5 . 40):>» > | ||
| 11 | < | ||
| 12 | NOT OK | ||
| 13 | > | ||
| 14 | |||
| 15 | test1.txt ends here. | ||
diff --git a/test/lisp/emacs-lisp/faceup-tests/faceup-test-basics.el b/test/lisp/emacs-lisp/faceup-tests/faceup-test-basics.el new file mode 100644 index 00000000000..6009bfa836d --- /dev/null +++ b/test/lisp/emacs-lisp/faceup-tests/faceup-test-basics.el | |||
| @@ -0,0 +1,287 @@ | |||
| 1 | ;;; faceup-test-basics.el --- Tests for the `faceup' package. | ||
| 2 | |||
| 3 | ;; Copyright (C) 2014-2017 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; Author: Anders Lindgren | ||
| 6 | ;; Keywords: languages, faces | ||
| 7 | |||
| 8 | ;; This file is part of GNU Emacs. | ||
| 9 | |||
| 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. | ||
| 14 | |||
| 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. | ||
| 19 | |||
| 20 | ;; You should have received a copy of the GNU General Public License | ||
| 21 | ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. | ||
| 22 | |||
| 23 | ;;; Commentary: | ||
| 24 | |||
| 25 | ;; Basic tests for the `faceup' package. | ||
| 26 | |||
| 27 | ;;; Code: | ||
| 28 | |||
| 29 | (require 'faceup) | ||
| 30 | |||
| 31 | (ert-deftest faceup-functions () | ||
| 32 | "Test primitive functions." | ||
| 33 | (should (equal (faceup-normalize-face-property '()) '())) | ||
| 34 | (should (equal (faceup-normalize-face-property 'a) '(a))) | ||
| 35 | (should (equal (faceup-normalize-face-property '(a)) '(a))) | ||
| 36 | (should (equal (faceup-normalize-face-property '(:x t)) '((:x t)))) | ||
| 37 | (should (equal (faceup-normalize-face-property '(:x t a)) '((:x t)))) | ||
| 38 | (should (equal (faceup-normalize-face-property '(:x t a b)) '((:x t)))) | ||
| 39 | (should (equal (faceup-normalize-face-property '(a :x t)) '(a (:x t)))) | ||
| 40 | (should (equal (faceup-normalize-face-property '(a b :x t)) | ||
| 41 | '(a b (:x t)))) | ||
| 42 | |||
| 43 | (should (equal (faceup-normalize-face-property '(:x t :y nil)) | ||
| 44 | '((:y nil) (:x t)))) | ||
| 45 | (should (equal (faceup-normalize-face-property '(:x t :y nil a)) | ||
| 46 | '((:y nil) (:x t)))) | ||
| 47 | (should (equal (faceup-normalize-face-property '(:x t :y nil a b)) | ||
| 48 | '((:y nil) (:x t)))) | ||
| 49 | (should (equal (faceup-normalize-face-property '(a :x t :y nil)) | ||
| 50 | '(a (:y nil) (:x t)))) | ||
| 51 | (should (equal (faceup-normalize-face-property '(a b :x t :y nil)) | ||
| 52 | '(a b (:y nil) (:x t))))) | ||
| 53 | |||
| 54 | |||
| 55 | (ert-deftest faceup-markup () | ||
| 56 | "Test basic `faceup' features." | ||
| 57 | ;; ---------- | ||
| 58 | ;; Basics | ||
| 59 | (should (equal (faceup-markup-string "") "")) | ||
| 60 | (should (equal (faceup-markup-string "test") "test")) | ||
| 61 | ;; ---------- | ||
| 62 | ;; Escaping | ||
| 63 | (should (equal (faceup-markup-string "«") "««")) | ||
| 64 | (should (equal (faceup-markup-string "«A«B«C«") "««A««B««C««")) | ||
| 65 | (should (equal (faceup-markup-string "»") "«»")) | ||
| 66 | (should (equal (faceup-markup-string "»A»B»C»") "«»A«»B«»C«»")) | ||
| 67 | ;; ---------- | ||
| 68 | ;; Plain property. | ||
| 69 | ;; | ||
| 70 | ;; UU | ||
| 71 | ;; ABCDEF | ||
| 72 | (let ((s "ABCDEF")) | ||
| 73 | (set-text-properties 2 4 '(face underline) s) | ||
| 74 | (should (equal (faceup-markup-string s) "AB«U:CD»EF"))) | ||
| 75 | ;; ---------- | ||
| 76 | ;; Plain property, full text | ||
| 77 | ;; | ||
| 78 | ;; UUUUUU | ||
| 79 | ;; ABCDEF | ||
| 80 | (let ((s "ABCDEF")) | ||
| 81 | (set-text-properties 0 6 '(face underline) s) | ||
| 82 | (should (equal (faceup-markup-string s) "«U:ABCDEF»"))) | ||
| 83 | ;; ---------- | ||
| 84 | ;; Anonymous face. | ||
| 85 | ;; | ||
| 86 | ;; AA | ||
| 87 | ;; ABCDEF | ||
| 88 | (let ((s "ABCDEF")) | ||
| 89 | (set-text-properties 2 4 '(face (:underline t)) s) | ||
| 90 | (should (equal (faceup-markup-string s) "AB«:(:underline t):CD»EF"))) | ||
| 91 | ;; ---------- | ||
| 92 | ;; Anonymous face -- plist with two keys. | ||
| 93 | ;; | ||
| 94 | ;; AA | ||
| 95 | ;; ABCDEF | ||
| 96 | (let ((s "ABCDEF")) | ||
| 97 | (set-text-properties 2 4 '(face (:foo t :bar nil)) s) | ||
| 98 | (should (equal (faceup-markup-string s) | ||
| 99 | "AB«:(:foo t):«:(:bar nil):CD»»EF"))) | ||
| 100 | ;; Ditto, with plist in list. | ||
| 101 | (let ((s "ABCDEF")) | ||
| 102 | (set-text-properties 2 4 '(face ((:foo t :bar nil))) s) | ||
| 103 | (should (equal (faceup-markup-string s) | ||
| 104 | "AB«:(:foo t):«:(:bar nil):CD»»EF"))) | ||
| 105 | ;; ---------- | ||
| 106 | ;; Anonymous face -- Two plists. | ||
| 107 | ;; | ||
| 108 | ;; AA | ||
| 109 | ;; ABCDEF | ||
| 110 | (let ((s "ABCDEF")) | ||
| 111 | (set-text-properties 2 4 '(face ((:foo t) (:bar nil))) s) | ||
| 112 | (should (equal (faceup-markup-string s) | ||
| 113 | "AB«:(:bar nil):«:(:foo t):CD»»EF"))) | ||
| 114 | ;; ---------- | ||
| 115 | ;; Anonymous face -- Nested. | ||
| 116 | ;; | ||
| 117 | ;; AA | ||
| 118 | ;; IIII | ||
| 119 | ;; ABCDEF | ||
| 120 | (let ((s "ABCDEF")) | ||
| 121 | (set-text-properties 1 2 '(face ((:foo t))) s) | ||
| 122 | (set-text-properties 2 4 '(face ((:bar t) (:foo t))) s) | ||
| 123 | (set-text-properties 4 5 '(face ((:foo t))) s) | ||
| 124 | (should (equal (faceup-markup-string s) | ||
| 125 | "A«:(:foo t):B«:(:bar t):CD»E»F"))) | ||
| 126 | ;; ---------- | ||
| 127 | ;; Nested properties. | ||
| 128 | ;; | ||
| 129 | ;; UU | ||
| 130 | ;; IIII | ||
| 131 | ;; ABCDEF | ||
| 132 | (let ((s "ABCDEF")) | ||
| 133 | (set-text-properties 1 2 '(face italic) s) | ||
| 134 | (set-text-properties 2 4 '(face (underline italic)) s) | ||
| 135 | (set-text-properties 4 5 '(face italic) s) | ||
| 136 | (should (equal (faceup-markup-string s) "A«I:B«U:CD»E»F"))) | ||
| 137 | ;; ---------- | ||
| 138 | ;; Overlapping, but not nesting, properties. | ||
| 139 | ;; | ||
| 140 | ;; UUU | ||
| 141 | ;; III | ||
| 142 | ;; ABCDEF | ||
| 143 | (let ((s "ABCDEF")) | ||
| 144 | (set-text-properties 1 2 '(face italic) s) | ||
| 145 | (set-text-properties 2 4 '(face (underline italic)) s) | ||
| 146 | (set-text-properties 4 5 '(face underline) s) | ||
| 147 | (should (equal (faceup-markup-string s) "A«I:B«U:CD»»«U:E»F"))) | ||
| 148 | ;; ---------- | ||
| 149 | ;; Overlapping, but not nesting, properties. | ||
| 150 | ;; | ||
| 151 | ;; III | ||
| 152 | ;; UUU | ||
| 153 | ;; ABCDEF | ||
| 154 | (let ((s "ABCDEF")) | ||
| 155 | (set-text-properties 1 2 '(face italic) s) | ||
| 156 | (set-text-properties 2 4 '(face (italic underline)) s) | ||
| 157 | (set-text-properties 4 5 '(face underline) s) | ||
| 158 | (should (equal (faceup-markup-string s) "A«I:B»«U:«I:CD»E»F"))) | ||
| 159 | ;; ---------- | ||
| 160 | ;; More than one face at the same location. | ||
| 161 | ;; | ||
| 162 | ;; The property to the front takes precedence, it is rendered as the | ||
| 163 | ;; innermost parenthesis pair. | ||
| 164 | (let ((s "ABCDEF")) | ||
| 165 | (set-text-properties 2 4 '(face (underline italic)) s) | ||
| 166 | (should (equal (faceup-markup-string s) "AB«I:«U:CD»»EF"))) | ||
| 167 | (let ((s "ABCDEF")) | ||
| 168 | (set-text-properties 2 4 '(face (italic underline)) s) | ||
| 169 | (should (equal (faceup-markup-string s) "AB«U:«I:CD»»EF"))) | ||
| 170 | ;; ---------- | ||
| 171 | ;; Equal ranges, full text. | ||
| 172 | (let ((s "ABCDEF")) | ||
| 173 | (set-text-properties 0 6 '(face (underline italic)) s) | ||
| 174 | (should (equal (faceup-markup-string s) "«I:«U:ABCDEF»»"))) | ||
| 175 | ;; Ditto, with stray markup characters. | ||
| 176 | (let ((s "AB«CD»EF")) | ||
| 177 | (set-text-properties 0 8 '(face (underline italic)) s) | ||
| 178 | (should (equal (faceup-markup-string s) "«I:«U:AB««CD«»EF»»"))) | ||
| 179 | |||
| 180 | ;; ---------- | ||
| 181 | ;; Multiple properties | ||
| 182 | (let ((faceup-properties '(alpha beta gamma))) | ||
| 183 | ;; One property. | ||
| 184 | (let ((s "ABCDEF")) | ||
| 185 | (set-text-properties 2 4 '(alpha (a l p h a)) s) | ||
| 186 | (should (equal (faceup-markup-string s) "AB«(alpha):(a l p h a):CD»EF"))) | ||
| 187 | |||
| 188 | ;; Two properties, inner enclosed. | ||
| 189 | (let ((s "ABCDEFGHIJ")) | ||
| 190 | (set-text-properties 2 8 '(alpha (a l p h a)) s) | ||
| 191 | (font-lock-append-text-property 4 6 'beta '(b e t a) s) | ||
| 192 | (should (equal (faceup-markup-string s) | ||
| 193 | "AB«(alpha):(a l p h a):CD«(beta):(b e t a):EF»GH»IJ"))) | ||
| 194 | |||
| 195 | ;; Two properties, same end | ||
| 196 | (let ((s "ABCDEFGH")) | ||
| 197 | (set-text-properties 2 6 '(alpha (a)) s) | ||
| 198 | (add-text-properties 4 6 '(beta (b)) s) | ||
| 199 | (should | ||
| 200 | (equal | ||
| 201 | (faceup-markup-string s) | ||
| 202 | "AB«(alpha):(a):CD«(beta):(b):EF»»GH"))) | ||
| 203 | |||
| 204 | ;; Two properties, overlap. | ||
| 205 | (let ((s "ABCDEFGHIJ")) | ||
| 206 | (set-text-properties 2 6 '(alpha (a)) s) | ||
| 207 | (add-text-properties 4 8 '(beta (b)) s) | ||
| 208 | (should | ||
| 209 | (equal | ||
| 210 | (faceup-markup-string s) | ||
| 211 | "AB«(alpha):(a):CD«(beta):(b):EF»»«(beta):(b):GH»IJ"))))) | ||
| 212 | |||
| 213 | |||
| 214 | (ert-deftest faceup-clean () | ||
| 215 | "Test the clean features of `faceup'." | ||
| 216 | (should (equal (faceup-clean-string "") "")) | ||
| 217 | (should (equal (faceup-clean-string "test") "test")) | ||
| 218 | (should (equal (faceup-clean-string "AB«U:CD»EF") "ABCDEF")) | ||
| 219 | (should (equal (faceup-clean-string "«U:ABCDEF»") "ABCDEF")) | ||
| 220 | (should (equal (faceup-clean-string "A«I:B«U:CD»E»F") "ABCDEF")) | ||
| 221 | (should (equal (faceup-clean-string "A«I:B«U:CD»»«U:E»F") "ABCDEF")) | ||
| 222 | (should (equal (faceup-clean-string "AB«I:«U:CD»»EF") "ABCDEF")) | ||
| 223 | (should (equal (faceup-clean-string "«I:«U:ABCDEF»»") "ABCDEF")) | ||
| 224 | (should (equal (faceup-clean-string "«(foo)I:ABC»DEF") "ABCDEF")) | ||
| 225 | (should (equal (faceup-clean-string "«:(:foo t):ABC»DEF") "ABCDEF")) | ||
| 226 | ;; Escaped markup characters. | ||
| 227 | (should (equal (faceup-clean-string "««") "«")) | ||
| 228 | (should (equal (faceup-clean-string "«»") "»")) | ||
| 229 | (should (equal (faceup-clean-string "A«I:B«U:CD»«»»«U:E»F") "ABCD»EF"))) | ||
| 230 | |||
| 231 | |||
| 232 | (ert-deftest faceup-render () | ||
| 233 | "Test the render features of `faceup'." | ||
| 234 | (should (equal (faceup-render-string "") "")) | ||
| 235 | (should (equal (faceup-render-string "««") "«")) | ||
| 236 | (should (equal (faceup-render-string "«»") "»")) | ||
| 237 | (should (equal (faceup-render-string "A«I:B«U:CD»«»»«U:E»F") "ABCD»EF"))) | ||
| 238 | |||
| 239 | |||
| 240 | (defvar faceup-test-resources-directory | ||
| 241 | (concat (file-name-directory | ||
| 242 | (substring (faceup-this-file-directory) 0 -1)) | ||
| 243 | "faceup-resources/") | ||
| 244 | "The `faceup-resources' directory.") | ||
| 245 | |||
| 246 | |||
| 247 | (defvar faceup-test-this-file-directory nil | ||
| 248 | "The result of `faceup-this-file-directory' in various contexts. | ||
| 249 | |||
| 250 | This is set by the file test support file | ||
| 251 | `faceup-test-this-file-directory.el'.") | ||
| 252 | |||
| 253 | |||
| 254 | (ert-deftest faceup-directory () | ||
| 255 | "Test `faceup-this-file-directory'." | ||
| 256 | (let ((file (concat faceup-test-resources-directory | ||
| 257 | "faceup-test-this-file-directory.el")) | ||
| 258 | (load-file-name nil)) | ||
| 259 | ;; Test normal load. | ||
| 260 | (makunbound 'faceup-test-this-file-directory) | ||
| 261 | (load file nil :nomessage) | ||
| 262 | (should (equal faceup-test-this-file-directory | ||
| 263 | faceup-test-resources-directory)) | ||
| 264 | ;; Test `eval-buffer'. | ||
| 265 | (makunbound 'faceup-test-this-file-directory) | ||
| 266 | (save-excursion | ||
| 267 | (find-file file) | ||
| 268 | (eval-buffer)) | ||
| 269 | (should (equal faceup-test-this-file-directory | ||
| 270 | faceup-test-resources-directory)) | ||
| 271 | ;; Test `eval-defun'. | ||
| 272 | (makunbound 'faceup-test-this-file-directory) | ||
| 273 | (save-excursion | ||
| 274 | (find-file file) | ||
| 275 | (save-excursion | ||
| 276 | (goto-char (point-min)) | ||
| 277 | (while (not (eobp)) | ||
| 278 | ;; Note: In batch mode, this prints the result of the | ||
| 279 | ;; evaluation. Unfortunately, this is hard to fix. | ||
| 280 | (eval-defun nil) | ||
| 281 | (forward-sexp)))) | ||
| 282 | (should (equal faceup-test-this-file-directory | ||
| 283 | faceup-test-resources-directory)))) | ||
| 284 | |||
| 285 | (provide 'faceup-test-basics) | ||
| 286 | |||
| 287 | ;;; faceup-test-basics.el ends here | ||
diff --git a/test/lisp/emacs-lisp/faceup-tests/faceup-test-files.el b/test/lisp/emacs-lisp/faceup-tests/faceup-test-files.el new file mode 100644 index 00000000000..0f136862094 --- /dev/null +++ b/test/lisp/emacs-lisp/faceup-tests/faceup-test-files.el | |||
| @@ -0,0 +1,63 @@ | |||
| 1 | ;;; faceup-test-files.el --- Self test of `faceup' using dummy major mode. | ||
| 2 | |||
| 3 | ;; Copyright (C) 2014-2017 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; Author: Anders Lindgren | ||
| 6 | ;; Keywords: languages, faces | ||
| 7 | |||
| 8 | ;; This file is part of GNU Emacs. | ||
| 9 | |||
| 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. | ||
| 14 | |||
| 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. | ||
| 19 | |||
| 20 | ;; You should have received a copy of the GNU General Public License | ||
| 21 | ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. | ||
| 22 | |||
| 23 | ;;; Commentary: | ||
| 24 | |||
| 25 | ;; Self test of `faceup' with a major mode that sets both the | ||
| 26 | ;; `syntax-table' and the `echo-help' property. | ||
| 27 | ;; | ||
| 28 | ;; This file can also be seen as a blueprint of test cases for real | ||
| 29 | ;; major modes. | ||
| 30 | |||
| 31 | ;;; Code: | ||
| 32 | |||
| 33 | (require 'faceup) | ||
| 34 | |||
| 35 | ;; Note: The byte compiler needs the value to load `faceup-test-mode', | ||
| 36 | ;; hence the `eval-and-compile'. | ||
| 37 | (eval-and-compile | ||
| 38 | (defvar faceup-test-files-dir (faceup-this-file-directory) | ||
| 39 | "The directory of this file.")) | ||
| 40 | |||
| 41 | (require 'faceup-test-mode | ||
| 42 | (concat faceup-test-files-dir | ||
| 43 | "../faceup-resources/" | ||
| 44 | "faceup-test-mode.el")) | ||
| 45 | |||
| 46 | (defun faceup-test-files-check-one (file) | ||
| 47 | "Test that FILE is fontified as the .faceup file describes. | ||
| 48 | |||
| 49 | FILE is interpreted as relative to this source directory." | ||
| 50 | (let ((faceup-properties '(face syntax-table help-echo))) | ||
| 51 | (faceup-test-font-lock-file 'faceup-test-mode | ||
| 52 | (concat | ||
| 53 | faceup-test-files-dir | ||
| 54 | "../faceup-resources/" | ||
| 55 | file)))) | ||
| 56 | (faceup-defexplainer faceup-test-files-check-one) | ||
| 57 | |||
| 58 | (ert-deftest faceup-files () | ||
| 59 | (should (faceup-test-files-check-one "files/test1.txt"))) | ||
| 60 | |||
| 61 | (provide 'faceup-test-files) | ||
| 62 | |||
| 63 | ;;; faceup-test-files.el ends here | ||