blob: 78c79b7e4e585c17fae47839bd81523269854675 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
;;; test-custom-case-downcase-dwim.el --- Tests for cj/downcase-dwim -*- lexical-binding: t; -*-
;;; Commentary:
;; Tests for the cj/downcase-dwim function from custom-case.el.
;;
;; Mirror of upcase-dwim: if a region is active, downcase the region;
;; otherwise downcase the symbol at point. Signals user-error if no symbol.
;; Tests focus on the dispatch logic, not on Emacs's downcase-region.
;;; Code:
(require 'ert)
(unless (boundp 'cj/custom-keymap)
(defvar cj/custom-keymap (make-sparse-keymap)))
(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
(require 'custom-case)
;;; Normal Cases
(ert-deftest test-custom-case-downcase-dwim-normal-region-downcased ()
"Active region should be downcased."
(with-temp-buffer
(insert "HELLO WORLD")
(set-mark (point-min))
(goto-char (point-max))
(activate-mark)
(cj/downcase-dwim)
(should (equal (buffer-string) "hello world"))))
(ert-deftest test-custom-case-downcase-dwim-normal-partial-region ()
"Only the selected region should be downcased."
(with-temp-buffer
(insert "HELLO WORLD")
(set-mark 1)
(goto-char 6)
(activate-mark)
(cj/downcase-dwim)
(should (equal (buffer-string) "hello WORLD"))))
(ert-deftest test-custom-case-downcase-dwim-normal-symbol-at-point ()
"Without region, symbol at point should be downcased."
(with-temp-buffer
(insert "HELLO WORLD")
(goto-char 1)
(cj/downcase-dwim)
(should (equal (buffer-string) "hello WORLD"))))
(ert-deftest test-custom-case-downcase-dwim-normal-symbol-mid-word ()
"Point in the middle of a symbol should downcase the whole symbol."
(with-temp-buffer
(insert "HELLO WORLD")
(goto-char 3)
(cj/downcase-dwim)
(should (equal (buffer-string) "hello WORLD"))))
(ert-deftest test-custom-case-downcase-dwim-normal-already-lowercase ()
"Already lowercase text should remain unchanged."
(with-temp-buffer
(insert "hello WORLD")
(goto-char 1)
(cj/downcase-dwim)
(should (equal (buffer-string) "hello WORLD"))))
;;; Boundary Cases
(ert-deftest test-custom-case-downcase-dwim-boundary-single-char-symbol ()
"Single character symbol should be downcased."
(with-temp-buffer
(insert "A")
(goto-char 1)
(cj/downcase-dwim)
(should (equal (buffer-string) "a"))))
;;; Error Cases
(ert-deftest test-custom-case-downcase-dwim-error-no-symbol-signals-error ()
"With no region and no symbol at point, should signal user-error."
(with-temp-buffer
(insert " ")
(goto-char 2)
(should-error (cj/downcase-dwim) :type 'user-error)))
(provide 'test-custom-case-downcase-dwim)
;;; test-custom-case-downcase-dwim.el ends here
|