#! /usr/bin/env python3 # $Id$ # Author: David Goodger # Copyright: This module has been placed in the public domain. """ Tests for states.py. """ from pathlib import Path import sys import unittest if __name__ == '__main__': # prepend the "docutils root" to the Python library path # so we import the local `docutils` package. sys.path.insert(0, str(Path(__file__).resolve().parents[3])) from docutils.frontend import get_default_settings from docutils.parsers.rst import Parser from docutils.utils import new_document class ParserTestCase(unittest.TestCase): def test_parser(self): parser = Parser() settings = get_default_settings(Parser) settings.warning_stream = '' for name, cases in totest.items(): for casenum, (case_input, case_expected) in enumerate(cases): with self.subTest(id=f'totest[{name!r}][{casenum}]'): document = new_document('test data', settings.copy()) parser.parse(case_input, document) output = document.pformat() self.assertEqual(output, case_expected) totest = {} totest['line_blocks'] = [ ["""\ | This is a line block. | Line breaks are *preserved*. | This is a second line block. | This is a third. """, """\ This is a line block. Line breaks are \n\ preserved . This is a second line block. This is a third. """], ["""\ | In line blocks, | Initial indentation is *also* preserved. """, """\ In line blocks, Initial indentation is \n\ also preserved. """], ["""\ | Individual lines in line blocks *may* wrap, as indicated by the lack of a vertical bar prefix. | These are called "continuation lines". """, """\ Individual lines in line blocks may wrap, as indicated by the lack of a vertical bar prefix. These are called "continuation lines". """], ["""\ | Inline markup in line blocks may also wrap *to continuation lines*. | But not to following lines. """, """\ Inline markup in line blocks may also wrap \n\ to continuation lines . But not to following lines. """], ["""\ \\| This is not a line block. The vertical bar is simply part of a paragraph. """, """\ | This is not a line block. The vertical bar is simply part of a paragraph. """], ["""\ | This line block is incomplete. There should be a blank line before this paragraph. """, """\ This line block is incomplete. Line block ends without a blank line. There should be a blank line before this paragraph. """], ["""\ | This line block contains | | blank lines. """, """\ This line block contains blank lines. """], ["""\ | The blank lines in this block | \n\ | \n\ | have bogus spaces. """, """\ The blank lines in this block have bogus spaces. """], ["""\ | Initial indentation is also significant and preserved: | | Indented 4 spaces | Not indented | Indented 2 spaces | Indented 4 spaces | Only one space | | Continuation lines may be indented less than their base lines. """, """\ Initial indentation is also significant and preserved: Indented 4 spaces Not indented Indented 2 spaces Indented 4 spaces Only one space Continuation lines may be indented less than their base lines. """], ["""\ | | This block begins and ends with blank lines. | """, """\ This block begins and ends with blank lines. """], ["""\ This is not | a line block. """, """\ This is not | a line block. """], ["""\ | The first line is indented. | The second line is more indented. """, """\ The first line is indented. The second line is more indented. """], ["""\ | The first line is indented. | The second line is less indented. """, """\ The first line is indented. The second line is less indented. """], ["""\ |This is not |a line block | This is an |incomplete line block. """, """\ | This is not | a line block Inline substitution_reference start-string without end-string. Inline substitution_reference start-string without end-string. This is an Line block ends without a blank line. | incomplete line block. Inline substitution_reference start-string without end-string. """], ["""\ | Inline markup *may not | wrap* over several lines. """, """\ Inline markup \n\ * may not wrap* over several lines. Inline emphasis start-string without end-string. """], ["""\ | * Block level markup | * is not recognized. """, """\ * Block level markup * is not recognized. """], ["""\ System messages can appear in place of lines: | `uff `_ | `uff `_ """, """\ System messages can appear in place of lines: uff Duplicate explicit target name: "uff". uff """], ] if __name__ == '__main__': unittest.main()