diff options
author | Marcin Borkowski <mbork@mbork.pl> | 2017-02-14 11:30:36 +0100 |
---|---|---|
committer | Marcin Borkowski <mbork@mbork.pl> | 2017-05-09 14:26:08 +0200 |
commit | 6d58dda40a0a43d14dffdd995f0cb3dcc329fa4b (patch) | |
tree | ecc8cc8a738a645ffa7ed4e52300769f216ff6e9 /test/lisp/emacs-lisp/lisp-tests.el | |
parent | 72d7961d678f9c5f4cb812e0bb9b6dffafb47c68 (diff) | |
download | emacs-6d58dda40a0a43d14dffdd995f0cb3dcc329fa4b.tar.gz |
Add elisp-tests-with-temp-buffer, a new testing macro
* test/lisp/emacs-lisp/lisp-tests.el
(elisp-test-point-marker-regex) New variable.
(elisp-tests-with-temp-buffer): New macro to help test functions
moving the point and/or mark.
Diffstat (limited to 'test/lisp/emacs-lisp/lisp-tests.el')
-rw-r--r-- | test/lisp/emacs-lisp/lisp-tests.el | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/test/lisp/emacs-lisp/lisp-tests.el b/test/lisp/emacs-lisp/lisp-tests.el index 8cba7fc526a..f6039f78eb1 100644 --- a/test/lisp/emacs-lisp/lisp-tests.el +++ b/test/lisp/emacs-lisp/lisp-tests.el @@ -5,6 +5,7 @@ ;; Author: Aaron S. Hawley <aaron.s.hawley@gmail.com> ;; Author: Stefan Monnier <monnier@iro.umontreal.ca> ;; Author: Daniel Colascione <dancol@dancol.org> +;; Author: Marcin Borkowski <mbork@mbork.pl> ;; Keywords: internal ;; GNU Emacs is free software: you can redistribute it and/or modify @@ -303,5 +304,43 @@ ;; abcdefghijklmnopqrstuv i f a scan-error) +;;; Helpers + +(defvar elisp-test-point-marker-regex "=!\\([a-zA-Z0-9-]+\\)=" + "A regexp matching placeholders for point position for +`elisp-tests-with-temp-buffer'.") + +;; Copied and heavily modified from `python-tests-with-temp-buffer' +(defmacro elisp-tests-with-temp-buffer (contents &rest body) + "Create an `emacs-lisp-mode' enabled temp buffer with CONTENTS. +BODY is the code to be executed within the temp buffer. Point is +always located at the beginning of buffer. Special markers of +the form =!NAME= in CONTENTS are removed, and a for each one +a variable called NAME is bound to the position of such +a marker." + (declare (indent 1) (debug t)) + `(with-temp-buffer + (emacs-lisp-mode) + (insert ,contents) + (goto-char (point-min)) + (while (re-search-forward elisp-test-point-marker-regex nil t) + (delete-region (match-beginning 0) + (match-end 0))) + (goto-char (point-min)) + ,(let (marker-list) + (with-temp-buffer + (insert (cond ((symbolp contents) + (symbol-value contents)) + (t contents))) + (goto-char (point-min)) + (while (re-search-forward elisp-test-point-marker-regex nil t) + (push (list (intern (match-string-no-properties 1)) + (match-beginning 0)) + marker-list) + (delete-region (match-beginning 0) + (match-end 0)))) + `(let ,marker-list + ,@body)))) + (provide 'lisp-tests) ;;; lisp-tests.el ends here |