#! /usr/bin/env python3 # $Id: test_definition_lists.py 9500 2023-12-14 22:38:49Z milde $ # 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): maxDiff = None 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(case_expected, output) totest = {} totest['definition_lists'] = [ ["""\ term definition """, """\ term definition """], ["""\ term definition paragraph """, """\ term definition paragraph """], ["""\ term definition no blank line """, """\ term definition Definition list ends without a blank line; unexpected unindent. no blank line """], ["""\ A paragraph:: A literal block without a blank line first? """, """\ A paragraph:: Blank line missing before literal block (after the "::")? Interpreted as a definition list item. A literal block without a blank line first? """], ["""\ this is not a term; a term may only be one line long this is not a definition """, """\ this is not a term; a term may only be one line long Unexpected indentation. this is not a definition """], ["""\ term 1 definition 1 term 2 definition 2 """, """\ term 1 definition 1 term 2 definition 2 """], ["""\ term 1 definition 1 (no blank line below) term 2 definition 2 """, """\ term 1 definition 1 (no blank line below) term 2 definition 2 """], ["""\ term 1 definition 1 (no blank line below) term 2 definition 2 No blank line after the definition list. """, """\ term 1 definition 1 (no blank line below) term 2 definition 2 Definition list ends without a blank line; unexpected unindent. No blank line after the definition list. """], ["""\ term 1 definition 1 term 1a definition 1a term 1b definition 1b term 2 definition 2 paragraph """, """\ term 1 definition 1 term 1a definition 1a term 1b definition 1b term 2 definition 2 paragraph """], ["""\ Term : classifier The ' : ' indicates a classifier in definition list item terms only. """, """\ Term classifier The ' : ' indicates a classifier in definition list item terms only. """], ["""\ Term: not a classifier Because there's no space before the colon. Term :not a classifier Because there's no space after the colon. Term \\: not a classifier Because the colon is escaped. """, """\ Term: not a classifier Because there's no space before the colon. Term :not a classifier Because there's no space after the colon. Term : not a classifier Because the colon is escaped. """], ["""\ ``Term : not a classifier`` Because the ' : ' is inside an inline literal. """, """\ Term : not a classifier Because the ' : ' is inside an inline literal. """], ["""\ Term `with *inline ``text **errors : classifier `with *errors ``too Definition `with *inline ``text **markup errors. """, """\ Term \n\ ` with \n\ * inline \n\ `` text \n\ ** errors classifier \n\ ` with \n\ * errors \n\ `` too Inline interpreted text or phrase reference start-string without end-string. Inline emphasis start-string without end-string. Inline literal start-string without end-string. Inline strong start-string without end-string. Inline interpreted text or phrase reference start-string without end-string. Inline emphasis start-string without end-string. Inline literal start-string without end-string. Definition \n\ ` with \n\ * inline \n\ `` text \n\ ** markup errors. Inline interpreted text or phrase reference start-string without end-string. Inline emphasis start-string without end-string. Inline literal start-string without end-string. Inline strong start-string without end-string. """], ["""\ Term : `reference`_ classifier starting with a reference crashes from release 8197 to ... """, """\ Term reference classifier starting with a reference crashes from release 8197 to ... """], ["""\ Term : a `reference`_ in text : second classifier with reference crashes from release 8197 to ... """, """\ Term a \n\ reference in text second classifier with reference crashes from release 8197 to ... """], ["""\ Term : classifier one : classifier two Definition """, """\ Term classifier one classifier two Definition """], ] if __name__ == '__main__': unittest.main()