blob: 46296e685f21a2e8d6d7e1cc8dff9d81d1e301d7 (
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
|
;;; test-org-reveal-config-title-to-filename.el --- Tests for cj/--reveal-title-to-filename -*- lexical-binding: t; -*-
;;; Commentary:
;; Tests for the cj/--reveal-title-to-filename function from org-reveal-config.el
;;
;; This function takes a presentation title string, downcases it, replaces
;; whitespace runs with hyphens, and appends ".org". It is a pure string
;; function with no external dependencies — zero mocking required.
;;; Code:
(require 'ert)
;; Add modules directory to load path
(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
;; Stub ox-reveal dependency (not available in batch mode)
(provide 'ox-reveal)
(require 'org-reveal-config)
;;; Normal Cases
(ert-deftest test-org-reveal-config-title-to-filename-normal-simple-title ()
"Simple title should become lowercase-hyphenated.org."
(should (equal "my-first-talk.org"
(cj/--reveal-title-to-filename "My First Talk"))))
(ert-deftest test-org-reveal-config-title-to-filename-normal-two-words ()
"Two-word title should produce single hyphen."
(should (equal "hello-world.org"
(cj/--reveal-title-to-filename "Hello World"))))
(ert-deftest test-org-reveal-config-title-to-filename-normal-already-lowercase ()
"Already lowercase title should be unchanged except for extension."
(should (equal "demo-talk.org"
(cj/--reveal-title-to-filename "demo talk"))))
(ert-deftest test-org-reveal-config-title-to-filename-normal-single-word ()
"Single word title should just get .org appended."
(should (equal "overview.org"
(cj/--reveal-title-to-filename "Overview"))))
(ert-deftest test-org-reveal-config-title-to-filename-normal-always-org-extension ()
"Result should always end with .org."
(should (string-suffix-p ".org"
(cj/--reveal-title-to-filename "Anything"))))
;;; Boundary Cases
(ert-deftest test-org-reveal-config-title-to-filename-boundary-multiple-spaces ()
"Multiple consecutive spaces should collapse to single hyphen."
(should (equal "foo-bar.org"
(cj/--reveal-title-to-filename "foo bar"))))
(ert-deftest test-org-reveal-config-title-to-filename-boundary-tabs ()
"Tabs should be treated as whitespace and replaced."
(should (equal "tab-separated.org"
(cj/--reveal-title-to-filename "tab\tseparated"))))
(ert-deftest test-org-reveal-config-title-to-filename-boundary-mixed-whitespace ()
"Mixed spaces and tabs should collapse to single hyphen."
(should (equal "mixed-ws.org"
(cj/--reveal-title-to-filename "mixed \t ws"))))
(ert-deftest test-org-reveal-config-title-to-filename-boundary-leading-trailing-spaces ()
"Leading and trailing spaces become leading/trailing hyphens."
(let ((result (cj/--reveal-title-to-filename " padded ")))
(should (equal "-padded-.org" result))))
(ert-deftest test-org-reveal-config-title-to-filename-boundary-unicode-title ()
"Unicode characters should be preserved (only whitespace replaced)."
(should (equal "日本語-talk.org"
(cj/--reveal-title-to-filename "日本語 Talk"))))
(ert-deftest test-org-reveal-config-title-to-filename-boundary-numbers-in-title ()
"Numbers should be preserved in slug."
(should (equal "q4-2026-results.org"
(cj/--reveal-title-to-filename "Q4 2026 Results"))))
(ert-deftest test-org-reveal-config-title-to-filename-boundary-special-chars-preserved ()
"Non-whitespace special characters should be preserved (not stripped)."
(should (equal "what's-new?.org"
(cj/--reveal-title-to-filename "What's New?"))))
(ert-deftest test-org-reveal-config-title-to-filename-boundary-very-long-title ()
"Very long title should still produce valid filename."
(let* ((long-title (mapconcat #'identity (make-list 20 "word") " "))
(result (cj/--reveal-title-to-filename long-title)))
(should (string-suffix-p ".org" result))
(should-not (string-match-p " " result))))
(ert-deftest test-org-reveal-config-title-to-filename-boundary-empty-string ()
"Empty string should produce just .org."
(should (equal ".org" (cj/--reveal-title-to-filename ""))))
(ert-deftest test-org-reveal-config-title-to-filename-boundary-newline ()
"Newlines should be treated as whitespace."
(should (equal "line-one-line-two.org"
(cj/--reveal-title-to-filename "Line One\nLine Two"))))
;;; Error Cases
(ert-deftest test-org-reveal-config-title-to-filename-error-nil-input ()
"Nil input should signal an error (not crash silently)."
(should-error (cj/--reveal-title-to-filename nil)))
(provide 'test-org-reveal-config-title-to-filename)
;;; test-org-reveal-config-title-to-filename.el ends here
|