]> code.delx.au - gnu-emacs/blobdiff - test/automated/tildify-tests.el
* test/automated/package-test.el (package-test-signed): Tweak skip
[gnu-emacs] / test / automated / tildify-tests.el
index 55d2d576721a3a47cfe71aa3cd3a67954926e643..8b50cf728686ac0848b66c020fcc545864231c45 100644 (file)
@@ -1,6 +1,6 @@
 ;;; tildify-test.el --- ERT tests for tildify.el -*- lexical-binding: t -*-
 
-;; Copyright (C) 2014 Free Software Foundation, Inc.
+;; Copyright (C) 2014-2016 Free Software Foundation, Inc.
 
 ;; Author:     Michal Nazarewicz <mina86@mina86.com>
 ;; Version:    4.5
@@ -55,6 +55,7 @@ If IS-XML is non-nil, <pre> tag is not treated specially."
 INPUT is the initial content of the buffer and EXPECTED is expected result
 after `tildify-buffer' is run."
   (with-temp-buffer
+    (setq-local buffer-file-coding-system 'utf-8)
     (dolist (mode modes)
       (erase-buffer)
       (funcall mode)
@@ -185,6 +186,79 @@ The function must terminate as soon as callback returns nil."
       (+ (point-min) 10) (+ (point-min) 20)))) ; start at "3" end past "5"
 
 
+(defun tildify-space-test--test (modes nbsp env-open &optional set-space-string)
+  (with-temp-buffer
+    (setq-local buffer-file-coding-system 'utf-8)
+    (dolist (mode modes)
+      (funcall mode)
+      (when set-space-string
+        (setq-local tildify-space-string nbsp))
+      (let ((header (concat "Testing `tildify-space' in "
+                            (symbol-name mode) "\n")))
+        ;; Replace space with hard space.
+        (erase-buffer)
+        (insert header "Lorem v ")
+        (should (tildify-space))
+        (should (string-equal (concat header "Lorem v" nbsp) (buffer-string)))
+        ;; Inside and ignore environment, replacing does not happen.
+        (erase-buffer)
+        (insert header env-open "Lorem v ")
+        (should (not (tildify-space)))
+        (should (string-equal (concat header env-open "Lorem v ")
+                              (buffer-string)))))))
+
+(ert-deftest tildify-space-test-html ()
+  "Tests auto-tildification in an HTML document"
+  (tildify-space-test--test '(html-mode sgml-mode) " " "<pre>"))
+
+(ert-deftest tildify-space-test-html-nbsp ()
+  "Tests auto-tildification in an HTML document"
+  (tildify-space-test--test '(html-mode sgml-mode) "&nbsp;" "<pre>" t))
+
+(ert-deftest tildify-space-test-xml ()
+  "Tests auto-tildification in an XML document"
+  (tildify-space-test--test '(nxml-mode) " " "<! -- "))
+
+(ert-deftest tildify-space-test-tex ()
+  "Tests tildification in a TeX document"
+  (tildify-space-test--test '(tex-mode latex-mode plain-tex-mode)
+                            "~" "\\verb# "))
+
+
+(defun tildify-space-undo-test--test
+    (modes nbsp env-open &optional set-space-string)
+  (with-temp-buffer
+    (setq-local buffer-file-coding-system 'utf-8)
+    (dolist (mode modes)
+      (funcall mode)
+      (when set-space-string
+        (setq-local tildify-space-string nbsp))
+      (let ((header (concat "Testing double-space-undos in "
+                            (symbol-name mode) "\n")))
+        (erase-buffer)
+        (insert header "Lorem v" nbsp " ")
+        (should (not (tildify-space)))
+        (should (string-equal (concat header "Lorem v ") (buffer-string)))))))
+
+(ert-deftest tildify-space-undo-test-html ()
+  "Tests auto-tildification in an HTML document"
+  (tildify-space-undo-test--test '(html-mode sgml-mode) " " "<pre>"))
+
+(ert-deftest tildify-space-undo-test-html-nbsp ()
+  "Tests auto-tildification in an HTML document"
+  (tildify-space-undo-test--test '(html-mode sgml-mode) "&nbsp;" "<pre>" t))
+
+(ert-deftest tildify-space-undo-test-xml ()
+  "Tests auto-tildification in an XML document"
+  (tildify-space-undo-test--test '(nxml-mode) " " "<! -- "))
+
+(ert-deftest tildify-space-undo-test-tex ()
+  "Tests tildification in a TeX document"
+  (tildify-space-undo-test--test '(tex-mode latex-mode plain-tex-mode)
+                                 "~" "\\verb# "))
+
+
+
 (provide 'tildify-tests)
 
 ;;; tildify-tests.el ends here