[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/assess 739661405b 59/95: Add assess-robot.el and tests
From: |
ELPA Syncer |
Subject: |
[elpa] externals/assess 739661405b 59/95: Add assess-robot.el and tests |
Date: |
Tue, 19 Jul 2022 15:57:33 -0400 (EDT) |
branch: externals/assess
commit 739661405b36f3e19c347cb55bde961b4497cf2c
Author: Phillip Lord <phillip.lord@russet.org.uk>
Commit: Phillip Lord <phillip.lord@russet.org.uk>
Add assess-robot.el and tests
assess-robot.el provides a framework for writing keyboard macros
in a readable way, embedded inside a test. It also adds macros for
running these macros similar to `with-current-buffer'.
---
README.md | 4 ++
assess-robot.el | 112 ++++++++++++++++++++++++++++++++++++++++++++++
test/assess-robot-test.el | 65 +++++++++++++++++++++++++++
3 files changed, 181 insertions(+)
diff --git a/README.md b/README.md
index ebc4864c04..77f1c66834 100644
--- a/README.md
+++ b/README.md
@@ -37,6 +37,10 @@ Emacs-25.1 release.
Release
-------
+## Version 0.3
+
+Add assess-robot.el
+
## Version 0.2
Add assess-call.el
diff --git a/assess-robot.el b/assess-robot.el
new file mode 100644
index 0000000000..b9d31680d9
--- /dev/null
+++ b/assess-robot.el
@@ -0,0 +1,112 @@
+;;; assess-robot.el --- Test support functions -*- lexical-binding: t -*-
+
+;;; Header:
+
+;; This file is not part of Emacs
+
+;; Author: Phillip Lord <phillip.lord@russet.org.uk>
+;; Maintainer: Phillip Lord <phillip.lord@russet.org.uk>
+;; Version: 0.2
+
+;; The contents of this file are subject to the GPL License, Version 3.0.
+
+;; Copyright (C) 2016, Phillip Lord
+
+;; This program is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Code:
+(defmacro assess-robot-with-switched-buffer (buffer &rest body)
+ "With BUFFER, evaluate BODY.
+
+This macro is rather like `with-current-buffer', except that it
+uses `switch-to-buffer'. This is generally a bad idea when used
+programmatically. But, it is necessary, for example, when using
+keyboard macros."
+ (declare (indent 1) (debug t))
+ (let ((before-buffer (make-symbol "before-buffer")))
+ `(let ((,before-buffer (current-buffer)))
+ (unwind-protect
+ (progn
+ (switch-to-buffer ,buffer)
+ ,@body)
+ (switch-to-buffer ,before-buffer)))))
+
+(defmacro assess-robot-with-temp-switched-buffer (&rest body)
+ "Evalate BODY in temporary buffer.
+
+As with `assess-robot-with-switched-buffer', `switch-to-buffer'
+is used."
+ (declare (indent 0) (debug t))
+ (let ((temp-buffer (make-symbol "temp-buffer")))
+ `(let ((,temp-buffer (generate-new-buffer " *temp*")))
+ (assess-robot-with-switched-buffer ,temp-buffer
+ (unwind-protect
+ (progn
+ ;; Enable the undo list because we want it for most robot
+ ;; situations.
+ (setq buffer-undo-list nil)
+ ,@body)
+ (and (buffer-name ,temp-buffer)
+ (kill-buffer ,temp-buffer)))))))
+
+(defmacro assess-robot-with-switched-buffer-string (&rest body)
+ "Evalate BODY in a temporary buffer and return buffer string.
+
+See also `assess-robot-with-temp-switched-buffer'."
+ (declare (debug t))
+ `(assess-robot-with-temp-switched-buffer
+ (progn
+ ,@body
+ (buffer-substring-no-properties
+ (point-min) (point-max)))))
+
+(defun assess-robot-execute-kmacro (macro)
+ "Execute the MACRO.
+
+In this case, MACRO is the \"long form\" accepted by
+`edit-kdb-macro'."
+ (let ((macro (read-kbd-macro macro)))
+ ;; I wanted to add a nice way to edit the macro, but sadly
+ ;; edit-kdb-macro provides no nice entry point. So, we take the nasty step
+ ;; of setting the last-kbd-macro instead.
+ (setq last-kbd-macro macro)
+ (execute-kbd-macro
+ (read-kbd-macro macro))))
+
+(defun assess-robot-copy-and-finish ()
+ "Copy the macro in edmacro to the kill-ring."
+ (interactive)
+ (save-excursion
+ (goto-char (point-min))
+ (search-forward "Macro:")
+ (forward-line)
+ (let ((string
+ (buffer-substring-no-properties
+ (point)
+ (point-max))))
+ (with-temp-buffer
+ (insert "\"")
+ (insert string)
+ (insert "\"")
+ (kill-ring-save (point-min)
+ (point-max))))
+ (edmacro-finish-edit)))
+
+(with-eval-after-load
+ 'edmacro
+ (define-key edmacro-mode-map "C-c C-k" 'assess-robot-copy-and-finish))
+
+(provide 'assess-robot)
+;;; assess-robot.el ends here
+
diff --git a/test/assess-robot-test.el b/test/assess-robot-test.el
new file mode 100644
index 0000000000..e7e7868d18
--- /dev/null
+++ b/test/assess-robot-test.el
@@ -0,0 +1,65 @@
+;;; assess-robot-test.el --- Test support functions -*- lexical-binding: t -*-
+
+;;; Header:
+
+;; This file is not part of Emacs
+
+;; Author: Phillip Lord <phillip.lord@russet.org.uk>
+;; Maintainer: Phillip Lord <phillip.lord@russet.org.uk>
+
+;; The contents of this file are subject to the GPL License, Version 3.0.
+
+;; Copyright (C) 2015, 2016, Phillip Lord
+
+;; This program is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Code:
+
+(require 'assess-robot)
+(require 'ert)
+
+(ert-deftest assess-robot-test-with-switched-buffer ()
+ (should
+ (with-temp-buffer
+ (let ((c (current-buffer)))
+ (assess-robot-with-switched-buffer
+ (current-buffer))
+ (buffer-live-p c))))
+ (should-not
+ (buffer-live-p
+ (with-temp-buffer
+ (assess-robot-with-switched-buffer
+ (current-buffer)
+ (current-buffer))))))
+
+(ert-deftest assess-robot-test-with-temp-switched-buffer ()
+ (should-not
+ (let ((b4 (current-buffer)))
+ (assess-robot-with-temp-switched-buffer
+ (equal
+ b4 (current-buffer)))))
+ (should-not
+ (buffer-live-p
+ (assess-robot-with-temp-switched-buffer
+ (current-buffer)))))
+
+
+(ert-deftest assess-robot-test-with-switched-buffer-string ()
+ (should
+ (assess=
+ "hello"
+ (assess-robot-with-switched-buffer-string
+ (insert "hello")))))
+
+(provide 'assess-robot-test)
- [elpa] externals/assess f490f18a18 32/95: Merge branch 'master' of github.com:phillord/sisyphus, (continued)
- [elpa] externals/assess f490f18a18 32/95: Merge branch 'master' of github.com:phillord/sisyphus, ELPA Syncer, 2022/07/19
- [elpa] externals/assess 0d079db1a7 34/95: Completed documentation., ELPA Syncer, 2022/07/19
- [elpa] externals/assess cab9fea7b8 28/95: Documentation for everything, ELPA Syncer, 2022/07/19
- [elpa] externals/assess f521db4101 36/95: Add sisyphus-discover, ELPA Syncer, 2022/07/19
- [elpa] externals/assess 46290f163d 37/95: Add tests for discover., ELPA Syncer, 2022/07/19
- [elpa] externals/assess 38fc7829bc 42/95: Interpret nil to mean no faces., ELPA Syncer, 2022/07/19
- [elpa] externals/assess 818cf77258 27/95: Merge pull request #2 from syohex/minimum, ELPA Syncer, 2022/07/19
- [elpa] externals/assess 880d519d6b 35/95: Update readme, add infojs., ELPA Syncer, 2022/07/19
- [elpa] externals/assess 216adb069c 47/95: Add assess-call.el, ELPA Syncer, 2022/07/19
- [elpa] externals/assess 07bd7f8915 58/95: Doc fixes, ELPA Syncer, 2022/07/19
- [elpa] externals/assess 739661405b 59/95: Add assess-robot.el and tests,
ELPA Syncer <=
- [elpa] externals/assess 9521b07480 71/95: Fix and Publish documentation statically, ELPA Syncer, 2022/07/19
- [elpa] externals/assess 5aee8d7500 81/95: Mark some tests as failed on earlier emacs, ELPA Syncer, 2022/07/19
- [elpa] externals/assess 0a3e94477a 78/95: Support all of Emacs 24 series, ELPA Syncer, 2022/07/19
- [elpa] externals/assess e5b0415126 85/95: Update README and release number, ELPA Syncer, 2022/07/19
- [elpa] externals/assess 7a3189a587 86/95: Remove types and replace with convertors, ELPA Syncer, 2022/07/19
- [elpa] externals/assess 5bac045b27 94/95: Update version, ELPA Syncer, 2022/07/19
- [elpa] externals/assess ac8ff1f928 39/95: Change all file names to assess., ELPA Syncer, 2022/07/19
- [elpa] externals/assess 4bf702a08a 43/95: Re-order to put macros first., ELPA Syncer, 2022/07/19
- [elpa] externals/assess e9344a55df 45/95: Move from ert to assess-discover, ELPA Syncer, 2022/07/19
- [elpa] externals/assess 7409b103a3 46/95: Update .gitignore, ELPA Syncer, 2022/07/19