diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2018-11-25 20:23:04 +0900 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2018-12-05 23:10:23 +0900 |
commit | 5fa8ca492ba05f316be4e644b89a5957025de4da (patch) | |
tree | d0b2f85b16f6ea84bab850dfe6c88016d12887d0 /tests/test_util_rst.py | |
parent | 039582395cea5134febf1adfd2febec1bf988438 (diff) | |
download | sphinx-git-5fa8ca492ba05f316be4e644b89a5957025de4da.tar.gz |
Add prepend_prolog() and append_epilog()
Diffstat (limited to 'tests/test_util_rst.py')
-rw-r--r-- | tests/test_util_rst.py | 70 |
1 files changed, 69 insertions, 1 deletions
diff --git a/tests/test_util_rst.py b/tests/test_util_rst.py index 07b9174cc..166c865d3 100644 --- a/tests/test_util_rst.py +++ b/tests/test_util_rst.py @@ -8,7 +8,10 @@ :copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. """ -from sphinx.util.rst import escape + +from docutils.statemachine import StringList + +from sphinx.util.rst import append_epilog, escape, prepend_prolog def test_escape(): @@ -16,3 +19,68 @@ def test_escape(): assert escape('footnote [#]_') == r'footnote \[\#\]\_' assert escape('sphinx.application') == r'sphinx.application' assert escape('.. toctree::') == r'\.. toctree\:\:' + + +def test_append_epilog(app): + epilog = 'this is rst_epilog\ngood-bye reST!' + content = StringList(['hello Sphinx world', + 'Sphinx is a document generator'], + 'dummy.rst') + append_epilog(content, epilog) + + assert list(content.xitems()) == [('dummy.rst', 0, 'hello Sphinx world'), + ('dummy.rst', 1, 'Sphinx is a document generator'), + ('<generated>', 0, ''), + ('<rst_epilog>', 0, 'this is rst_epilog'), + ('<rst_epilog>', 1, 'good-bye reST!')] + + +def test_prepend_prolog(app): + prolog = 'this is rst_prolog\nhello reST!' + content = StringList([':title: test of SphinxFileInput', + ':author: Sphinx team', + '', + 'hello Sphinx world', + 'Sphinx is a document generator'], + 'dummy.rst') + prepend_prolog(content, prolog) + + assert list(content.xitems()) == [('dummy.rst', 0, ':title: test of SphinxFileInput'), + ('dummy.rst', 1, ':author: Sphinx team'), + ('<generated>', 0, ''), + ('<rst_prolog>', 0, 'this is rst_prolog'), + ('<rst_prolog>', 1, 'hello reST!'), + ('<generated>', 0, ''), + ('dummy.rst', 2, ''), + ('dummy.rst', 3, 'hello Sphinx world'), + ('dummy.rst', 4, 'Sphinx is a document generator')] + + +def test_prepend_prolog_with_CR(app): + # prolog having CR at tail + prolog = 'this is rst_prolog\nhello reST!\n' + content = StringList(['hello Sphinx world', + 'Sphinx is a document generator'], + 'dummy.rst') + prepend_prolog(content, prolog) + + assert list(content.xitems()) == [('<rst_prolog>', 0, 'this is rst_prolog'), + ('<rst_prolog>', 1, 'hello reST!'), + ('<generated>', 0, ''), + ('dummy.rst', 0, 'hello Sphinx world'), + ('dummy.rst', 1, 'Sphinx is a document generator')] + + +def test_prepend_prolog_without_CR(app): + # prolog not having CR at tail + prolog = 'this is rst_prolog\nhello reST!' + content = StringList(['hello Sphinx world', + 'Sphinx is a document generator'], + 'dummy.rst') + prepend_prolog(content, prolog) + + assert list(content.xitems()) == [('<rst_prolog>', 0, 'this is rst_prolog'), + ('<rst_prolog>', 1, 'hello reST!'), + ('<generated>', 0, ''), + ('dummy.rst', 0, 'hello Sphinx world'), + ('dummy.rst', 1, 'Sphinx is a document generator')] |