aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-24 07:26:20 -0500
committerCraig Jennings <c@cjennings.net>2026-05-24 07:26:20 -0500
commita7cc89482cc931f60d4b43d5c7b875542cbe2538 (patch)
tree8f313e84bfcefd4ed4f83e36aa9c4e8b25c180db /tests
parent9135298c45f2f03ab92903edb242c8f5f94396d5 (diff)
downloaddotemacs-a7cc89482cc931f60d4b43d5c7b875542cbe2538.tar.gz
dotemacs-a7cc89482cc931f60d4b43d5c7b875542cbe2538.zip
refactor(text-enclose): extract shared region-or-buffer bounds helper
The append/prepend/indent/dedent *-in-region-or-buffer commands each inlined the same (if (use-region-p) (region-beginning) (point-min)) / (region-end)/(point-max) block — four copies of the "operate on the region, else the whole buffer" contract. Extracted cj/--region-or-buffer-bounds as the single source of that decision and routed all four through it. Behavior is unchanged; the public-wrapper tests still pass. This was the "extract a shared helper that decides the target range" option from the reconcile task. The sibling custom-ordering.el helpers (cj/--arrayify, cj/--unarrayify) already document an explicit (start end) contract accurately and are region-required by design, so they needed no docstring change — each pair now has one clear, consistent contract. Tests cover the helper for the region case, the no-region whole-buffer case, and an empty buffer.
Diffstat (limited to 'tests')
-rw-r--r--tests/test-custom-text-enclose--region-or-buffer-bounds.el43
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/test-custom-text-enclose--region-or-buffer-bounds.el b/tests/test-custom-text-enclose--region-or-buffer-bounds.el
new file mode 100644
index 00000000..98992af8
--- /dev/null
+++ b/tests/test-custom-text-enclose--region-or-buffer-bounds.el
@@ -0,0 +1,43 @@
+;;; test-custom-text-enclose--region-or-buffer-bounds.el --- Tests for bounds helper -*- lexical-binding: t; -*-
+
+;;; Commentary:
+;; Unit tests for cj/--region-or-buffer-bounds, the single source of the
+;; "operate on the active region, else the whole buffer" contract shared by
+;; the *-in-region-or-buffer editing commands.
+
+;;; Code:
+
+(require 'ert)
+(require 'cl-lib)
+
+(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
+(require 'custom-text-enclose)
+
+;;; Normal Cases
+
+(ert-deftest test-ctenc-bounds-uses-region-when-active ()
+ "Normal: with an active region, returns its beginning and end."
+ (cl-letf (((symbol-function 'use-region-p) (lambda () t))
+ ((symbol-function 'region-beginning) (lambda () 3))
+ ((symbol-function 'region-end) (lambda () 8)))
+ (should (equal '(3 . 8) (cj/--region-or-buffer-bounds)))))
+
+(ert-deftest test-ctenc-bounds-uses-whole-buffer-when-no-region ()
+ "Normal: with no active region, returns the whole buffer's bounds."
+ (with-temp-buffer
+ (insert "line one\nline two\n")
+ (cl-letf (((symbol-function 'use-region-p) (lambda () nil)))
+ (should (equal (cons (point-min) (point-max))
+ (cj/--region-or-buffer-bounds))))))
+
+;;; Boundary Cases
+
+(ert-deftest test-ctenc-bounds-empty-buffer-no-region ()
+ "Boundary: an empty buffer with no region yields equal start and end."
+ (with-temp-buffer
+ (cl-letf (((symbol-function 'use-region-p) (lambda () nil)))
+ (let ((b (cj/--region-or-buffer-bounds)))
+ (should (= (car b) (cdr b)))))))
+
+(provide 'test-custom-text-enclose--region-or-buffer-bounds)
+;;; test-custom-text-enclose--region-or-buffer-bounds.el ends here