4 # Author: David Goodger <goodger@python.org>
5 # Copyright: This module has been placed in the public domain.
8 Tests for `docutils.transforms.parts.Contents` (via
9 `docutils.transforms.universal.LastReaderPending`).
12 from __init__
import DocutilsTestSupport
13 from docutils
.transforms
.references
import Substitutions
14 from docutils
.parsers
.rst
import Parser
19 s
= DocutilsTestSupport
.TransformTestSuite(parser
)
20 s
.generateTests(totest
)
25 totest
['tables_of_contents'] = ((Substitutions
,), [
46 <document source="test data">
47 <topic classes="contents" ids="contents" names="contents">
53 <reference ids="id1" refid="title-1">
58 <reference ids="id2" refid="title-2">
64 <reference ids="id3" refid="title-3">
69 <reference ids="id4" refid="title-4">
71 <section ids="title-1" names="title\ 1">
76 <section ids="title-2" names="title\ 2">
78 <reference name="Title" refname="title">
83 <section ids="title-3" names="title\ 3">
85 <target ids="title" names="title">
90 <section ids="title-4" names="title\ 4">
97 .. contents:: Table of Contents
108 <document source="test data">
109 <topic classes="contents" ids="table-of-contents" names="table\ of\ contents">
115 <reference ids="id1" refid="title-1">
120 <reference ids="id2" refid="title-2">
122 <section ids="title-1" names="title\ 1">
127 <section ids="title-2" names="title\ 2">
134 .. contents:: There's an image in Title 2
144 .. |Title 2| image:: title2.png
147 <document source="test data">
148 <topic classes="contents" ids="there-s-an-image-in-title-2" names="there's\ an\ image\ in\ title\ 2">
150 There's an image in Title 2
154 <reference ids="id1" refid="title-1">
158 <reference ids="id2" refid="title-2">
160 <section ids="title-1" names="title\ 1">
165 <section ids="title-2" names="title\ 2">
167 <image alt="Title 2" uri="title2.png">
170 <substitution_definition names="Title\ 2">
171 <image alt="Title 2" uri="title2.png">
172 """], # emacs cruft: "
194 <document source="test data">
195 <topic classes="contents" ids="contents" names="contents">
201 <reference ids="id1" refid="title-1">
206 <reference ids="id2" refid="title-2">
210 <reference ids="id3" refid="title-4">
212 <section ids="title-1" names="title\ 1">
217 <section ids="title-2" names="title\ 2">
222 <section ids="title-3" names="title\ 3">
227 <section ids="title-4" names="title\ 4">
255 <document source="test data">
256 <section ids="title-1" names="title\ 1">
259 <topic classes="contents local" ids="contents" names="contents">
263 <reference ids="id1" refid="title-2">
268 <reference ids="id2" refid="title-3">
272 <reference ids="id3" refid="title-4">
276 <section ids="title-2" names="title\ 2">
281 <section ids="title-3" names="title\ 3">
286 <section ids="title-4" names="title\ 4">
296 Test duplicate name "Contents".
303 <document source="test data">
304 <topic classes="contents local" ids="contents" names="contents">
308 <reference ids="id1" refid="section">
311 Test duplicate name "Contents".
312 <section ids="section" names="section">
327 <document source="test data">
328 <topic classes="contents" ids="contents" names="contents">
334 <reference ids="id1" refid="section">
336 <section ids="section" names="section">
337 <title refid="contents">
351 <document source="test data">
352 <topic classes="contents" ids="contents" names="contents">
358 <reference ids="id1" refid="section">
360 <section ids="section" names="section">
369 Degenerate case, no table of contents generated.
372 <document source="test data">
374 Degenerate case, no table of contents generated.
382 .. sidebar:: Contents
396 <document source="test data">
397 <section ids="title-1" names="title\ 1">
405 <topic classes="contents local" ids="contents" names="contents">
409 <reference ids="id1" refid="title-2">
414 <reference ids="id2" refid="title-3">
416 <section ids="title-2" names="title\ 2">
421 <section ids="title-3" names="title\ 3">
430 if __name__
== '__main__':
432 unittest
.main(defaultTest
='suite')