Add support for `imenu` and `which-func-mode`. Remember setting
[docutils/kirr.git] / docutils / tools / editors / emacs / tests / toc.el
blob1f53c8d63269946d1247f22b42d6703a66c0bb28
1 ;; Tests for operations on toc
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-toc-insert ()
14 "Tests `rst-toc-insert'."
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 Subheader B.b
33 -------------
35 Header C
36 ========"))
37 ;; Set customizable variables to defaults
38 (let ((rst-toc-indent 2)
39 (rst-toc-insert-style 'fixed)
40 (rst-toc-insert-number-separator " ")
41 (rst-toc-insert-max-level nil))
42 ;; Can't identify a title so do nothing - that's actually a (MIS-)FEATURE
43 (should (ert-equal-buffer
44 (rst-toc-insert)
45 (concat "\^@" headers)
46 t))
47 ;; Won't work on a section title
48 (should (ert-equal-buffer
49 (rst-toc-insert)
50 (concat title "\^@" headers)
51 t))
52 ;; No indentation
53 (should (ert-equal-buffer
54 (rst-toc-insert)
55 (concat title "\^@\n\n" headers)
56 (concat title "1 Header A
57 2 Header B
58 2.1 Subheader B.a
59 2.1.1 SubSubheader B.a.1
60 2.2 Subheader B.b
61 3 Header C\^@
63 " headers)))
64 ;; Indentation
65 (should (ert-equal-buffer
66 (rst-toc-insert)
67 (concat title " \^@\n\n" headers)
68 (concat title " 1 Header A
69 2 Header B
70 2.1 Subheader B.a
71 2.1.1 SubSubheader B.a.1
72 2.2 Subheader B.b
73 3 Header C\^@
75 " headers)))
76 ;; Only first level
77 (should (ert-equal-buffer
78 (rst-toc-insert 1)
79 (concat title " \^@\n\n" headers)
80 (concat title " 1 Header A
81 2 Header B
82 3 Header C\^@
84 " headers)))
85 ;; Prefix and indentation
86 (should (ert-equal-buffer
87 (rst-toc-insert)
88 (concat title ".. \^@\n\n" headers)
89 (concat title ".. 1 Header A
90 2 Header B
91 2.1 Subheader B.a
92 2.1.1 SubSubheader B.a.1
93 2.2 Subheader B.b
94 3 Header C\^@
96 " headers)))
100 (ert-deftest rst-toc-update ()
101 "Tests `rst-toc-update'."
102 (let ((title "=====
103 Title
104 =====
107 (headers "Header A
108 ========
110 Header B
111 ========
113 Subheader B.a
114 -------------
116 SubSubheader B.a.1
117 ~~~~~~~~~~~~~~~~~~
119 Subheader B.b
120 -------------
122 Header C
123 ========")
124 (contents ".. contents:: Inhalt\n")
125 (fields " :bla: blub\n :local:\n")
126 (old ".. 1 Header A
127 2 Header B
128 3 Header C")
129 (new "..
130 1 Header A
131 2 Header B
132 2.1 Subheader B.a
133 2.1.1 SubSubheader B.a.1
134 2.2 Subheader B.b
135 3 Header C")
137 ;; Set customizable variables to defaults
138 (let ((rst-toc-indent 2)
139 (rst-toc-insert-style 'fixed)
140 (rst-toc-insert-number-separator " ")
141 (rst-toc-insert-max-level nil))
142 (should (ert-equal-buffer
143 (rst-toc-update)
144 (concat title contents fields old "\n\n" headers "\^@")
145 (concat title contents fields new "\n\n" headers "\^@")))
146 (should (ert-equal-buffer
147 (rst-toc-update)
148 (concat title contents old "\n\n" headers "\^@")
149 (concat title contents new "\n\n" headers "\^@")))
153 ;; FIXME: More functions to test:
154 ;; * rst-toc
155 ;; * rst-toc-mode-goto-section