aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMichal Nazarewicz2014-05-27 21:00:44 -0400
committerStefan Monnier2014-05-27 21:00:44 -0400
commitfc21a7de3a92a38c5b00ce64a81c8668d0482fbb (patch)
tree5791ec3019cdb37ff4798f9ec4f93a79a815038d /test
parent4c539a7b387874577136190d8e1a413da1d7e240 (diff)
downloademacs-fc21a7de3a92a38c5b00ce64a81c8668d0482fbb.tar.gz
emacs-fc21a7de3a92a38c5b00ce64a81c8668d0482fbb.zip
* test/automated/tildify-tests.el: New file.
* lisp/textmodes/tildify.el (tildify-buffer, tildify-region): Add dont-ask option. Fixes: debbugs:17547
Diffstat (limited to 'test')
-rw-r--r--test/ChangeLog4
-rw-r--r--test/automated/tildify-tests.el106
2 files changed, 110 insertions, 0 deletions
diff --git a/test/ChangeLog b/test/ChangeLog
index 5c037eb2b79..33a70436b2d 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,7 @@
12014-05-21 Michal Nazarewicz <mina86@mina86.com>
2
3 * automated/tildify-tests.el: New file.
4
12014-05-27 Stefan Monnier <monnier@iro.umontreal.ca> 52014-05-27 Stefan Monnier <monnier@iro.umontreal.ca>
2 6
3 * indent/ruby.rb: Add one more test. 7 * indent/ruby.rb: Add one more test.
diff --git a/test/automated/tildify-tests.el b/test/automated/tildify-tests.el
new file mode 100644
index 00000000000..4223029f626
--- /dev/null
+++ b/test/automated/tildify-tests.el
@@ -0,0 +1,106 @@
1;;; tildify-test.el --- ERT tests for teldify.el
2
3;; Copyright (C) 2014 Free Software Foundation, Inc.
4
5;; Author: Michal Nazarewicz <mina86@mina86.com>
6;; Version: 4.5
7;; Keywords: text, TeX, SGML, wp
8
9;; This file is part of GNU Emacs.
10
11;; GNU Emacs is free software: you can redistribute it and/or modify
12;; it under the terms of the GNU General Public License as published by
13;; the Free Software Foundation, either version 3 of the License, or
14;; (at your option) any later version.
15
16;; GNU Emacs is distributed in the hope that it will be useful,
17;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19;; GNU General Public License for more details.
20
21;; You should have received a copy of the GNU General Public License
22;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23
24;;; Commentary:
25
26;; This package defines regression tests for the tildify package.
27
28;;; Code:
29
30(require 'ert)
31(require 'tildify)
32
33(defun tildify-test--example-sentence (space)
34 "Return an example sentence with SPACE where hard space is required."
35 (concat "Lorem ipsum v" space "dolor sit amet, a" space
36 "consectetur adipiscing elit."))
37
38
39(defun tildify-test--example-html (sentence &optional with-nbsp)
40 "Return an example HTML code.
41SENTENCE is placed where spaces should not be replaced with hard spaces, and
42WITH-NBSP is placed where spaces should be replaced with hard spaces. If the
43latter is missing, SENTENCE will be used in all placeholder positions."
44 (let ((with-nbsp (or with-nbsp sentence)))
45 (concat "<p>" with-nbsp "</p>\n"
46 "<pre>" sentence "</pre>\n"
47 "<! -- " sentence " -- >\n"
48 "<p>" with-nbsp "</p>\n"
49 "<" sentence ">\n")))
50
51
52(defun tildify-test--test (modes input expected)
53 "Test tildify running in MODES.
54INPUT is the initial content of the buffer and EXPECTED is expected result
55after `tildify-buffer' is run."
56 (dolist (mode modes)
57 (with-temp-buffer
58 (funcall mode)
59 (let ((header (concat "Testing `tildify-buffer' in "
60 (symbol-name mode) "\n")))
61 (insert header input)
62 (tildify-buffer t)
63 (should (string-equal (concat header expected) (buffer-string)))))
64 (with-temp-buffer
65 (funcall mode)
66 (let ((header (concat "Testing `tildify-region' in "
67 (symbol-name mode) "\n")))
68 (insert header input)
69 (tildify-region (point-min) (point-max) t)
70 (should (string-equal (concat header expected) (buffer-string)))))))
71
72(ert-deftest tildify-test-html ()
73 "Tests tildification in an HTML document"
74 (let* ((sentence (tildify-test--example-sentence " "))
75 (with-nbsp (tildify-test--example-sentence "&nbsp;")))
76 (tildify-test--test '(html-mode sgml-mode)
77 (tildify-test--example-html sentence sentence)
78 (tildify-test--example-html sentence with-nbsp))))
79
80
81(defun tildify-test--example-tex (sentence &optional with-nbsp)
82 "Return an example (La)Tex code.
83SENTENCE is placed where spaces should not be replaced with hard spaces, and
84WITH-NBSP is placed where spaces should be replaced with hard spaces. If the
85latter is missing, SENTENCE will be used in all placeholder positions."
86 (let ((with-nbsp (or with-nbsp sentence)))
87 (concat with-nbsp "\n"
88 "\\begin{verbatim}\n" sentence "\n\\end{verbatim}\n"
89 "\\verb#" sentence "#\n"
90 "$$" sentence "$$\n"
91 "$" sentence "$\n"
92 "\\[" sentence "\\]\n"
93 "\\v A % " sentence "\n"
94 with-nbsp "\n")))
95
96(ert-deftest tildify-test-tex ()
97 "Tests tildification in a (La)TeX document"
98 (let* ((sentence (tildify-test--example-sentence " "))
99 (with-nbsp (tildify-test--example-sentence "~")))
100 (tildify-test--test '(tex-mode latex-mode plain-tex-mode)
101 (tildify-test--example-tex sentence sentence)
102 (tildify-test--example-tex sentence with-nbsp))))
103
104(provide 'tildify-tests)
105
106;;; tildify-tests.el ends here