Add support for `imenu` and `which-func-mode`. Remember setting
[docutils/kirr.git] / docutils / tools / editors / emacs / tests / tree.el
blob5c475430f15bcb70c7b78068d2a8684758434ae0
1 ;; Tests for `rst-section-tree'
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 (defun mrk2int (obj)
14 "Replace all markers in OBJ by integers and return result."
15 (cond
16 ((markerp obj)
17 (marker-position obj))
18 ((stringp obj)
19 obj)
20 ((sequencep obj)
21 (mapcar 'mrk2int obj))
22 (t obj)))
24 (defun section-tree ()
25 "Return result of `rst-section-tree' with markers replaced by integers."
26 (mrk2int (rst-section-tree)))
28 (defun section-tree-point ()
29 "Return result of `rst-section-tree-point' with markers replaced by integers."
30 (mrk2int (rst-section-tree-point (rst-section-tree))))
32 (ert-deftest rst-section-tree ()
33 "Tests `rst-section-tree'."
34 (let ((title "=====
35 Title
36 =====
39 (headers "Header A
40 ========
42 Header B
43 ========
45 Subheader B.a
46 -------------
48 SubSubheader B.a.1
49 ~~~~~~~~~~~~~~~~~~
51 Subheader B.b
52 -------------
54 Header C
55 ========"))
56 (should (ert-equal-buffer-return
57 (section-tree)
60 '((nil))
62 (should (ert-equal-buffer-return
63 (section-tree)
64 title
66 '((nil 7) (("Title" 7)))
68 (should (ert-equal-buffer-return
69 (section-tree)
70 (concat title headers)
72 '((nil 7)
73 (("Title" 7)
74 (("Header A" 20))
75 (("Header B" 39)
76 (("Subheader B.a" 58)
77 (("SubSubheader B.a.1" 87)))
78 (("Subheader B.b" 126)))
79 (("Header C" 155))))
83 (ert-deftest rst-section-tree-point ()
84 "Tests `rst-section-tree-point'."
85 (let ((title "=====
86 Title
87 =====
89 "))
90 (should (ert-equal-buffer-return
91 (section-tree-point)
92 "\^@"
94 '(((nil)))
96 (should (ert-equal-buffer-return
97 (section-tree-point)
98 (concat "\^@" title)
100 '(((nil 7)))
102 (should (ert-equal-buffer-return
103 (section-tree-point)
104 (concat title "\^@")
106 '(((nil 7) ("Title" 7)) ("Title" 7))
108 (should (ert-equal-buffer-return
109 (section-tree-point)
110 (concat title "\^@Header A
111 ========
113 Header B
114 ========
116 Subheader B.a
117 -------------
119 SubSubheader B.a.1
120 ~~~~~~~~~~~~~~~~~~
122 Subheader B.b
123 -------------
125 Header C
126 ========")
128 '(((nil 7) ("Title" 7) ("Header A" 20)) ("Header A" 20))
130 (should (ert-equal-buffer-return
131 (section-tree-point)
132 (concat title "Header A
133 ========
135 Header B
136 ========
138 Subheader B.a
139 -------------
141 SubSubheader B.a.1
142 ~~~~~~~~~~~~~~~~~~
144 Subheader B.b
145 -------------
147 Header C
148 ========")
150 '(((nil 7) ("Title" 7) ("Header B" 39)) ("Header B" 39)
151 (("Subheader B.a" 58)
152 (("SubSubheader B.a.1" 87)))
153 (("Subheader B.b" 126)))
155 (should (ert-equal-buffer-return
156 (section-tree-point)
157 (concat title "Header A
158 ========
160 Header B
161 ========
163 Subheader B.a\^@
164 -------------
166 SubSubheader B.a.1
167 ~~~~~~~~~~~~~~~~~~
169 Subheader B.b
170 -------------
172 Header C
173 ========")
175 '(((nil 7) ("Title" 7) ("Header B" 39) ("Subheader B.a" 58))
176 ("Subheader B.a" 58)
177 (("SubSubheader B.a.1" 87)))
179 (should (ert-equal-buffer-return
180 (section-tree-point)
181 (concat title "Header A
182 ========
184 Header B
185 ========
187 Subheader B.a
188 -------------
190 SubSubheader B.a.1
191 ~~~~~~~~~~~~~~~~~~
193 S\^@ubheader B.b
194 -------------
196 Header C
197 ========")
199 '(((nil 7) ("Title" 7) ("Header B" 39) ("Subheader B.b" 126))
200 ("Subheader B.b" 126))