Debian Codegraph @

tools/editors/emacs/tests/tree.el

raw
1 ;; Tests for `rst-all-stn' and relatives -*- lexical-binding: t -*-
2
3 (add-to-list 'load-path ".")
4 (load "init" nil t)
5 (init-rst-ert t)
6
7 (ert-deftest toc-asserts ()
8 "Check some assertions."
9 (should (equal ert-Buf-point-char "\^@"))
10 (should (equal ert-Buf-mark-char "\^?"))
11 )
12
13 (ert-deftest rst-all-stn ()
14 "Tests `rst-all-stn'."
15 (let* ((title "=====
16 Title
17 =====
18
19 ")
20 (headers "Header A
21 ========
22
23 Header B
24 ========
25
26 Subheader B.a
27 -------------
28
29 SubSubheader B.a.1
30 ~~~~~~~~~~~~~~~~~~
31
32 Header C
33 ========
34
35 Missing node C.a.1
36 ~~~~~~~~~~~~~~~~~~
37 ")
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)
76 ""
77 t
78 nil
79 ))
80 (should (ert-equal-buffer-return
81 '(rst-all-stn)
82 title
83 t
84 (rst-Stn-new
85 nil -1
86 (list (rst-Stn-new ttl-T 0 nil)))
87 ))
88 (should (ert-equal-buffer-return
89 '(rst-all-stn)
90 (concat title headers)
91 t
92 (rst-Stn-new
93 nil -1
94 (list stn-T))
95 ))
96 )))
97
98 (ert-deftest rst-stn-containing-point ()
99 "Tests `rst-stn-containing-point'."
100 (let* (;; "
101 ;; =====
102 ;; Title
103 ;; =====
104 ;;
105 ;; Header A
106 ;; ========
107 ;;
108 ;; Header B
109 ;; ========
110 ;;
111 ;; Subheader B.a
112 ;; -------------
113 ;;
114 ;; SubSubheader B.a.1
115 ;; ~~~~~~~~~~~~~~~~~~
116 ;;
117 ;; Subheader B.b
118 ;; -------------
119 ;;
120 ;; Header C
121 ;; ========
122 ;;
123 ;; Missing node C.a.1
124 ;; ~~~~~~~~~~~~~~~~~~
125 ;; "
126 (title "=====
127 Title
128 =====
129
130 ")
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 "\^@"
175 t
176 nil
177 ))
178 (should (ert-equal-buffer-return
179 '(rst-stn-containing-point (rst-all-stn))
180 (concat "\^@" title)
181 t
182 nil
183 ))
184 (should (ert-equal-buffer-return
185 '(rst-stn-containing-point (rst-all-stn))
186 (concat title "\^@")
187 t
188 (rst-Stn-new ttl-T 0 nil)
189 ))
190 (should (ert-equal-buffer-return
191 '(rst-stn-containing-point (rst-all-stn))
192 (concat title "\^@Header A
193 ========
194
195 Header B
196 ========
197
198 Subheader B.a
199 -------------
200
201 SubSubheader B.a.1
202 ~~~~~~~~~~~~~~~~~~
203
204 Subheader B.b
205 -------------
206
207 Header C
208 ========")
209 t
210 stn-A
211 ))
212 (should (ert-equal-buffer-return
213 '(rst-stn-containing-point (rst-all-stn))
214 (concat title "Header A
215 ========
216
217 Header B
218 ========
219 \^@
220 Subheader B.a
221 -------------
222
223 SubSubheader B.a.1
224 ~~~~~~~~~~~~~~~~~~
225
226 Subheader B.b
227 -------------
228
229 Header C
230 ========")
231 t
232 stn-B
233 ))
234 (should (ert-equal-buffer-return
235 '(rst-stn-containing-point (rst-all-stn))
236 (concat title "Header A
237 ========
238
239 Header B
240 ========
241
242 Subheader B.a\^@
243 -------------
244
245 SubSubheader B.a.1
246 ~~~~~~~~~~~~~~~~~~
247
248 Subheader B.b
249 -------------
250
251 Header C
252 ========")
253 t
254 stn-Ba
255 ))
256 (should (ert-equal-buffer-return
257 '(rst-stn-containing-point (rst-all-stn))
258 (concat title "Header A
259 ========
260
261 Header B
262 ========
263
264 Subheader B.a
265 -------------
266
267 SubSubheader B.a.1
268 ~~~~~~~~~~~~~~~~~~
269
270 S\^@ubheader B.b
271 -------------
272
273 Header C
274 ========")
275 t
276 stn-Bb
277 ))
278 )))