Lots of refactorings and a few minor improvements.
[docutils.git] / docutils / tools / editors / emacs / tests / tree.el
blobbef5481de73c45ca8a8ee42574a79eef5a0456ad
1 ;; Tests for `rst-all-stn' and relatives -*- lexical-binding: t -*-
3 (add-to-list 'load-path ".")
4 (load "init" nil t)
5 (init-rst-ert t)
7 (ert-deftest toc-asserts ()
8 "Check some assertions."
9 (should (equal ert-Buf-point-char "\^@"))
10 (should (equal ert-Buf-mark-char "\^?"))
13 (ert-deftest rst-all-stn ()
14 "Tests `rst-all-stn'."
15 (let* ((title "=====
16 Title
17 =====
20 (headers "Header A
21 ========
23 Header B
24 ========
26 Subheader B.a
27 -------------
29 SubSubheader B.a.1
30 ~~~~~~~~~~~~~~~~~~
32 Header C
33 ========
35 Missing node C.a.1
36 ~~~~~~~~~~~~~~~~~~
38 (ado-T (rst-Ado-new-over-and-under ?=))
39 (ttl-T (rst-Ttl--new ado-T '(1 18 1 6 7 12 13 18) 0
40 "Title"))
41 (ado-A (rst-Ado-new-simple ?=))
42 (ttl-A (rst-Ttl--new ado-A '(20 37 nil nil 20 28 29 37) 0
43 "Header A"))
44 (ttl-B (rst-Ttl--new ado-A '(39 56 nil nil 39 47 48 56) 0
45 "Header B"))
46 (ado-Ba (rst-Ado-new-simple ?-))
47 (ttl-Ba (rst-Ttl--new ado-Ba '(58 85 nil nil 58 71 72 85) 0
48 "Subheader B.a"))
49 (ado-Ba1 (rst-Ado-new-simple ?~))
50 (ttl-Ba1 (rst-Ttl--new ado-Ba1 '(87 124 nil nil 87 105 106 124) 0
51 "SubSubheader B.a.1"))
52 (ttl-C (rst-Ttl--new ado-A '(126 143 nil nil 126 134 135 143) 0
53 "Header C"))
54 (ttl-Ca nil)
55 (ttl-Ca1 (rst-Ttl--new ado-Ba1 '(145 182 nil nil 145 163 164 182) 0
56 "Missing node C.a.1")))
57 (let* ((stn-Ca (rst-Stn-new
58 ttl-Ca 2
59 (list (rst-Stn-new ttl-Ca1 3 nil))))
60 (stn-C (rst-Stn-new
61 ttl-C 1
62 (list stn-Ca)))
63 (stn-A (rst-Stn-new ttl-A 1 nil))
64 (stn-B (rst-Stn-new
65 ttl-B 1
66 (list (rst-Stn-new
67 ttl-Ba 2
68 (list (rst-Stn-new ttl-Ba1 3 nil))))))
69 (stn-T (rst-Stn-new
70 ttl-T 0
71 (list stn-A
72 stn-B
73 stn-C))))
74 (should (ert-equal-buffer-return
75 '(rst-all-stn)
78 nil
80 (should (ert-equal-buffer-return
81 '(rst-all-stn)
82 title
84 (rst-Stn-new
85 nil -1
86 (list (rst-Stn-new ttl-T 0 nil)))
88 (should (ert-equal-buffer-return
89 '(rst-all-stn)
90 (concat title headers)
92 (rst-Stn-new
93 nil -1
94 (list stn-T))
96 )))
98 (ert-deftest rst-stn-containing-point ()
99 "Tests `rst-stn-containing-point'."
100 (let* (;; "
101 ;; =====
102 ;; Title
103 ;; =====
105 ;; Header A
106 ;; ========
108 ;; Header B
109 ;; ========
111 ;; Subheader B.a
112 ;; -------------
114 ;; SubSubheader B.a.1
115 ;; ~~~~~~~~~~~~~~~~~~
117 ;; Subheader B.b
118 ;; -------------
120 ;; Header C
121 ;; ========
123 ;; Missing node C.a.1
124 ;; ~~~~~~~~~~~~~~~~~~
125 ;; "
126 (title "=====
127 Title
128 =====
131 (ado-T (rst-Ado-new-over-and-under ?=))
132 (ttl-T (rst-Ttl--new ado-T '(1 18 1 6 7 12 13 18) 0
133 "Title"))
134 (ado-A (rst-Ado-new-simple ?=))
135 (ttl-A (rst-Ttl--new ado-A '(20 37 nil nil 20 28 29 37) 0
136 "Header A"))
137 (ttl-B (rst-Ttl--new ado-A '(39 56 nil nil 39 47 48 56) 0
138 "Header B"))
139 (ado-Ba (rst-Ado-new-simple ?-))
140 (ttl-Ba (rst-Ttl--new ado-Ba '(58 85 nil nil 58 71 72 85) 0
141 "Subheader B.a"))
142 (ado-Ba1 (rst-Ado-new-simple ?~))
143 (ttl-Ba1 (rst-Ttl--new ado-Ba1 '(87 124 nil nil 87 105 106 124) 0
144 "SubSubheader B.a.1"))
145 (ttl-Bb (rst-Ttl--new ado-Ba '(126 153 nil nil 126 139 140 153) 0
146 "Subheader B.b"))
147 (ttl-C (rst-Ttl--new ado-A '(155 172 nil nil 155 163 164 172) 0
148 "Header C"))
149 (ttl-Ca nil)
150 (ttl-Ca1 (rst-Ttl--new ado-Ba1 '(164 211 nil nil 164 192 193 211) 0
151 "Missing node C.a.1")))
152 (let* ((stn-Ca (rst-Stn-new
153 ttl-Ca 2
154 (list (rst-Stn-new ttl-Ca1 3 nil))))
155 (stn-C (rst-Stn-new
156 ttl-C 1
157 (list stn-Ca)))
158 (stn-A (rst-Stn-new ttl-A 1 nil))
159 (stn-Ba (rst-Stn-new
160 ttl-Ba 2
161 (list (rst-Stn-new ttl-Ba1 3 nil))))
162 (stn-Bb (rst-Stn-new ttl-Bb 2 nil))
163 (stn-B (rst-Stn-new
164 ttl-B 1
165 (list stn-Ba
166 stn-Bb)))
167 (stn-T (rst-Stn-new
168 ttl-T 0
169 (list stn-A
170 stn-B
171 stn-C))))
172 (should (ert-equal-buffer-return
173 '(rst-stn-containing-point (rst-all-stn))
174 "\^@"
178 (should (ert-equal-buffer-return
179 '(rst-stn-containing-point (rst-all-stn))
180 (concat "\^@" title)
184 (should (ert-equal-buffer-return
185 '(rst-stn-containing-point (rst-all-stn))
186 (concat title "\^@")
188 (rst-Stn-new ttl-T 0 nil)
190 (should (ert-equal-buffer-return
191 '(rst-stn-containing-point (rst-all-stn))
192 (concat title "\^@Header A
193 ========
195 Header B
196 ========
198 Subheader B.a
199 -------------
201 SubSubheader B.a.1
202 ~~~~~~~~~~~~~~~~~~
204 Subheader B.b
205 -------------
207 Header C
208 ========")
210 stn-A
212 (should (ert-equal-buffer-return
213 '(rst-stn-containing-point (rst-all-stn))
214 (concat title "Header A
215 ========
217 Header B
218 ========
220 Subheader B.a
221 -------------
223 SubSubheader B.a.1
224 ~~~~~~~~~~~~~~~~~~
226 Subheader B.b
227 -------------
229 Header C
230 ========")
232 stn-B
234 (should (ert-equal-buffer-return
235 '(rst-stn-containing-point (rst-all-stn))
236 (concat title "Header A
237 ========
239 Header B
240 ========
242 Subheader B.a\^@
243 -------------
245 SubSubheader B.a.1
246 ~~~~~~~~~~~~~~~~~~
248 Subheader B.b
249 -------------
251 Header C
252 ========")
254 stn-Ba
256 (should (ert-equal-buffer-return
257 '(rst-stn-containing-point (rst-all-stn))
258 (concat title "Header A
259 ========
261 Header B
262 ========
264 Subheader B.a
265 -------------
267 SubSubheader B.a.1
268 ~~~~~~~~~~~~~~~~~~
270 S\^@ubheader B.b
271 -------------
273 Header C
274 ========")
276 stn-Bb