[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] fix/bug-21072 f6d0fe7 1/5: Add elisp-tests-with-temp-buffe
From: |
Marcin Borkowski |
Subject: |
[Emacs-diffs] fix/bug-21072 f6d0fe7 1/5: Add elisp-tests-with-temp-buffer, a new testing macro |
Date: |
Fri, 21 Apr 2017 08:26:43 -0400 (EDT) |
branch: fix/bug-21072
commit f6d0fe78efc7b849c1c094414525cef80c8427dd
Author: Marcin Borkowski <address@hidden>
Commit: Marcin Borkowski <address@hidden>
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.
---
etc/NEWS | 5 +++++
test/lisp/emacs-lisp/lisp-tests.el | 39 ++++++++++++++++++++++++++++++++++++++
2 files changed, 44 insertions(+)
diff --git a/etc/NEWS b/etc/NEWS
index 7281827..3aa3ec4 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1200,6 +1200,11 @@ window changed size when 'window-size-change-functions'
are run.
For details see the section "Mouse Window Auto-selection" in the Elisp
manual.
+** New macro 'elisp-tests-with-temp-buffer'
+which helps writing tests for functions that should change buffers in
+specific ways or manipulate point or mark positions.
+
+---
* Changes in Emacs 26.1 on Non-Free Operating Systems
** Intercepting hotkeys on Windows 7 and later now works better.
diff --git a/test/lisp/emacs-lisp/lisp-tests.el
b/test/lisp/emacs-lisp/lisp-tests.el
index 8cba7fc..f6039f7 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 <address@hidden>
;; Author: Stefan Monnier <address@hidden>
;; Author: Daniel Colascione <address@hidden>
+;; Author: Marcin Borkowski <address@hidden>
;; 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
- [Emacs-diffs] branch fix/bug-21072 created (now 87268bc), Marcin Borkowski, 2017/04/21
- [Emacs-diffs] fix/bug-21072 f6d0fe7 1/5: Add elisp-tests-with-temp-buffer, a new testing macro,
Marcin Borkowski <=
- [Emacs-diffs] fix/bug-21072 87268bc 5/5: Simplification due to Noam Postavsky, Marcin Borkowski, 2017/04/21
- [Emacs-diffs] fix/bug-21072 52477f4 4/5: Fix entry in NEWS, Marcin Borkowski, 2017/04/21
- [Emacs-diffs] fix/bug-21072 b26f400 3/5: Delete unnecessary entry from NEWS, Marcin Borkowski, 2017/04/21
- [Emacs-diffs] fix/bug-21072 4216827 2/5: Fix Bug#21072 and rework `mark-defun', Marcin Borkowski, 2017/04/21