build.test.test_transforms.test_contents.py Maven / Gradle / Ivy
#! /usr/bin/env python
# $Id: test_contents.py 4564 2006-05-21 20:44:42Z wiemann $
# Author: David Goodger
# Copyright: This module has been placed in the public domain.
"""
Tests for `docutils.transforms.parts.Contents` (via
`docutils.transforms.universal.LastReaderPending`).
"""
from __init__ import DocutilsTestSupport
from docutils.transforms.references import Substitutions
from docutils.parsers.rst import Parser
def suite():
parser = Parser()
s = DocutilsTestSupport.TransformTestSuite(parser)
s.generateTests(totest)
return s
totest = {}
totest['tables_of_contents'] = ((Substitutions,), [
["""\
.. contents::
Title 1
=======
Paragraph 1.
Title_ 2
--------
Paragraph 2.
_`Title` 3
``````````
Paragraph 3.
Title 4
-------
Paragraph 4.
""",
"""\
Contents
Title 1
Title
2
Title
3
Title 4
Title 1
Paragraph 1.
Title
2
Paragraph 2.
Title
3
Paragraph 3.
Title 4
Paragraph 4.
"""],
["""\
.. contents:: Table of Contents
Title 1
=======
Paragraph 1.
Title 2
-------
Paragraph 2.
""",
"""\
Table of Contents
Title 1
Title 2
Title 1
Paragraph 1.
Title 2
Paragraph 2.
"""],
["""\
.. contents:: There's an image in Title 2
Title 1
=======
Paragraph 1.
|Title 2|
=========
Paragraph 2.
.. |Title 2| image:: title2.png
""",
"""\
There's an image in Title 2
Title 1
Title 2
Title 1
Paragraph 1.
Paragraph 2.
"""], # emacs cruft: "
["""\
.. contents::
:depth: 2
Title 1
=======
Paragraph 1.
Title 2
-------
Paragraph 2.
Title 3
```````
Paragraph 3.
Title 4
-------
Paragraph 4.
""",
"""\
Contents
Title 1
Title 2
Title 4
Title 1
Paragraph 1.
Title 2
Paragraph 2.
Title 3
Paragraph 3.
Title 4
Paragraph 4.
"""],
["""\
Title 1
=======
.. contents::
:local:
Paragraph 1.
Title 2
-------
Paragraph 2.
Title 3
```````
Paragraph 3.
Title 4
-------
Paragraph 4.
""",
"""\
Title 1
Title 2
Title 3
Title 4
Paragraph 1.
Title 2
Paragraph 2.
Title 3
Paragraph 3.
Title 4
Paragraph 4.
"""],
["""\
.. contents::
:local:
Test duplicate name "Contents".
Section
--------
Paragraph.
""",
"""\
Section
Test duplicate name "Contents".
Section
Paragraph.
"""],
["""\
.. contents::
:backlinks: top
Section
--------
Paragraph.
""",
"""\
Contents
Section
Section
Paragraph.
"""],
["""\
.. contents::
:backlinks: none
Section
--------
Paragraph.
""",
"""\
Contents
Section
Section
Paragraph.
"""],
["""\
.. contents::
Degenerate case, no table of contents generated.
""",
"""\
Degenerate case, no table of contents generated.
"""],
["""\
Title 1
=======
Paragraph 1.
.. sidebar:: Contents
.. contents::
:local:
Title 2
-------
Paragraph 2.
Title 3
```````
Paragraph 3.
""",
"""\
Title 1
Paragraph 1.
Contents
Title 2
Title 3
Title 2
Paragraph 2.
Title 3
Paragraph 3.
"""],
])
if __name__ == '__main__':
import unittest
unittest.main(defaultTest='suite')