aboutsummaryrefslogtreecommitdiff
path: root/tests/test-org-noter-config--title-to-slug.el
blob: 3122086dcbb45987b53437f80b8485b6cce6bc5d (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
;;; 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