aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcin Borkowski2017-02-14 11:30:36 +0100
committerMarcin Borkowski2017-05-09 14:26:08 +0200
commit6d58dda40a0a43d14dffdd995f0cb3dcc329fa4b (patch)
treeecc8cc8a738a645ffa7ed4e52300769f216ff6e9
parent72d7961d678f9c5f4cb812e0bb9b6dffafb47c68 (diff)
downloademacs-6d58dda40a0a43d14dffdd995f0cb3dcc329fa4b.tar.gz
emacs-6d58dda40a0a43d14dffdd995f0cb3dcc329fa4b.zip
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.
-rw-r--r--test/lisp/emacs-lisp/lisp-tests.el39
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 @@
5;; Author: Aaron S. Hawley <aaron.s.hawley@gmail.com> 5;; Author: Aaron S. Hawley <aaron.s.hawley@gmail.com>
6;; Author: Stefan Monnier <monnier@iro.umontreal.ca> 6;; Author: Stefan Monnier <monnier@iro.umontreal.ca>
7;; Author: Daniel Colascione <dancol@dancol.org> 7;; Author: Daniel Colascione <dancol@dancol.org>
8;; Author: Marcin Borkowski <mbork@mbork.pl>
8;; Keywords: internal 9;; Keywords: internal
9 10
10;; GNU Emacs is free software: you can redistribute it and/or modify 11;; GNU Emacs is free software: you can redistribute it and/or modify
@@ -303,5 +304,43 @@
303 ;; abcdefghijklmnopqrstuv 304 ;; abcdefghijklmnopqrstuv
304 i f a scan-error) 305 i f a scan-error)
305 306
307;;; Helpers
308
309(defvar elisp-test-point-marker-regex "=!\\([a-zA-Z0-9-]+\\)="
310 "A regexp matching placeholders for point position for
311`elisp-tests-with-temp-buffer'.")
312
313;; Copied and heavily modified from `python-tests-with-temp-buffer'
314(defmacro elisp-tests-with-temp-buffer (contents &rest body)
315 "Create an `emacs-lisp-mode' enabled temp buffer with CONTENTS.
316BODY is the code to be executed within the temp buffer. Point is
317always located at the beginning of buffer. Special markers of
318the form =!NAME= in CONTENTS are removed, and a for each one
319a variable called NAME is bound to the position of such
320a marker."
321 (declare (indent 1) (debug t))
322 `(with-temp-buffer
323 (emacs-lisp-mode)
324 (insert ,contents)
325 (goto-char (point-min))
326 (while (re-search-forward elisp-test-point-marker-regex nil t)
327 (delete-region (match-beginning 0)
328 (match-end 0)))
329 (goto-char (point-min))
330 ,(let (marker-list)
331 (with-temp-buffer
332 (insert (cond ((symbolp contents)
333 (symbol-value contents))
334 (t contents)))
335 (goto-char (point-min))
336 (while (re-search-forward elisp-test-point-marker-regex nil t)
337 (push (list (intern (match-string-no-properties 1))
338 (match-beginning 0))
339 marker-list)
340 (delete-region (match-beginning 0)
341 (match-end 0))))
342 `(let ,marker-list
343 ,@body))))
344
306(provide 'lisp-tests) 345(provide 'lisp-tests)
307;;; lisp-tests.el ends here 346;;; lisp-tests.el ends here