[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/org-superstar 22a44f14ee 026/162: overhauled testing modul
From: |
Stefan Kangas |
Subject: |
[nongnu] elpa/org-superstar 22a44f14ee 026/162: overhauled testing module composure-test.el |
Date: |
Fri, 31 Dec 2021 19:35:20 -0500 (EST) |
branch: elpa/org-superstar
commit 22a44f14ee040a4db5a76388814be190100b0fb3
Author: D. Williams <d.williams@posteo.net>
Commit: D. Williams <d.williams@posteo.net>
overhauled testing module composure-test.el
added hooks for useful minor modes specific to module
added features for toggling individual function listening
re-formatted output
---
tests/README.org | 5 +--
tests/composure-test.el | 83 +++++++++++++++++++++++++++++++++++--------------
2 files changed, 62 insertions(+), 26 deletions(-)
diff --git a/tests/README.org b/tests/README.org
index 3e218cf2e4..b07432b5ba 100644
--- a/tests/README.org
+++ b/tests/README.org
@@ -29,8 +29,9 @@ To run additional test files, it is easiest to just =-l= them
as well.
This file adds lots of information regarding calls to ~compose-region~
for functions defined in =org-superstar.el=. They are written to the
=*Messages*= buffer. It also makes sure all ~--prettify-~ functions
-return proper faces (or ~nil~).
-
+return proper faces (or ~nil~). This module auto-enables
+~column-number-mode~ as well as ~linum-mode~ for org to allow for manual,
+character-wise comparison of the characters prettified.
# LocalWords: README el
diff --git a/tests/composure-test.el b/tests/composure-test.el
index 618ec369de..b92c1fa7d2 100644
--- a/tests/composure-test.el
+++ b/tests/composure-test.el
@@ -17,12 +17,30 @@
;;; Code:
(require 'cl-macs)
+(require 'subr-x)
+(require 'linum)
(defvar-local org-superstar/listen nil
"If t, activate the advice ‘org-superstar/comp-test’.
The idea is to only let ‘org-superstar/comp-test’ listen in on
‘compose-region’ when another function is advised to let-bind
-this variable.")
+this variable. You can control which functions are currently
+active listeners by calling ‘org-superstar/toggle-listener’.")
+
+
+(defconst org-superstar/comp-listeners
+ '(org-superstar--prettify-ibullets
+ org-superstar--prettify-main-hbullet
+ org-superstar--prettify-other-hbullet
+ org-superstar--prettify-leading-hbullets)
+ "List of functions ‘org-superstar/comp-test’ can be applied to.")
+
+;;; Hooks
+
+(add-hook 'org-mode-hook
+ (lambda ()
+ (linum-mode 1)
+ (column-number-mode 1)))
;;; Advice definitions
@@ -31,27 +49,29 @@ this variable.")
START, END, COMPONENTS and MOD-FUNC correspond to the arguments
of ‘compose-region’."
(when org-superstar/listen
- (message "compose-region called: from %d to %d" start end)
;; I currently *do not* want to touch more than one character at a
;; time. This test will only fail when I mess up regex grouping,
;; but it serves as a reminder that composing a region is not as
;; trivial as making the region bigger.
(cl-assert (= 1 (- end start)))
+ (let ((line (line-number-at-pos start))
+ (col (save-excursion (goto-char start) (current-column)))
+ (composed-string (buffer-substring-no-properties start end)))
(cond
((stringp components)
(message
- "composing ‘%s’ using string ‘%s’"
- (buffer-substring-no-properties start end)
+ "line %s, column %s: composing ‘%s’ using string ‘%s’"
+ line col composed-string
components))
((characterp components)
(message
- "composing ‘%s’ using string ‘%s’"
- (buffer-substring-no-properties start end)
+ "line %s, column %s: composing ‘%s’ using character ‘%c’"
+ line col composed-string
components))
(t
(message
"composing ‘%s’ using a sequence"
- (buffer-substring-no-properties start end))))))
+ (buffer-substring-no-properties start end)))))))
(defun org-superstar/wrap-prettify (face-function &rest args)
"Wrap FACE-FUNCTION and call with ARGS.
@@ -59,29 +79,44 @@ Ensure the return value is a face or nil. Also toggle
‘compose-region’ calls to log behavior."
(let ((org-superstar/listen t)
(returned-face nil))
- (message "Entered function")
(prog1 (setq returned-face (apply face-function args))
(cl-assert (or (facep returned-face)
(null returned-face)))
(when (facep returned-face)
- (message "Applied face ‘%s’ to group."
- returned-face))
- (message "Exited" face-function))))
-
-
-
-;;; Adding advice
+ (message "Applied face ‘%s’ to group (line %d)"
+ returned-face
+ (line-number-at-pos (match-beginning 0)))))))
+
+
+;;; Helper functions
+(defun org-superstar/read-listener ()
+ "Return an argument list for ‘org-superstar/toggle-silence’."
+ (let ((answer (completing-read
+ "Toggle silence for: "
+ org-superstar/comp-listeners nil t)))
+ (unless (string-empty-p answer)
+ (list (read answer)))))
+
+;;; Adding and removing advice
+
+(defun org-superstar/toggle-listener (&optional symbol)
+ "Toggle listening to ‘compose-region’ for listener SYMBOL."
+ (interactive (org-superstar/read-listener))
+ (when symbol
+ (let ((is-adviced
+ (advice-member-p #'org-superstar/wrap-prettify symbol)))
+ (cond (is-adviced
+ (message "‘%s’ listening: OFF" symbol)
+ (advice-remove symbol #'org-superstar/wrap-prettify))
+ (t
+ (message "‘%s’ listening: ON" symbol)
+ (advice-add symbol
+ :around #'org-superstar/wrap-prettify))))))
;; listen in on compose-region
(advice-add 'compose-region :before #'org-superstar/comp-test)
-;; advise prettifyers to snoop
+;; advise prettifyers
-(advice-add 'org-superstar--prettify-ibullets
- :around #'org-superstar/wrap-prettify)
-(advice-add 'org-superstar--prettify-main-hbullet
- :around #'org-superstar/wrap-prettify)
-(advice-add 'org-superstar--prettify-other-hbullet
- :around #'org-superstar/wrap-prettify)
-(advice-add 'org-superstar--prettify-leading-hbullets
- :around #'org-superstar/wrap-prettify)
+(dolist (symbol org-superstar/comp-listeners)
+ (org-superstar/toggle-listener symbol))
- [nongnu] elpa/org-superstar 8daeb3c4f3 040/162: added further reference files, (continued)
- [nongnu] elpa/org-superstar 8daeb3c4f3 040/162: added further reference files, Stefan Kangas, 2021/12/31
- [nongnu] elpa/org-superstar f4ef9bb36d 017/162: added a roadmap., Stefan Kangas, 2021/12/31
- [nongnu] elpa/org-superstar ffaf1feb01 018/162: added mention of worg contrib in order not to forget myself, Stefan Kangas, 2021/12/31
- [nongnu] elpa/org-superstar 9a60ffc4cc 058/162: Removing warning from source., Stefan Kangas, 2021/12/31
- [nongnu] elpa/org-superstar bce708624d 039/162: updated composure-test to run with new unit tests, Stefan Kangas, 2021/12/31
- [nongnu] elpa/org-superstar f5a258d524 057/162: Remove warnings from README., Stefan Kangas, 2021/12/31
- [nongnu] elpa/org-superstar f7cb51960e 029/162: added FIXME: other-hbullet face behaves inconsistently when treated as leading bullet., Stefan Kangas, 2021/12/31
- [nongnu] elpa/org-superstar a2876d7399 045/162: fixed bug in external module 'honest-marketing', Stefan Kangas, 2021/12/31
- [nongnu] elpa/org-superstar ca448ebd7c 065/162: Added a temporary file slomode.el, Stefan Kangas, 2021/12/31
- [nongnu] elpa/org-superstar 98bba637cd 078/162: removing old bullet point, Stefan Kangas, 2021/12/31
- [nongnu] elpa/org-superstar 22a44f14ee 026/162: overhauled testing module composure-test.el,
Stefan Kangas <=
- [nongnu] elpa/org-superstar 589b136106 064/162: updating homepage., Stefan Kangas, 2021/12/31
- [nongnu] elpa/org-superstar a0d2cfaae1 076/162: "org-mode" -> "Org mode", Stefan Kangas, 2021/12/31
- [nongnu] elpa/org-superstar 4500a774bb 068/162: Added an FAQ., Stefan Kangas, 2021/12/31
- [nongnu] elpa/org-superstar a078ca392a 079/162: Remove unnecessary lighter for Org Superstar., Stefan Kangas, 2021/12/31
- [nongnu] elpa/org-superstar 369292856e 042/162: reduced minimal-setup, Stefan Kangas, 2021/12/31
- [nongnu] elpa/org-superstar 3818dff655 006/162: Completed first draft of README., Stefan Kangas, 2021/12/31
- [nongnu] elpa/org-superstar 3bbb8e551c 011/162: updating gitignore to correctly handle temp files, Stefan Kangas, 2021/12/31
- [nongnu] elpa/org-superstar d9accdcad7 002/162: Added README, Stefan Kangas, 2021/12/31
- [nongnu] elpa/org-superstar 02497248a9 007/162: Adding first revision of org-superstar.el, Stefan Kangas, 2021/12/31
- [nongnu] elpa/org-superstar d45e1eb060 004/162: Added further fix: forgot that ‘’-support was a custom modification., Stefan Kangas, 2021/12/31