summaryrefslogtreecommitdiff
path: root/tests/test-org-noter-config--title-to-slug.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-04-30 08:33:31 -0500
committerCraig Jennings <c@cjennings.net>2026-04-30 09:13:53 -0500
commitef7cc3afe3c5e7bca50ecfc6fd2a643704a071b6 (patch)
tree2089682eb50b309a4ff8d173a3d07737b5fa4b09 /tests/test-org-noter-config--title-to-slug.el
parent1066ef4238eded84ccf581da8747cc4db28673a8 (diff)
downloaddotemacs-ef7cc3afe3c5e7bca50ecfc6fd2a643704a071b6.tar.gz
dotemacs-ef7cc3afe3c5e7bca50ecfc6fd2a643704a071b6.zip
test(org-noter-config): cover preferred-split, slug, template, predicates
Four new test files for the pure-and-near-pure helpers in org-noter-config.el. The interactive heavyweights (cj/org-noter-start, cj/org-noter-insert-note-dwim, cj/org-noter--toggle-notes-window, cj/org-noter--find-notes-file, cj/org-noter--create-notes-file) are out of scope for this pass — they need org-noter loaded and a real session, or a substantial internal/wrapper split before they can be tested without spinning up real PDFs and EPUBs. - preferred-split: 5 tests walking the 1.4 width-to-height threshold from both sides plus a square-frame boundary. - title-to-slug: 7 tests covering multi-word, single-word, mixed punctuation, leading/trailing junk, collapsed runs, digits, and empty input. - generate-notes-template: 5 tests with org-id-uuid mocked, asserting the rendered template carries the UUID, the dual ROAM_REFS / NOTER_DOCUMENT pointers, the title-and-category lines, the ReadingNotes filetag, and the trailing Notes heading. - predicates: 13 tests covering cj/org-noter--in-document-p, cj/org-noter--in-notes-file-p, cj/org-noter--session-active-p, cj/org-noter--get-document-path, and cj/org-noter--extract-document-title. Mocks derived-mode-p, org-entry-get, and buffer-file-name at the boundary so the suite doesn't require pdf-tools or nov. The require chain in each test file is user-constants → keybindings → org-noter-config because cj/org-noter-notes-directory captures roam-dir from user-constants and the prefix-map binding at the bottom of org-noter-config references cj/custom-keymap. 30 new tests, all passing. Full suite green.
Diffstat (limited to 'tests/test-org-noter-config--title-to-slug.el')
-rw-r--r--tests/test-org-noter-config--title-to-slug.el50
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/test-org-noter-config--title-to-slug.el b/tests/test-org-noter-config--title-to-slug.el
new file mode 100644
index 00000000..3122086d
--- /dev/null
+++ b/tests/test-org-noter-config--title-to-slug.el
@@ -0,0 +1,50 @@
+;;; test-org-noter-config--title-to-slug.el --- Tests for cj/org-noter--title-to-slug -*- lexical-binding: t; -*-
+
+;;; Commentary:
+;; Tests for `cj/org-noter--title-to-slug'. The function lowercases its
+;; input, replaces every run of non-alphanumeric characters with a
+;; single hyphen, and trims leading/trailing hyphens. It's used to
+;; turn a book title into a filename-safe slug.
+
+;;; Code:
+
+(require 'ert)
+
+(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
+(require 'user-constants)
+(require 'keybindings)
+(require 'org-noter-config)
+
+(ert-deftest test-org-noter-config-title-to-slug-multi-word ()
+ "Normal: a multi-word title becomes hyphen-separated lowercase."
+ (should (equal "the-pragmatic-programmer"
+ (cj/org-noter--title-to-slug "The Pragmatic Programmer"))))
+
+(ert-deftest test-org-noter-config-title-to-slug-single-word ()
+ "Normal: a single-word lowercase title is unchanged."
+ (should (equal "anaphora" (cj/org-noter--title-to-slug "anaphora"))))
+
+(ert-deftest test-org-noter-config-title-to-slug-mixed-punctuation ()
+ "Boundary: punctuation is collapsed into single hyphens."
+ (should (equal "godel-escher-bach"
+ (cj/org-noter--title-to-slug "Godel, Escher, Bach!"))))
+
+(ert-deftest test-org-noter-config-title-to-slug-leading-trailing-non-alnum ()
+ "Boundary: leading and trailing non-alnum runs are trimmed."
+ (should (equal "title"
+ (cj/org-noter--title-to-slug " ...title!?? "))))
+
+(ert-deftest test-org-noter-config-title-to-slug-collapses-multiple-non-alnum ()
+ "Boundary: a run of non-alnum chars in the middle becomes one hyphen."
+ (should (equal "a-b" (cj/org-noter--title-to-slug "a --- b"))))
+
+(ert-deftest test-org-noter-config-title-to-slug-numbers-preserved ()
+ "Boundary: digits are preserved as-is."
+ (should (equal "1984" (cj/org-noter--title-to-slug "1984"))))
+
+(ert-deftest test-org-noter-config-title-to-slug-empty-string ()
+ "Error: empty input yields empty string."
+ (should (equal "" (cj/org-noter--title-to-slug ""))))
+
+(provide 'test-org-noter-config--title-to-slug)
+;;; test-org-noter-config--title-to-slug.el ends here