diff options
author | Michal Nazarewicz <mina86@mina86.com> | 2014-10-15 10:01:26 +0200 |
---|---|---|
committer | Michal Nazarewicz <mina86@mina86.com> | 2015-01-20 13:55:02 +0100 |
commit | 571441fc790fadfdc48a6287328828495719e990 (patch) | |
tree | 42be47520cddbf1f0f96bcab4ddfef4cade0d155 /test/automated/tildify-tests.el | |
parent | f9775f21fcddd3d3715cb3249090d99322488a45 (diff) | |
download | emacs-571441fc790fadfdc48a6287328828495719e990.tar.gz |
tildify: add `tildify-space' and `tildify-mode'
* lisp/textmodes/tildify.el (tildify-space): A new function
which can be used as a `post-self-insert-hook' to automatically
convert spaces into hard spaces.
(tildify-space-pattern): A new variable specifying pattern where
`tildify-space' should take effect.
(tildify-space-predicates): A new variable specifying list of
predicate functions that all must return non-nil for
`tildify-space' to take effect.
(tildify-space-region-predicate): A new functions meant to be
used as a predicate in `tildify-space-predicates' list.
(tildify-mode): A new minor mode enabling `tildify-space' as a
`post-self-insert-hook'
* tests/automated/tildify-tests.el (tildify-space-test--test):
A new helper function for testing `tildify-space' function.
(tildify-space-test-html, tildify-space-test-html-nbsp)
(tildify-space-test-xml, tildify-space-test-tex): New tests for
`tildify-space' function.
Diffstat (limited to 'test/automated/tildify-tests.el')
-rw-r--r-- | test/automated/tildify-tests.el | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/test/automated/tildify-tests.el b/test/automated/tildify-tests.el index b1f3de94fc5..dcbbbf137e3 100644 --- a/test/automated/tildify-tests.el +++ b/test/automated/tildify-tests.el @@ -185,6 +185,44 @@ 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 + (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) " " "<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# ")) + + (provide 'tildify-tests) ;;; tildify-tests.el ends here |