blob: eb3149dd0218a0c7663a9d65aea80cab9a7ef82c (
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
|
;;; test-org-roam-config-slug.el --- Tests for cj/--generate-roam-slug -*- lexical-binding: t; -*-
;;; Commentary:
;; Tests for the cj/--generate-roam-slug function from org-roam-config.el
;;
;; This function converts a title to a filename-safe slug by:
;; 1. Converting to lowercase
;; 2. Replacing non-alphanumeric characters with hyphens
;; 3. Removing leading and trailing hyphens
;;
;; Examples:
;; Input: "My Project Name"
;; Output: "my-project-name"
;;
;; Input: "Hello, World!"
;; Output: "hello-world"
;;; Code:
(require 'ert)
(require 'testutil-general)
;; Add modules directory to load path
(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
;; Now load the actual production module
(require 'org-roam-config)
;;; Test Helpers
(defun test-slug (title)
"Test cj/--generate-roam-slug on TITLE.
Returns the slugified string."
(cj/--generate-roam-slug title))
;;; Normal Cases - Simple Titles
(ert-deftest test-slug-simple-word ()
"Should return lowercase simple word."
(let ((result (test-slug "Hello")))
(should (string= result "hello"))))
(ert-deftest test-slug-multiple-words ()
"Should replace spaces with hyphens."
(let ((result (test-slug "My Project Name")))
(should (string= result "my-project-name"))))
(ert-deftest test-slug-already-lowercase ()
"Should handle already lowercase text."
(let ((result (test-slug "simple")))
(should (string= result "simple"))))
(ert-deftest test-slug-mixed-case ()
"Should convert mixed case to lowercase."
(let ((result (test-slug "MixedCaseTitle")))
(should (string= result "mixedcasetitle"))))
;;; Normal Cases - Punctuation
(ert-deftest test-slug-with-comma ()
"Should remove commas."
(let ((result (test-slug "Hello, World")))
(should (string= result "hello-world"))))
(ert-deftest test-slug-with-period ()
"Should remove periods."
(let ((result (test-slug "Version 2.0")))
(should (string= result "version-2-0"))))
(ert-deftest test-slug-with-exclamation ()
"Should remove exclamation marks."
(let ((result (test-slug "Hello World!")))
(should (string= result "hello-world"))))
(ert-deftest test-slug-with-question ()
"Should remove question marks."
(let ((result (test-slug "What Is This?")))
(should (string= result "what-is-this"))))
(ert-deftest test-slug-with-colon ()
"Should remove colons."
(let ((result (test-slug "Note: Important")))
(should (string= result "note-important"))))
(ert-deftest test-slug-with-parentheses ()
"Should remove parentheses."
(let ((result (test-slug "Item (copy)")))
(should (string= result "item-copy"))))
;;; Normal Cases - Numbers
(ert-deftest test-slug-with-numbers ()
"Should preserve numbers."
(let ((result (test-slug "Chapter 42")))
(should (string= result "chapter-42"))))
(ert-deftest test-slug-only-numbers ()
"Should handle titles with only numbers."
(let ((result (test-slug "123")))
(should (string= result "123"))))
(ert-deftest test-slug-mixed-alphanumeric ()
"Should preserve alphanumeric characters."
(let ((result (test-slug "Test123ABC")))
(should (string= result "test123abc"))))
;;; Boundary Cases - Multiple Consecutive Special Chars
(ert-deftest test-slug-multiple-spaces ()
"Should collapse multiple spaces into single hyphen."
(let ((result (test-slug "Hello World")))
(should (string= result "hello-world"))))
(ert-deftest test-slug-mixed-punctuation ()
"Should collapse mixed punctuation into single hyphen."
(let ((result (test-slug "Hello, ... World!")))
(should (string= result "hello-world"))))
(ert-deftest test-slug-consecutive-hyphens ()
"Should collapse consecutive hyphens."
(let ((result (test-slug "Hello---World")))
(should (string= result "hello-world"))))
;;; Boundary Cases - Leading/Trailing Special Chars
(ert-deftest test-slug-leading-space ()
"Should remove leading hyphen from leading space."
(let ((result (test-slug " Hello")))
(should (string= result "hello"))))
(ert-deftest test-slug-trailing-space ()
"Should remove trailing hyphen from trailing space."
(let ((result (test-slug "Hello ")))
(should (string= result "hello"))))
(ert-deftest test-slug-leading-punctuation ()
"Should remove leading hyphen from leading punctuation."
(let ((result (test-slug "...Hello")))
(should (string= result "hello"))))
(ert-deftest test-slug-trailing-punctuation ()
"Should remove trailing hyphen from trailing punctuation."
(let ((result (test-slug "Hello!!!")))
(should (string= result "hello"))))
(ert-deftest test-slug-leading-and-trailing ()
"Should remove both leading and trailing hyphens."
(let ((result (test-slug " Hello World ")))
(should (string= result "hello-world"))))
;;; Boundary Cases - Empty and Short
(ert-deftest test-slug-empty-string ()
"Should return empty string for empty input."
(let ((result (test-slug "")))
(should (string= result ""))))
(ert-deftest test-slug-only-punctuation ()
"Should return empty string for only punctuation."
(let ((result (test-slug "!!!")))
(should (string= result ""))))
(ert-deftest test-slug-only-spaces ()
"Should return empty string for only spaces."
(let ((result (test-slug " ")))
(should (string= result ""))))
(ert-deftest test-slug-single-char ()
"Should handle single character."
(let ((result (test-slug "A")))
(should (string= result "a"))))
;;; Edge Cases - Special Characters
(ert-deftest test-slug-with-underscore ()
"Should replace underscores with hyphens."
(let ((result (test-slug "my_variable_name")))
(should (string= result "my-variable-name"))))
(ert-deftest test-slug-with-slash ()
"Should remove slashes."
(let ((result (test-slug "path/to/file")))
(should (string= result "path-to-file"))))
(ert-deftest test-slug-with-at-sign ()
"Should remove at signs."
(let ((result (test-slug "user@example")))
(should (string= result "user-example"))))
(ert-deftest test-slug-with-hash ()
"Should remove hash symbols."
(let ((result (test-slug "#hashtag")))
(should (string= result "hashtag"))))
(ert-deftest test-slug-with-dollar ()
"Should remove dollar signs."
(let ((result (test-slug "$price")))
(should (string= result "price"))))
;;; Edge Cases - Unicode (if supported)
(ert-deftest test-slug-with-unicode ()
"Should remove unicode characters."
(let ((result (test-slug "Café")))
(should (string= result "caf"))))
(ert-deftest test-slug-with-emoji ()
"Should remove emoji."
(let ((result (test-slug "Hello 😀 World")))
(should (string= result "hello-world"))))
;;; Edge Cases - Long Titles
(ert-deftest test-slug-very-long-title ()
"Should handle very long titles."
(let* ((long-title (mapconcat #'identity (make-list 20 "word") " "))
(result (test-slug long-title)))
(should (string-prefix-p "word-" result))
(should (string-suffix-p "-word" result))
(should (not (string-match-p " " result)))))
(provide 'test-org-roam-config-slug)
;;; test-org-roam-config-slug.el ends here
|