blob: f68a06680c95f2c5791443fa99462716b5e2a1ec (
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
|
;;; test-custom-text-enclose-wrap.el --- Tests for cj/--wrap -*- lexical-binding: t; -*-
;;; Commentary:
;; Tests for the cj/--wrap function from custom-text-enclose.el
;;
;; This function wraps text with different opening and closing strings.
;; Unlike surround which uses the same string on both sides, wrap allows
;; asymmetric delimiters.
;;
;; Examples:
;; Input: "content", opening: "<div>", closing: "</div>"
;; Output: "<div>content</div>"
;;
;; Input: "text", opening: "(", closing: ")"
;; Output: "(text)"
;;
;; We test the NON-INTERACTIVE implementation (cj/--wrap) to avoid
;; mocking user input. This follows our testing best practice of
;; separating business logic from UI interaction.
;;; 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.")
;; Now load the actual production module
(require 'custom-text-enclose)
;;; Test Helpers
(defun test-wrap (text opening closing)
"Test cj/--wrap on TEXT with OPENING and CLOSING.
Returns the transformed string."
(cj/--wrap text opening closing))
;;; Normal Cases - Common Bracket Types
(ert-deftest test-wrap-parentheses ()
"Should wrap text with parentheses."
(let ((result (test-wrap "text" "(" ")")))
(should (string= result "(text)"))))
(ert-deftest test-wrap-square-brackets ()
"Should wrap text with square brackets."
(let ((result (test-wrap "item" "[" "]")))
(should (string= result "[item]"))))
(ert-deftest test-wrap-curly-braces ()
"Should wrap text with curly braces."
(let ((result (test-wrap "code" "{" "}")))
(should (string= result "{code}"))))
(ert-deftest test-wrap-angle-brackets ()
"Should wrap text with angle brackets."
(let ((result (test-wrap "tag" "<" ">")))
(should (string= result "<tag>"))))
;;; Normal Cases - HTML/XML Tags
(ert-deftest test-wrap-html-div ()
"Should wrap text with HTML div tags."
(let ((result (test-wrap "content" "<div>" "</div>")))
(should (string= result "<div>content</div>"))))
(ert-deftest test-wrap-html-span ()
"Should wrap text with HTML span tags."
(let ((result (test-wrap "text" "<span>" "</span>")))
(should (string= result "<span>text</span>"))))
(ert-deftest test-wrap-xml-tag ()
"Should wrap text with XML tags."
(let ((result (test-wrap "data" "<item>" "</item>")))
(should (string= result "<item>data</item>"))))
(ert-deftest test-wrap-html-with-attributes ()
"Should wrap text with HTML tag containing attributes."
(let ((result (test-wrap "link" "<a href=\"url\">" "</a>")))
(should (string= result "<a href=\"url\">link</a>"))))
;;; Normal Cases - Markdown Syntax
(ert-deftest test-wrap-markdown-bold ()
"Should wrap text with markdown bold syntax."
(let ((result (test-wrap "bold" "**" "**")))
(should (string= result "**bold**"))))
(ert-deftest test-wrap-markdown-italic ()
"Should wrap text with markdown italic syntax."
(let ((result (test-wrap "italic" "*" "*")))
(should (string= result "*italic*"))))
(ert-deftest test-wrap-markdown-code ()
"Should wrap text with markdown code syntax."
(let ((result (test-wrap "code" "`" "`")))
(should (string= result "`code`"))))
(ert-deftest test-wrap-markdown-link ()
"Should wrap text with markdown link syntax."
(let ((result (test-wrap "text" "[" "](url)")))
(should (string= result "[text](url)"))))
;;; Normal Cases - Various Content
(ert-deftest test-wrap-single-word ()
"Should wrap single word."
(let ((result (test-wrap "word" "(" ")")))
(should (string= result "(word)"))))
(ert-deftest test-wrap-multiple-words ()
"Should wrap multiple words."
(let ((result (test-wrap "hello world" "(" ")")))
(should (string= result "(hello world)"))))
(ert-deftest test-wrap-sentence ()
"Should wrap full sentence."
(let ((result (test-wrap "This is a sentence." "(" ")")))
(should (string= result "(This is a sentence.)"))))
(ert-deftest test-wrap-with-numbers ()
"Should wrap text with numbers."
(let ((result (test-wrap "123" "[" "]")))
(should (string= result "[123]"))))
(ert-deftest test-wrap-with-special-chars ()
"Should wrap text with special characters."
(let ((result (test-wrap "hello@world.com" "<" ">")))
(should (string= result "<hello@world.com>"))))
;;; Normal Cases - Multiline Text
(ert-deftest test-wrap-multiline ()
"Should wrap multiline text."
(let ((result (test-wrap "line1\nline2\nline3" "<div>" "</div>")))
(should (string= result "<div>line1\nline2\nline3</div>"))))
(ert-deftest test-wrap-text-with-newlines ()
"Should wrap text containing newlines."
(let ((result (test-wrap "first\nsecond" "(" ")")))
(should (string= result "(first\nsecond)"))))
;;; Boundary Cases
(ert-deftest test-wrap-empty-string ()
"Should wrap empty string."
(let ((result (test-wrap "" "(" ")")))
(should (string= result "()"))))
(ert-deftest test-wrap-single-character ()
"Should wrap single character."
(let ((result (test-wrap "x" "[" "]")))
(should (string= result "[x]"))))
(ert-deftest test-wrap-empty-opening ()
"Should handle empty opening delimiter."
(let ((result (test-wrap "text" "" ")")))
(should (string= result "text)"))))
(ert-deftest test-wrap-empty-closing ()
"Should handle empty closing delimiter."
(let ((result (test-wrap "text" "(" "")))
(should (string= result "(text"))))
(ert-deftest test-wrap-both-empty ()
"Should handle both delimiters empty."
(let ((result (test-wrap "text" "" "")))
(should (string= result "text"))))
(ert-deftest test-wrap-very-long-text ()
"Should wrap very long text."
(let* ((long-text (make-string 1000 ?a))
(result (test-wrap long-text "(" ")")))
(should (string-prefix-p "(" result))
(should (string-suffix-p ")" result))
(should (= (length result) 1002))))
(ert-deftest test-wrap-whitespace-only ()
"Should wrap whitespace-only text."
(let ((result (test-wrap " " "(" ")")))
(should (string= result "( )"))))
(ert-deftest test-wrap-tabs ()
"Should wrap text with tabs."
(let ((result (test-wrap "\t\ttext\t\t" "[" "]")))
(should (string= result "[\t\ttext\t\t]"))))
;;; Edge Cases - Already Wrapped
(ert-deftest test-wrap-already-wrapped ()
"Should wrap text that is already wrapped."
(let ((result (test-wrap "(hello)" "[" "]")))
(should (string= result "[(hello)]"))))
(ert-deftest test-wrap-nested ()
"Should wrap text creating nested delimiters."
(let ((result (test-wrap "[inner]" "(" ")")))
(should (string= result "([inner])"))))
;;; Edge Cases - Special Delimiters
(ert-deftest test-wrap-asymmetric-length ()
"Should wrap with different length delimiters."
(let ((result (test-wrap "text" "<<" ">>>")))
(should (string= result "<<text>>>"))))
(ert-deftest test-wrap-multi-char-delimiters ()
"Should wrap with multi-character delimiters."
(let ((result (test-wrap "data" "BEGIN" "END")))
(should (string= result "BEGINdataEND"))))
(ert-deftest test-wrap-space-delimiters ()
"Should wrap with space delimiters."
(let ((result (test-wrap "text" " " " ")))
(should (string= result " text "))))
(ert-deftest test-wrap-newline-delimiters ()
"Should wrap with newline delimiters."
(let ((result (test-wrap "text" "\n" "\n")))
(should (string= result "\ntext\n"))))
(ert-deftest test-wrap-quote-delimiters ()
"Should wrap with quote delimiters."
(let ((result (test-wrap "text" "\"" "\"")))
(should (string= result "\"text\""))))
;;; Edge Cases - Same Opening and Closing
(ert-deftest test-wrap-same-delimiters ()
"Should work like surround when delimiters are the same."
(let ((result (test-wrap "text" "*" "*")))
(should (string= result "*text*"))))
(provide 'test-custom-text-enclose-wrap)
;;; test-custom-text-enclose-wrap.el ends here
|