blob: a0546b18d598ef2648fff8fddbc1487244df1013 (
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
;;; test-custom-file-buffer-copy-whole-buffer.el --- Tests for cj/copy-whole-buffer -*- lexical-binding: t; -*-
;;; Commentary:
;; Tests for the cj/copy-whole-buffer function from custom-file-buffer.el
;;
;; This function copies the entire contents of the current buffer to the kill ring.
;; Point and mark are left exactly where they were. No transient region is created.
;;; Code:
(require 'ert)
(require 'testutil-general)
;; Add modules directory to load path
(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
;; Stub dependencies before loading the module
(defvar cj/custom-keymap (make-sparse-keymap)
"Stub keymap for testing.")
;; Stub ps-print package
(provide 'ps-print)
;; Now load the actual production module
(require 'custom-file-buffer)
;;; Setup and Teardown
(defun test-copy-whole-buffer-setup ()
"Set up test environment."
(setq kill-ring nil))
(defun test-copy-whole-buffer-teardown ()
"Clean up test environment."
(setq kill-ring nil))
;;; Normal Cases
(ert-deftest test-copy-whole-buffer-simple-text ()
"Should copy simple text content to kill ring."
(test-copy-whole-buffer-setup)
(unwind-protect
(with-temp-buffer
(insert "Hello, world!")
(cj/copy-whole-buffer)
(should (equal (car kill-ring) "Hello, world!")))
(test-copy-whole-buffer-teardown)))
(ert-deftest test-copy-whole-buffer-preserves-point ()
"Should preserve point position."
(test-copy-whole-buffer-setup)
(unwind-protect
(with-temp-buffer
(insert "Hello, world!")
(goto-char 7) ; Position in middle
(cj/copy-whole-buffer)
(should (= (point) 7)))
(test-copy-whole-buffer-teardown)))
(ert-deftest test-copy-whole-buffer-preserves-mark ()
"Should preserve mark position."
(test-copy-whole-buffer-setup)
(unwind-protect
(with-temp-buffer
(insert "Hello, world!")
(push-mark 5)
(goto-char 10)
(cj/copy-whole-buffer)
(should (= (mark) 5))
(should (= (point) 10)))
(test-copy-whole-buffer-teardown)))
;;; Boundary Cases
(ert-deftest test-copy-whole-buffer-empty ()
"Should handle empty buffer."
(test-copy-whole-buffer-setup)
(unwind-protect
(with-temp-buffer
(cj/copy-whole-buffer)
(should (equal (car kill-ring) "")))
(test-copy-whole-buffer-teardown)))
(ert-deftest test-copy-whole-buffer-large ()
"Should handle very large buffer."
(test-copy-whole-buffer-setup)
(unwind-protect
(with-temp-buffer
(let ((large-content (make-string 100000 ?x)))
(insert large-content)
(cj/copy-whole-buffer)
(should (equal (car kill-ring) large-content))))
(test-copy-whole-buffer-teardown)))
(ert-deftest test-copy-whole-buffer-unicode ()
"Should handle unicode content (emoji, RTL text)."
(test-copy-whole-buffer-setup)
(unwind-protect
(with-temp-buffer
(insert "Hello 👋 مرحبا")
(cj/copy-whole-buffer)
(should (equal (car kill-ring) "Hello 👋 مرحبا")))
(test-copy-whole-buffer-teardown)))
(ert-deftest test-copy-whole-buffer-binary ()
"Should handle binary content."
(test-copy-whole-buffer-setup)
(unwind-protect
(with-temp-buffer
(insert (string 0 1 2 255))
(cj/copy-whole-buffer)
(should (equal (car kill-ring) (string 0 1 2 255))))
(test-copy-whole-buffer-teardown)))
(ert-deftest test-copy-whole-buffer-only-whitespace ()
"Should handle buffer with only whitespace."
(test-copy-whole-buffer-setup)
(unwind-protect
(with-temp-buffer
(insert " \t\n ")
(cj/copy-whole-buffer)
(should (equal (car kill-ring) " \t\n ")))
(test-copy-whole-buffer-teardown)))
(ert-deftest test-copy-whole-buffer-newlines-at-boundaries ()
"Should handle newlines at start/end."
(test-copy-whole-buffer-setup)
(unwind-protect
(with-temp-buffer
(insert "\n\nHello\n\n")
(cj/copy-whole-buffer)
(should (equal (car kill-ring) "\n\nHello\n\n")))
(test-copy-whole-buffer-teardown)))
(ert-deftest test-copy-whole-buffer-narrowed ()
"Should copy only visible region in narrowed buffer."
(test-copy-whole-buffer-setup)
(unwind-protect
(with-temp-buffer
(insert "Line 1\nLine 2\nLine 3\n")
(goto-char (point-min))
(forward-line 1)
(narrow-to-region (point) (progn (forward-line 1) (point)))
(cj/copy-whole-buffer)
;; Should copy only the narrowed region
(should (equal (car kill-ring) "Line 2\n")))
(test-copy-whole-buffer-teardown)))
(ert-deftest test-copy-whole-buffer-read-only ()
"Should work in read-only buffer."
(test-copy-whole-buffer-setup)
(unwind-protect
(with-temp-buffer
(insert "Read-only content")
(read-only-mode 1)
(cj/copy-whole-buffer)
(should (equal (car kill-ring) "Read-only content")))
(test-copy-whole-buffer-teardown)))
(ert-deftest test-copy-whole-buffer-kill-ring-has-content ()
"Should add to kill ring when it already has content."
(test-copy-whole-buffer-setup)
(unwind-protect
(with-temp-buffer
(insert "New content")
(kill-new "existing content")
(cj/copy-whole-buffer)
(should (equal (car kill-ring) "New content"))
(should (equal (cadr kill-ring) "existing content")))
(test-copy-whole-buffer-teardown)))
(ert-deftest test-copy-whole-buffer-multiline ()
"Should preserve multiline content."
(test-copy-whole-buffer-setup)
(unwind-protect
(with-temp-buffer
(insert "Line 1\nLine 2\nLine 3")
(cj/copy-whole-buffer)
(should (equal (car kill-ring) "Line 1\nLine 2\nLine 3")))
(test-copy-whole-buffer-teardown)))
(ert-deftest test-copy-whole-buffer-no-properties ()
"Should strip text properties."
(test-copy-whole-buffer-setup)
(unwind-protect
(with-temp-buffer
(insert (propertize "Hello" 'face 'bold))
(cj/copy-whole-buffer)
(should (equal (car kill-ring) "Hello"))
(should (null (text-properties-at 0 (car kill-ring)))))
(test-copy-whole-buffer-teardown)))
(provide 'test-custom-file-buffer-copy-whole-buffer)
;;; test-custom-file-buffer-copy-whole-buffer.el ends here
|