[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/org-superstar b196dc10af 025/162: adding first draft of pu
From: |
Stefan Kangas |
Subject: |
[nongnu] elpa/org-superstar b196dc10af 025/162: adding first draft of public testing facilities |
Date: |
Fri, 31 Dec 2021 19:35:20 -0500 (EST) |
branch: elpa/org-superstar
commit b196dc10afc203763bf867815f79cb7d61ce3167
Author: D. Williams <d.williams@posteo.net>
Commit: D. Williams <d.williams@posteo.net>
adding first draft of public testing facilities
---
tests/README.org | 36 ++++++++++++++++++++
tests/composure-test.el | 87 +++++++++++++++++++++++++++++++++++++++++++++++++
tests/minimal-setup.el | 6 ++++
tests/sample.org | 35 ++++++++++++++++++++
4 files changed, 164 insertions(+)
diff --git a/tests/README.org b/tests/README.org
new file mode 100644
index 0000000000..3e218cf2e4
--- /dev/null
+++ b/tests/README.org
@@ -0,0 +1,36 @@
+#+TITLE: Testing Routines: There be Dragons
+
+* Purpose
+This is where I will put cleaned up testing routines meant for testing
+and debugging ~org-superstar-mode~. However, as the title suggests,
+*none of these files are meant for normal package usage*. Consequently,
+I advise to run these files with a minimal setup (think =emacs -Q=) and
+only keep sessions involving them open /as long as necessary/. Since
+the things I want to test are very side effect reliant, I see myself
+forced to rely on ~advice~ and family. To further emphasize that I do
+not intend to ship any of these functions as part of my package, I use
+the non-standard (yet popular) naming convention
+~org-superstar/variable-name~. See below for the purpose of the
+individual files included here.
+
+** =sample.org=
+A harmless sample file. An earlier version was used for the sample
+image in the top-level README.
+
+** =minimal-setup.el=
+This file contains a minimal setup useful for testing. Just run:
+#+BEGIN_SRC bash
+emacs -Q -l ../org-superstar.el -l minimal-setup.el sample.org
+#+END_SRC
+
+To run additional test files, it is easiest to just =-l= them as well.
+
+** =composure-test.el=
+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~).
+
+
+
+# LocalWords: README el
diff --git a/tests/composure-test.el b/tests/composure-test.el
new file mode 100644
index 0000000000..618ec369de
--- /dev/null
+++ b/tests/composure-test.el
@@ -0,0 +1,87 @@
+;;; composure-test.el --- Track how org-superstar primitives modify the
buffer. -*- lexical-binding: t; -*-
+
+;;; Commentary:
+
+;; This file purposefully breaks naming conventions to indicate that
+;; it is *NOT* part of the main package.
+
+;; WARNING: This testing package is *not* suitable for any purpose
+;; other than testing org-superstar-mode. ONLY use this code on a
+;; clean Emacs install ("emacs -Q") and ONLY keep the Emacs session
+;; running for as long as you need to. DO NOT use an Emacs session
+;; loading this file for everyday editing.
+
+;; THIS FILE ADVISES EMACS INTERNALS FOR DEBUGGING PURPOSES ONLY.
+;; USE AT YOUR OWN RISK.
+
+;;; Code:
+
+(require 'cl-macs)
+
+(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.")
+
+;;; Advice definitions
+
+(defun org-superstar/comp-test (start end &optional components mod-func)
+ "Advise ‘compose-region’ to log modifications made to buffer.
+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)))
+ (cond
+ ((stringp components)
+ (message
+ "composing ‘%s’ using string ‘%s’"
+ (buffer-substring-no-properties start end)
+ components))
+ ((characterp components)
+ (message
+ "composing ‘%s’ using string ‘%s’"
+ (buffer-substring-no-properties start end)
+ components))
+ (t
+ (message
+ "composing ‘%s’ using a sequence"
+ (buffer-substring-no-properties start end))))))
+
+(defun org-superstar/wrap-prettify (face-function &rest args)
+ "Wrap FACE-FUNCTION and call with ARGS.
+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
+
+;; listen in on compose-region
+(advice-add 'compose-region :before #'org-superstar/comp-test)
+
+;; advise prettifyers to snoop
+
+(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)
diff --git a/tests/minimal-setup.el b/tests/minimal-setup.el
new file mode 100644
index 0000000000..46c3987194
--- /dev/null
+++ b/tests/minimal-setup.el
@@ -0,0 +1,6 @@
+;;; A small init file setting you up for tests.
+(add-hook 'org-mode-hook
+ (lambda ()
+ (org-superstar-mode 1)))
+
+(setq debug-on-error t)
diff --git a/tests/sample.org b/tests/sample.org
new file mode 100644
index 0000000000..b95b373957
--- /dev/null
+++ b/tests/sample.org
@@ -0,0 +1,35 @@
+#+TITLE: Sample File
+#+STARTUP: showeverything
+* Lorem ipsum dolor sit amet
+** Consectetur adipiscing elit
+*** Eiusmod tempor incididunt
+ Ut labore et dolore magna aliqua. Fringilla phasellus faucibus
+ scelerisque eleifend donec pretium vulputate sapien. Odio pellentesque
+ diam volutpat commodo.
+ * Varius morbi enim nunc
+ * faucibus, ultrices vitae
+ + auctor eu augue ut lectus arcu bibendum.
+ + neque egestas congue quisque
+ - Et ultrices neque ornare aenean euismod.
+ * Tristique nulla!
+
+#+BEGIN_SRC C
+/*
+,* This is not a header
+ + this
+ + is not
+ * a list.
+*/
+#+END_SRC
+
+
+*************** Inline task?
+**************** second
+***************** third
+
+* 1
+** 2
+*** 3
+**** 4
+***** 5
+****** 6
- [nongnu] elpa/org-superstar d0cb2f4b9f 150/162: Merge branch 'hide-all-todo-keywords' of andersjohansson, (continued)
- [nongnu] elpa/org-superstar d0cb2f4b9f 150/162: Merge branch 'hide-all-todo-keywords' of andersjohansson, Stefan Kangas, 2021/12/31
- [nongnu] elpa/org-superstar f14dd4dc8b 151/162: Fixed logic errors I introduced with last merge., Stefan Kangas, 2021/12/31
- [nongnu] elpa/org-superstar 03be6c0a30 162/162: Remove now redundant call to org-element-lineage, version bump., Stefan Kangas, 2021/12/31
- [nongnu] elpa/org-superstar 4a4ae121c1 061/162: Add further documentation regarding org-indent-mode., Stefan Kangas, 2021/12/31
- [nongnu] elpa/org-superstar 457b6cdb49 019/162: Updating README to include new features., Stefan Kangas, 2021/12/31
- [nongnu] elpa/org-superstar fe061dce0c 043/162: added simple batch mode based unit tests for font lock, Stefan Kangas, 2021/12/31
- [nongnu] elpa/org-superstar c70360d76b 028/162: Adding "test image" face-test.el, Stefan Kangas, 2021/12/31
- [nongnu] elpa/org-superstar 5614c01993 081/162: fixed typo in README, Stefan Kangas, 2021/12/31
- [nongnu] elpa/org-superstar d4948eb213 032/162: Updated README, Stefan Kangas, 2021/12/31
- [nongnu] elpa/org-superstar 45719ffd10 022/162: added a marker for melpa review, Stefan Kangas, 2021/12/31
- [nongnu] elpa/org-superstar b196dc10af 025/162: adding first draft of public testing facilities,
Stefan Kangas <=
- [nongnu] elpa/org-superstar 086ab28506 075/162: Updating Roadmap, Stefan Kangas, 2021/12/31
- [nongnu] elpa/org-superstar 4965e70c75 036/162: added reference for default headline fontification, Stefan Kangas, 2021/12/31
- [nongnu] elpa/org-superstar c58d1e2689 046/162: force org-superstar to clean up --font-lock-keywords, Stefan Kangas, 2021/12/31
- [nongnu] elpa/org-superstar a7d6b37ea2 062/162: Removing references to org-hide-leading-stars-before-indent-mode., Stefan Kangas, 2021/12/31
- [nongnu] elpa/org-superstar 6ef00c4eaf 034/162: renamed sample-titles to sample-headlines, Stefan Kangas, 2021/12/31
- [nongnu] elpa/org-superstar bd99047cb3 048/162: updating README, Stefan Kangas, 2021/12/31
- [nongnu] elpa/org-superstar b7c660aa32 038/162: adding further faceup files, Stefan Kangas, 2021/12/31
- [nongnu] elpa/org-superstar 4c2015072c 024/162: updated roadmap, Stefan Kangas, 2021/12/31
- [nongnu] elpa/org-superstar 845aa85b78 080/162: fixed typo in docstring, Stefan Kangas, 2021/12/31
- [nongnu] elpa/org-superstar fc62da2f85 077/162: fixed README conflict, Stefan Kangas, 2021/12/31