[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/buttercup 81bfed4 272/340: test: Add utility function send
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/buttercup 81bfed4 272/340: test: Add utility function send-string-to-ansi-buffer |
Date: |
Thu, 16 Dec 2021 14:59:49 -0500 (EST) |
branch: elpa/buttercup
commit 81bfed41e6b716e40139a94e0b137724f9d70d34
Author: Ola Nilsson <ola.nilsson@gmail.com>
Commit: Ola Nilsson <ola.nilsson@gmail.com>
test: Add utility function send-string-to-ansi-buffer
A `send-string-to-terminal' variant that sends STRING to BUFFER. Any
backspace, tab, newline, vertical tab, formfeed, or carriage return in
STRING will be translared to in-buffer movement to emulate a
terminal. Escape sequences in STRING are translated to text properties
using `ansi-color-apply'.
---
tests/test-buttercup.el | 44 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+)
diff --git a/tests/test-buttercup.el b/tests/test-buttercup.el
index fe94749..2719a37 100644
--- a/tests/test-buttercup.el
+++ b/tests/test-buttercup.el
@@ -25,6 +25,7 @@
(require 'buttercup)
(require 'autoload)
+(require 'ansi-color)
(require 'ert)
(require 'cl-lib)
@@ -48,6 +49,49 @@
(buttercup-warning-buffer-name " *ignored buttercup warnings*"))
,@body))
+(defun send-string-to-ansi-buffer (buffer string)
+ "A `send-string-to-terminal' variant that sends STRING to BUFFER.
+Any backspace, tab, newline, vertical tab, formfeed, or carriage
+return in STRING will be translared to in-buffer movement to
+emulate a terminal. Escape sequences in STRING are translated to
+text properties using `ansi-color-apply'."
+ (setq string (ansi-color-apply string))
+ (cl-labels ((insert-owrt (text)
+ "Insert TEXT by first overwriting until end of line."
+ ;; Delete and insert separately. Otherwise characters
+ ;; with text properties may remain when the new and
+ ;; the old text share substrings.
+ (delete-region (point) ; only delete up to the end of line
+ (min (+ (point) (length text))
+ (line-end-position)))
+ (insert text))
+ (line-feed ()
+ "Go to beginning of next line, creating it if necessary."
+ (end-of-line)
+ (or (zerop (forward-line))
+ (insert-and-inherit "\n"))))
+ (with-current-buffer buffer
+ (let ((tab-width 8) ; terminal uses 8 char tabs
+ (indent-tabs-mode nil) ; make sure move-* does not insert tabs
+ (tab-stop-list nil) ; default tab-stops (8 char interval)
+ ctrl-char)
+ (save-match-data
+ (while (string-match "\\(.*?\\)\\([\b\t\n\v\f\r]\\)\\([^z-a]*\\)"
string)
+ (insert-owrt (match-string 1 string))
+ (setq ctrl-char (aref (match-string 2 string) 0)
+ string (match-string 3 string))
+ (cl-case ctrl-char
+ (?\b (unless (bolp) (backward-char)))
+ (?\t (move-to-tab-stop))
+ (?\n (line-feed))
+ ((?\v ?\f) (let ((line-pos (current-column)))
+ (line-feed)
+ (move-to-column line-pos t)))
+ (?\r (forward-line 0))))
+ ;; print remaining text
+ (insert-owrt string))))))
+
+
;;;;;;;;;;
;;; expect
- [nongnu] elpa/buttercup 8a28489 230/340: Bump version: 1.18 → 1.19, (continued)
- [nongnu] elpa/buttercup 8a28489 230/340: Bump version: 1.18 → 1.19, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 0e40587 231/340: Tweak the spy-contexts to be more backward compatible, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 60028db 236/340: docs: Clarify the spy lifespan in writing-tests.md, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 9c4b473 237/340: test: Add missing apostrophe in spec title, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 90654ec 238/340: Update some docstrings, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 178c795 242/340: README: Add '-L .' to test runner example, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup fc4276a 247/340: Make it possible to abort test run cleanly, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup dbcd3d4 256/340: Calculate total test run time with current-time, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup c83ba7d 268/340: Extract function buttercup-elapsed-time-string, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 38cfa6f 270/340: Fix spy-on on Emacs 24.3 for symbols that are not fbound, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 81bfed4 272/340: test: Add utility function send-string-to-ansi-buffer,
ELPA Syncer <=
- [nongnu] elpa/buttercup cf4eee8 274/340: test: Verify output in the "The batch reporter" suite, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 4159111 275/340: test: Verify full line for reporter spec-done tests, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup fbb790b 278/340: test: Add tests for buttercup-started and buttercup-reporter-batch-color, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup d563e18 281/340: test: Add color tests for suite-done, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup b910b71 285/340: Extract buttercup--indented-description from the batch reporters, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup e71a40f 287/340: Make sure carriage movement characters are not colorized, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup a22fc29 288/340: Bump version: 1.21 → 1.22, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup dde8651 290/340: Add new function buttercup--spec-mark-pending and use it, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup c59110b 291/340: test: Extend with-local-buttercup with some key arguments, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup d443ecb 293/340: Clarify patterns in bin/buttercup, ELPA Syncer, 2021/12/16