-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorg-roam-folgezettel-tests.el
134 lines (111 loc) · 4.61 KB
/
org-roam-folgezettel-tests.el
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
;;; org-roam-folgezettel-tests.el --- Test suite for org-roam-folgezettel -*- lexical-binding: t; -*-
;; Copyright (C) 2024 Kristoffer Balintona
;; Author: Kristoffer Balintona <[email protected]>
;; Keywords: files, text, convenience
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; Tests for org-roam-folgezettel.
;;; Code:
(require 'ert)
(require 'org-roam-folgezettel)
(defmacro org-roam-folgezettel-deftest (name doc &rest body)
"Generate an ert test for `org-roam-folgezettel'.
NAME is the label of the test. DOC is its docsting. BODY contains the
tests that should be run."
(let ((xname (intern (concat "org-roam-folgezettel-defun-test-"
(symbol-name name)))))
`(ert-deftest ,xname ()
,doc
,@body)))
;;; Index numbering sorting
(org-roam-folgezettel-deftest
internal-sorting-functions
"Tests internal functions for folgezettel sorting of index numberings."
(let ((i1 "1.3a")
(i2 "1.1a1")
(i3 "")
(i4 "1234"))
;; Basic
(should (equal (org-roam-folgezettel--index-normalize i1)
"1.3.a"))
(should (equal (org-roam-folgezettel--index-normalize i2)
"1.1.a.1"))
(should (equal (org-roam-folgezettel--index-split i1)
'("1" "3" "a")))
(should (equal (org-roam-folgezettel--index-split i2)
'("1" "1" "a" "1")))
(should (equal (org-roam-folgezettel--index-padded-parts i1)
" 1. 3. a"))
(should (equal (org-roam-folgezettel--index-padded-parts i2)
" 1. 1. a. 1"))
;; With "/" as a section delimiter
(should (equal (org-roam-folgezettel--index-normalize "1/1/a/1")
"1.1.a.1"))
(should (equal (org-roam-folgezettel--index-normalize "1/a/a/1")
"1.a.a.1"))
;; Negative numbers
(should (equal (org-roam-folgezettel--index-normalize "1.-1ab-30")
"1.-1.ab.-30"))
(should (equal (org-roam-folgezettel--index-split "1.-1ab-30")
'("1" "-1" "ab" "-30")))
;; Empty
(should (equal (org-roam-folgezettel--index-padded-parts i3)
""))
;; Single section
(should (equal (org-roam-folgezettel--index-padded-parts i4)
" 1234"))))
(org-roam-folgezettel-deftest
sorting
"Tests folgezettel sorting of index numberings."
(let ((i1 "1.3a")
(i2 "1.1a1"))
;; Basic
(should (equal (org-roam-folgezettel--index-lessp i1 i2)
nil))
;; Equal
(should (equal (org-roam-folgezettel--index-lessp i1 i2)
nil))
;; One is empty
(should (equal (org-roam-folgezettel--index-lessp "" i1)
t)) ; We want non-indexed nodes sorted to the top
;; Both are empty
(should (equal (org-roam-folgezettel--index-lessp "" "")
nil)) ; nil means the order is undisturbed when sorting
;; 10 vs 1
(should (equal (org-roam-folgezettel--index-lessp "1.10a" "1.1a")
nil))
;; One is a subset of the other
(should (equal (org-roam-folgezettel--index-lessp "2.10a" "2.10a30")
t))
;; Long first section
(should (equal (org-roam-folgezettel--index-lessp "1234" "2.10a30")
nil))
;; Long vs long
(should (equal (org-roam-folgezettel--index-lessp "16.23a54z34" "16.23a54z35")
t))
;; Zero numbering
(should (equal (org-roam-folgezettel--index-lessp "1.0" "1.1")
t))
(should (equal (org-roam-folgezettel--index-lessp "1.1" "1.0")
nil))
;; Negative numbering
(should (equal (org-roam-folgezettel--index-lessp "1.1" "1.-1")
nil))
(should (equal (org-roam-folgezettel--index-lessp "1.-1" "1.1")
t))
(should (equal (org-roam-folgezettel--index-lessp "1.-1" "1.-2")
nil))
(should (equal (org-roam-folgezettel--index-lessp "1.-10" "1.-2")
t))))
;;; Provide
(provide 'org-roam-folgezettel-tests)
;;; org-roam-folgezettel-tests.el ends here